Whenever the user scrolls using the mouse wheel it will disable all methods to programmatically scroll for 1000 ms. Basically preventing websites to implement custom scrolling behaviors like smooth scrolling.
目前為
// ==UserScript== // @name Don't fuck with my scroll!!! // @namespace http://github.com/YePpHa // @version 1.0 // @description Whenever the user scrolls using the mouse wheel it will disable all methods to programmatically scroll for 1000 ms. Basically preventing websites to implement custom scrolling behaviors like smooth scrolling. // @author Jeppe Rune Mortensen <[email protected]> // @match http://*/* // @match https://*/* // @grant none // @run-at document-start // ==/UserScript== (function() { 'use strict'; var inject = function() { var timeout = 1000; function init() { function enableScrolling() { window.scrollBy = _scrollBy; window.scrollTo = _scrollTo; Object.defineProperty(scrollingElement, "scrollTop", { configurable: true, enumerable: false, get: _scrollTopGetter, set: _scrollTopSetter }); } function disableScrolling() { window.scrollBy = _void; window.scrollTo = _void; Object.defineProperty(scrollingElement, "scrollTop", { configurable: true, enumerable: false, get: _scrollTopGetter, set: _void }); } function scrollHandler() { disableScrolling(); clearTimeout(timer); timer = setTimeout(enableScrolling, timeout); } var scrollingElement = document.scrollingElement; var _void = function() {}; var _scrollBy = window.scrollBy; var _scrollTo = window.scrollTo; var _scrollTopGetter = scrollingElement.__lookupGetter__("scrollTop"); var _scrollTopSetter = scrollingElement.__lookupSetter__("scrollTop"); var timer; scrollingElement.addEventListener("wheel", scrollHandler, { passive: false, capture: true }); window.addEventListener("wheel", scrollHandler, { passive: false, capture: true }); scrollingElement.addEventListener("mousewheel", scrollHandler, { passive: false, capture: true }); window.addEventListener("mousewheel", scrollHandler, { passive: false, capture: true }); } function isReady() { return document.readyState === "complete" || document.readyState === "interactive"; } function handleReadyStateChange() { if (isReady()) { document.removeEventListener("readystatechange", handleReadyStateChange, false); init(); } } if (isReady()) { init(); } else { document.addEventListener("readystatechange", handleReadyStateChange, false); } }; var script = document.createElement("script"); script.type = "text/javascript"; script.appendChild(document.createTextNode('(' + inject.toString() + ')();')); (document.body || document.head || document.documentElement).appendChild(script); })();