Auto Refresher

Automatically refresh websites with a config!

目前為 2021-04-12 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Auto Refresher
// @namespace    http://tampermonkey.net/
// @version      0.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
}


// —————————————————————————————— 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 (regex.test(str)) 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)]);
}