developer.chrome.com fast back/forward

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

  1. // ==UserScript==
  2. // @name developer.chrome.com fast back/forward
  3. // @namespace https://greasyfork.org/en/users/2159-woxxom
  4. // @description Makes back/forward navigation fast as they should be instead of half a second
  5. // @version 1.0.1
  6. // @license MIT
  7. // @match https://developer.chrome.com/*
  8. // @run-at document-start
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. const {addEventListener} = window;
  13. window.addEventListener = function (type) {
  14. if (type !== 'popstate') addEventListener.apply(this, arguments);
  15. };
  16. Object.defineProperty(history, 'scrollRestoration', {
  17. value: history.scrollRestoration = 'auto',
  18. writable: false,
  19. });
  20. addEventListener('click', e => {
  21. const a = e.target.closest('a');
  22. if (a && a.href && a.getAttribute('href') !== '#') {
  23. e.stopPropagation();
  24. a.click();
  25. if (!document.getElementById(a.hash.slice(1)))
  26. (document.querySelector('h1') || document.body).scrollIntoView();
  27. requestAnimationFrame(() => scrollBy(0, -30));
  28. }
  29. }, true);