Miniflux automatically refresh feeds

Automatically refreshes Miniflux feeds

当前为 2023-04-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Miniflux automatically refresh feeds
  3. // @namespace https://reader.miniflux.app/
  4. // @version 2
  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. // @grant none
  10. // ==/UserScript==
  11.  
  12. const apiKey = '';
  13. const rateLimit = 600000; // time in miliseconds that must pass before it refreshes the feeds. 3600000 = 1 hour. 300000 = 5 minutes. 600000 = 10 minutes.
  14.  
  15. const refreshFeeds = async () => {
  16. if (await shouldUpdate()) {
  17. console.log('Miniflux: Time to refresh');
  18. let req = await fetch('https://reader.miniflux.app/v1/feeds/refresh', {
  19. method: "PUT",
  20. headers: {
  21. 'X-Auth-Token': apiKey
  22. }
  23. });
  24. let res = await req;
  25. if (res.status == 204) { console.log('Successfully started refresh on all feeds.'); } else { console.log('Error, Miniflux did not return a 204 status.'); }
  26. } else { console.log('Miniflux: Not time to refresh yet.'); }
  27. }
  28.  
  29. const shouldUpdate = async () => {
  30. let shouldUpdate = false;
  31. let req = await fetch('https://reader.miniflux.app/v1/feeds', {
  32. headers: {
  33. 'X-Auth-Token': apiKey
  34. }
  35. });
  36. let res = JSON.parse(await req.text());
  37. let now = new Date().getTime();
  38. for (let feed of res) {
  39. let jsTime = Date.parse(feed.checked_at);
  40. let difference = now - jsTime; // JS stores time like Unix but miliseconds since January 01, 1970 00:00:00 UTC instead of seconds, so this subtracts miliseconds from miliseconds.
  41. if (difference > rateLimit) {
  42. shouldUpdate = true;
  43. break; // If even one is out-of-date, refresh. No need to keep checking
  44. }
  45. }
  46. return shouldUpdate;
  47. }
  48.  
  49. // run once when the page is loaded.
  50. refreshFeeds();