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 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
})();