Miniflux automatically refresh feeds

Automatically refreshes Miniflux feeds

当前为 2024-07-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Miniflux automatically refresh feeds
  3. // @namespace https://reader.miniflux.app/
  4. // @version 12
  5. // @description Automatically refreshes Miniflux feeds
  6. // @author Tehhund
  7. // @match *://*.miniflux.app/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=miniflux.app
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. let apiKey = ''; // Put your API key from Miniflux here.
  13. const rateLimit = 43200000; // Only refresh twice per day. 43200000 miliseconds = 12 hours. If a feed has an error (e.g., too many requests) its checked_at datetime still gets updated so we won't hit the feeds with too many requests.
  14.  
  15. const refreshFeeds = async () => {
  16. if (!apiKey) { // If the API key isn't specified, try getting it from localstorage.
  17. apiKey = localStorage.getItem('miniFluxRefresherApiKey');
  18. } else { // If we have the API key, store it in localstorage.
  19. localStorage.setItem('miniFluxRefresherApiKey', apiKey)
  20. }
  21. let req = await fetch('https://reader.miniflux.app/v1/feeds', { headers: { 'X-Auth-Token': apiKey } });
  22. let res = JSON.parse(await req.text());
  23. let feedsArray = res.map(currentFeed => currentFeed);
  24. console.log(feedsArray);
  25. feedsArray.sort((a, b) => {
  26. return (new Date(a.checked_at).getTime() - new Date(b.checked_at).getTime()); // Sort from last checked to most recently checked.
  27. })
  28. for (let [index, feed] of feedsArray.entries()) {
  29. let lastChecked = new Date(feed.checked_at).getTime();
  30. if (Date.now() - lastChecked > rateLimit) {
  31. console.log(`It's been more than 24 hours, refresh.`);
  32. setTimeout(
  33. async () => {
  34. let res = await fetch(`https://reader.miniflux.app/v1/feeds/${feed.id}/refresh`, {
  35. method: "PUT",
  36. headers: { 'X-Auth-Token': apiKey }
  37. });
  38. console.log(res);
  39. }, 15000 * index); // Make a call every 15 seconds.
  40. } else console.log(`It's been less than 24 hours, do nothing.`)
  41. }
  42. }
  43.  
  44. // run once when the page is loaded.
  45. window.addEventListener("DOMContentLoaded", refreshFeeds);