FreshRSS Double-Tap and Auto-Scroll

Double-tap to close active articles and auto-scroll to the active article in FreshRSS.

当前为 2025-02-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name FreshRSS Double-Tap and Auto-Scroll
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Double-tap to close active articles and auto-scroll to the active article in FreshRSS.
  6. // @author Your Name
  7. // @homepage https://greasyfork.org/en/scripts/525912
  8. // @match http://192.168.1.2:1030/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. // Double-tap event to close active articles
  16. document.addEventListener('dblclick', function (event) {
  17. // Check if the double-tap is on an interactive element
  18. const interactiveElements = ['A', 'BUTTON', 'INPUT', 'TEXTAREA', 'SELECT', 'LABEL'];
  19. if (interactiveElements.includes(event.target.tagName)) {
  20. return; // Ignore double-taps on interactive elements
  21. }
  22.  
  23. // Find the closest element with 'active' classes
  24. const activeElement = event.target.closest('.active');
  25. if (activeElement) {
  26. // Remove the 'active' class
  27. activeElement.classList.remove('active');
  28. // console.log('Removed "active" class from:', activeElement);
  29.  
  30. // Scroll the page to the closed article (activeElement)
  31. activeElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
  32. }
  33. });
  34.  
  35. // Automatically scroll to the active article when it gains the 'active' class
  36. const observeActiveElements = () => {
  37. // Set up a MutationObserver to watch for changes to the 'active' class
  38. const observer = new MutationObserver((mutations) => {
  39. mutations.forEach((mutation) => {
  40. if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
  41. const targetElement = mutation.target;
  42. if (targetElement.classList.contains('active')) {
  43. // Scroll the active element into view
  44. targetElement.scrollIntoView({ behavior: 'smooth', block: 'top' });
  45. }
  46. }
  47. });
  48. });
  49.  
  50. // Observe all elements with the 'flux' class (potential candidates for 'active')
  51. const currentElements = document.querySelectorAll('.flux');
  52. currentElements.forEach((element) => {
  53. observer.observe(element, { attributes: true });
  54. });
  55. };
  56.  
  57. // Start observing for changes
  58. observeActiveElements();
  59. })();