Miniflux automatically refresh feeds

Automatically refreshes Miniflux feeds

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

  1. // ==UserScript==
  2. // @name Miniflux automatically refresh feeds
  3. // @namespace https://reader.miniflux.app/
  4. // @version 9
  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. const 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. let req = await fetch('https://reader.miniflux.app/v1/feeds', { headers: { 'X-Auth-Token': apiKey } });
  17. let res = JSON.parse(await req.text());
  18. let feedsArray = res.map(currentFeed => currentFeed);
  19. for (let feed of feedsArray) {
  20. let lastChecked = new Date(feed.checked_at).getTime();
  21. if (Date.now() - lastChecked > rateLimit) {
  22. console.log('it\'s been more than 24 hours, refresh.');
  23. let res = await fetch(`https://reader.miniflux.app/v1/feeds/${feed.id}/refresh`, {
  24. method: "PUT",
  25. headers: { 'X-Auth-Token': apiKey }
  26. });
  27. console.log(res);
  28. } else console.log('it\'s been less than 24 hours, do nothing.')
  29. }
  30. }
  31.  
  32. // run once when the page is loaded.
  33. try { refreshFeeds(); } catch (e) { }// If the script runs after DOMContentLoaded this will add the links. If it runs before DOMContentLoaded, this will error and the listener below will run it instead.
  34. window.addEventListener("DOMContentLoaded", refreshFeeds);