Miniflux automatically refresh feeds

Automatically refreshes Miniflux feeds

Από την 23/04/2023. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Miniflux automatically refresh feeds
// @namespace    https://reader.miniflux.app/
// @version      2
// @description  Automatically refreshes Miniflux feeds
// @author       Tehhund
// @match        *://*.miniflux.app/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=miniflux.app
// @grant        none
// ==/UserScript==

const apiKey = '';
const rateLimit = 600000; // time in miliseconds that must pass before it refreshes the feeds. 3600000 = 1 hour. 300000 = 5 minutes. 600000 = 10 minutes.

const refreshFeeds = async () => {
  if (await shouldUpdate()) {
    console.log('Miniflux: Time to refresh');
    let req = await fetch('https://reader.miniflux.app/v1/feeds/refresh', {
      method: "PUT",
      headers: {
        'X-Auth-Token': apiKey
      }
    });
    let res = await req;
    if (res.status == 204) { console.log('Successfully started refresh on all feeds.'); } else { console.log('Error, Miniflux did not return a 204 status.'); }
  } else { console.log('Miniflux: Not time to refresh yet.'); }
}

const shouldUpdate = async () => {
  let shouldUpdate = false;
  let req = await fetch('https://reader.miniflux.app/v1/feeds', {
    headers: {
      'X-Auth-Token': apiKey
    }
  });
  let res = JSON.parse(await req.text());
  let now = new Date().getTime();
  for (let feed of res) {
    let jsTime = Date.parse(feed.checked_at);
    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.
    if (difference > rateLimit) {
      shouldUpdate = true;
      break; // If even one is out-of-date, refresh. No need to keep checking
    }
  }
  return shouldUpdate;
}

// run once when the page is loaded.
refreshFeeds();