Greasy Fork is available in English.

Miniflux automatically refresh feeds

Automatically refreshes Miniflux feeds

Verzia zo dňa 26.04.2023. Pozri najnovšiu verziu.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==UserScript==
// @name         Miniflux automatically refresh feeds
// @namespace    https://reader.miniflux.app/
// @version      3
// @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 = 300000; // time in miliseconds that must pass before it refreshes the feeds. 3600000 = 1 hour. 300000 = 5 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 jsTime = getLastUpdateTime();
  let now = new Date().getTime();
  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; }
  return shouldUpdate;
}

const getLastUpdateTime = async () => {
  // Try to get time from localstorage.
  let earliestTime = localStorage.getItem('lastRefreshTime');
  // If it's not in localstorage, get time from feeds and store the earliest time.
  if (earliestTime == null) {
    let req = await fetch('https://reader.miniflux.app/v1/feeds', { headers: { 'X-Auth-Token': apiKey } });
    let res = JSON.parse(await req.text());
    let timesArray = res.map(currentFeed => Date.parse(currentFeed.checked_at)); // returns an array of each feed's checked_at.
    earliestTime = Math.min(...timesArray); // Instead of comparing in a For loop, let Math.min return the lowest value which is the earliest time.
    localStorage.setItem('lastRefreshTime', earliestTime);
  } else { console.log('lastRefreshTime was in localStorage: ' + earliestTime);}
  return earliestTime;
}

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