Auto Refresher

Automatically refresh websites with a config!

  1. // ==UserScript==
  2. // @name Auto Refresher
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.1
  5. // @description Automatically refresh websites with a config!
  6. // @author DeltAndy
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11.  
  12. // ———————————————————————————————————— Config —————————————————————————————————————————
  13.  
  14.  
  15. // The key is the website URL (with RegExp), and the value is the time in milliseconds
  16. const reloadPages = {
  17. ".*://www.google.com/": 5000, // This will refresh google.com every 5000 ms (5s)
  18. }
  19.  
  20.  
  21. // —————————————————————————————— Do Not Modify Below ——————————————————————————————————
  22.  
  23.  
  24. function regexMatches(arr, regex) {
  25. for (const i of arr) {
  26. var regexp = new RegExp(regex)
  27. if (i.replace(regexp, '') === '') return true
  28. }
  29. return false
  30. }
  31.  
  32. function arrayMatches(regArr, str) {
  33. for (const i of regArr) {
  34. var regexp = new RegExp(i)
  35. if (str.replace(regexp, '') === '') return true
  36. }
  37. return false
  38. }
  39. function regexIndexOf(regArr, str) {
  40. var i = 0
  41. for (const reg of regArr) {
  42. const regex = new RegExp(reg)
  43. if (str.replace(regex, '') === '') return i
  44. i++
  45. }
  46. return -1
  47. }
  48.  
  49.  
  50. var urls = []
  51. for(var key in reloadPages) urls.push(key)
  52.  
  53. const websiteRegex = new RegExp(reloadPages[window.location.href])
  54.  
  55.  
  56. if (arrayMatches(urls, window.location.href)) {
  57. console.log(`Reloading page in ${Object.values(reloadPages)[regexIndexOf(urls, window.location.href)]} ms`)
  58. setTimeout(() => {
  59. window.location = window.location
  60. }, Object.values(reloadPages)[regexIndexOf(urls, window.location.href)]);
  61. }