Tumblr - Remember scroll position

Remembers the scrolling position you left on the thing you're searching on Tumblr.

  1. // ==UserScript==
  2. // @name Tumblr - Remember scroll position
  3. // @namespace https://myanimelist.net/profile/kyoyatempest
  4. // @match https://www.tumblr.com/search/*
  5. // @version 1.1
  6. // @author kyoyacchi
  7. // @description Remembers the scrolling position you left on the thing you're searching on Tumblr.
  8. // @icon https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://tumblr.com&size=64
  9. // @license gpl-3.0
  10. // ==/UserScript==
  11. window.onbeforeunload = function () {
  12. var scrollPos;
  13. if (typeof window.pageYOffset != 'undefined') {
  14. scrollPos = window.pageYOffset;
  15. }
  16. else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
  17. scrollPos = document.documentElement.scrollTop;
  18. }
  19. else if (typeof document.body != 'undefined') {
  20. scrollPos = document.body.scrollTop;
  21. }
  22. document.cookie = "scrollTop=" + scrollPos + "URL=" + window.location.href;
  23. }
  24.  
  25. window.onload = function () {
  26. if (document.cookie.includes(window.location.href)) {
  27. if (document.cookie.match(/scrollTop=([^;]+)(;|$)/) != null) {
  28. var arr = document.cookie.match(/scrollTop=([^;]+)(;|$)/);
  29. document.documentElement.scrollTop = parseInt(arr[1]);
  30. document.body.scrollTop = parseInt(arr[1]);
  31. }
  32. }
  33. // console.log("hmm?")
  34. }
  35.  
  36. //https://stackoverflow.com/a/65746118/19276081