RSS: FreshRSS Filter Articles by Title (Obsolete)

Add a button to filter articles based on whether their title contains the ⏳ emoji (after reading time generation)

  1. // ==UserScript==
  2. // @name RSS: FreshRSS Filter Articles by Title (Obsolete)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.9
  5. // @homepage https://greasyfork.org/en/scripts/526410
  6. // @description Add a button to filter articles based on whether their title contains the ⏳ emoji (after reading time generation)
  7. // @author You
  8. // @match http://192.168.1.2:1030/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Variable to track the hidden state
  16. let isHidden = false;
  17.  
  18. // Function to filter divs
  19. function filterDivs() {
  20. const divs = document.querySelectorAll('.flux');
  21.  
  22. divs.forEach(div => {
  23. const titleElement = div.querySelector('.title');
  24. if (titleElement) {
  25. const titleText = titleElement.textContent || titleElement.innerText;
  26. if (!titleText.includes('⏳')) {
  27. div.style.display = isHidden ? '' : 'none';
  28. }
  29. }
  30. });
  31.  
  32. // Toggle the button text
  33. const button = document.getElementById('filterButton');
  34. if (button) {
  35. button.textContent = isHidden ? '⏳' : '🌎';
  36. }
  37.  
  38. // Toggle the hidden state
  39. isHidden = !isHidden;
  40. }
  41.  
  42. // Function to load all articles
  43. async function loadAllArticles() {
  44. const loadMoreButton = document.getElementById('load_more');
  45. if (loadMoreButton && !loadMoreButton.disabled) {
  46. // Show loading hint
  47. const loadingHint = document.getElementById('loadingHint');
  48. if (loadingHint) {
  49. loadingHint.style.display = 'block';
  50. }
  51.  
  52. loadMoreButton.click(); // Click the "Load more articles" button
  53. await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for articles to load
  54. await loadAllArticles(); // Recursively load more articles
  55.  
  56. // Hide loading hint after loading is complete
  57. if (loadingHint) {
  58. loadingHint.style.display = 'none';
  59. }
  60. }
  61. }
  62.  
  63. // Create the button
  64. const button = document.createElement('a');
  65. button.id = 'filterButton';
  66. button.className = 'btn'; // Match the class of other navigation buttons
  67. button.href = '#'; // Add a placeholder href to match the style
  68. button.title = 'Filter by ⏳'; // Add a tooltip
  69. button.textContent = '⏳'; // Use emoji directly
  70.  
  71. // Create the loading hint element
  72. const loadingHint = document.createElement('div');
  73. loadingHint.id = 'loadingHint';
  74. loadingHint.textContent = 'Loading all articles...';
  75. loadingHint.style.display = 'none'; // Initially hidden
  76. loadingHint.style.marginTop = '10px';
  77. loadingHint.style.fontStyle = 'italic';
  78. loadingHint.style.color = '#666';
  79.  
  80. // Add click event listener to the button
  81. button.addEventListener('click', async (e) => {
  82. e.preventDefault(); // Prevent the default link behavior
  83.  
  84. // Load all articles before filtering
  85. await loadAllArticles();
  86.  
  87. // Filter the articles
  88. filterDivs();
  89. });
  90.  
  91. // Find the last .group div and insert the button and loading hint after it
  92. const lastGroupDiv = document.querySelector('.group:last-of-type');
  93. if (lastGroupDiv) {
  94. lastGroupDiv.parentNode.insertBefore(button, lastGroupDiv.nextSibling);
  95. lastGroupDiv.parentNode.insertBefore(loadingHint, button.nextSibling);
  96. } else {
  97. console.error('Could not find the last .group element.');
  98. }
  99. })();