Disable NYTimes Blog Smooth-Scrolling

Disables the smooth scrolling done by site's script

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Disable NYTimes Blog Smooth-Scrolling
// @namespace   DisableNYTimesBlogSmoothScrolling
// @description Disables the smooth scrolling done by site's script
// @author      jcunews
// @match       *://*.nytimes.com/*
// @version     1.0.1
// @grant       none
// @run-at      document-start
// ==/UserScript==

(function() {
  var ele = document.createElement("SCRIPT");

  ele.text = "(" + (function() {

    var orgKeyDownHandler;
    
    //save original document's addEventListener function
    var docAddEventListener = document.addEventListener;

    //our keydown handler
    function newKeyDownHandler(ev) {
      //check key pressed
      switch (ev.key) {
        case "PageDown":
        case "PageUp":
        case " ": //spacebar
          //don't call original handler for these keys
          break;
        default:
          //call original handler for other keys
          return orgKeyDownHandler.apply(this, arguments);
      }
    }

    //hook document's addEventListener function
    document.addEventListener = function(name, func, capture) {
      if ((name === "keydown") && !orgKeyDownHandler) {
        //use our handler for keydown event
        orgKeyDownHandler = func; //save original handler
        func = newKeyDownHandler; //replace it with our handler
      }
      return docAddEventListener.apply(this, arguments);
    };

  }).toString() + ")()";

  document.head.appendChild(ele);
})();