X (Twitter) Bookmark Scroll Position Keeper

Fixes automatic scroll to top after clicking on a bookmarked post in X (formerly Twitter) Bookmarks page

当前为 2024-08-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name X (Twitter) Bookmark Scroll Position Keeper
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Fixes automatic scroll to top after clicking on a bookmarked post in X (formerly Twitter) Bookmarks page
  6. // @match https://x.com/i/bookmarks*
  7. // @grant none
  8. // @license MIT
  9. // ==/UserScript==
  10. (function() {
  11. 'use strict';
  12.  
  13. let posY = 0;
  14.  
  15. window.addEventListener('scroll', function() {
  16. const scrollPosition = window.scrollY; // Get the vertical scroll position
  17.  
  18. if (window.scrollY === 0) {
  19. console.log("back to zero!");
  20. window.scrollTo(0, posY);
  21. }
  22. else {
  23. posY = scrollPosition;
  24. }
  25.  
  26. console.log(scrollPosition);
  27. });
  28. })();