Auto Refresher

Automatically refresh websites with a config!

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Auto Refresher
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  Automatically refresh websites with a config!
// @author       DeltAndy
// @match        *://*/*
// @grant        none
// ==/UserScript==


// ———————————————————————————————————— Config —————————————————————————————————————————


// The key is the website URL (with RegExp), and the value is the time in milliseconds
const reloadPages = {
    ".*://www.google.com/": 5000, // This will refresh google.com every 5000 ms (5s)
}


// —————————————————————————————— Do Not Modify Below ——————————————————————————————————


function regexMatches(arr, regex) {
    for (const i of arr) {
        var regexp = new RegExp(regex)
        if (i.replace(regexp, '') === '') return true
    }
    return false
}

function arrayMatches(regArr, str) {
    for (const i of regArr) {
        var regexp = new RegExp(i)
        if (str.replace(regexp, '') === '') return true
    }
    return false
}
function regexIndexOf(regArr, str) {
    var i = 0
    for (const reg of regArr) {
        const regex = new RegExp(reg)
        if (str.replace(regex, '') === '') return i
        i++
    }
    return -1
}


var urls = []
for(var key in reloadPages) urls.push(key)

const websiteRegex = new RegExp(reloadPages[window.location.href])


if (arrayMatches(urls, window.location.href)) {
    console.log(`Reloading page in ${Object.values(reloadPages)[regexIndexOf(urls, window.location.href)]} ms`)
    setTimeout(() => {
        window.location = window.location
    }, Object.values(reloadPages)[regexIndexOf(urls, window.location.href)]);
}