developer.chrome.com fast back/forward

Makes back/forward navigation fast as they should be instead of half a second

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        developer.chrome.com fast back/forward
// @namespace   https://greasyfork.org/en/users/2159-woxxom
// @description Makes back/forward navigation fast as they should be instead of half a second
// @version     1.0.1
// @license     MIT
// @match       https://developer.chrome.com/*
// @run-at      document-start
// @grant       none
// ==/UserScript==

const {addEventListener} = window;
window.addEventListener = function (type) {
  if (type !== 'popstate') addEventListener.apply(this, arguments);
};
Object.defineProperty(history, 'scrollRestoration', {
  value: history.scrollRestoration = 'auto',
  writable: false,
});
addEventListener('click', e => {
  const a = e.target.closest('a');
  if (a && a.href && a.getAttribute('href') !== '#') {
    e.stopPropagation();
    a.click();
    if (!document.getElementById(a.hash.slice(1)))
      (document.querySelector('h1') || document.body).scrollIntoView();
    requestAnimationFrame(() => scrollBy(0, -30));
  }
}, true);