Mouse Wheel seek

Allows seeking audio and video elements with the mousewheel

Click here to install Browse More Scripts
// ==UserScript==
// @name         Mouse Wheel seek
// @namespace    715ba2933bbfa95cddb5e390c6fc9343b00a812b
// @version      1.0
// @description  Allows seeking audio and video elements with the mousewheel
// @author       /u/AyrA_ch
// @include      http://*
// @include      https://*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
	var isMedia = function (x) {
		return ["video", "audio"].indexOf(x.tagName.toLowerCase()) >= 0;
	};
	var INTERVAL = 3;
	document.addEventListener("mousewheel", function (e) {
		//detect scroll direction
		var dir = e.deltaY > 0 ? "down" : "up";
		//Element the mouse is currently over
		var tag = e.target;
		//Get video or audio element (useful if something covers the media element)
		while (tag && !isMedia(tag)) {
			tag = tag.parentNode;
		}
		if (tag) {
			e.preventDefault();
			e.stopPropagation();
			//seek 3 seconds but ensure the position is stil within the bounds (0-duration)
			tag.currentTime = Math.max(Math.min(tag.currentTime + (dir === "up" ? -INTERVAL : +INTERVAL), tag.duration), 0) | 0;
		}
	});
})();

/*
LICENSE:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
The link has an easy to understand version of the license and the full license text.

DISCLAIMER:
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/

Copyright © 2018 by Kevin Gut 📧 | More services | Generated for 18.119.253.93