Don't fuck with my scroll!!!

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.

目前為 2019-04-11 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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);
})();