Hackernews Scroll to Next Top-Level Comment

Adds a button that scroll to quickly and smoothly navigate to the next top-level comment. This scroller saves time by allowing you to skip comment threads you're not interested in. An alternative to collapsing the thread.

当前为 2023-01-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hackernews Scroll to Next Top-Level Comment
  3. // @namespace https://news.ycombinator.com/
  4. // @version 0.1
  5. // @description Adds a button that scroll to quickly and smoothly navigate to the next top-level comment. This scroller saves time by allowing you to skip comment threads you're not interested in. An alternative to collapsing the thread.
  6. // @author Jonathan Woolf
  7. // @match https://news.ycombinator.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. const button = document.createElement('button');
  14. button.textContent = '⬇️';
  15. button.style.cssText = `
  16. position: fixed;
  17. bottom: 10px;
  18. left: 10px;
  19. z-index: 999;
  20. background-color: rgb(255, 198, 156);
  21. color: #fff;
  22. border: 6px solid rgb(255, 102, 0);
  23. background-color: rgb(255, 198, 156);
  24. border-radius: 50%;
  25. width: 40px;
  26. height: 40px;
  27. font-size: 24px;
  28. text-align: center;
  29. line-height: 40px;
  30. cursor: pointer;
  31. display: flex;
  32. justify-content: center;
  33. align-items: center;
  34. font-size: 91%;
  35. `;
  36. document.body.appendChild(button);
  37.  
  38. const comments = [...document.querySelectorAll('td.ind[indent="0"]')];
  39. let currentCommentIndex = 0;
  40.  
  41. button.addEventListener('click', () => {
  42. if (currentCommentIndex === comments.length - 1) {
  43. currentCommentIndex = 0;
  44. } else {
  45. currentCommentIndex++;
  46. }
  47. comments[currentCommentIndex].closest('tr').scrollIntoView({ behavior: 'smooth', block: 'start' });
  48. });
  49. })();