-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuto Refresher.user.js
61 lines (47 loc) · 1.89 KB
/
Auto Refresher.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// ==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)]);
}