May 21, 2024 at 16:04
I was waiting for a weed delivery today and realized that login cookies were preventing a simple web-scraping bot or a Change-Detection check. The delivery was due in three hours, and I wanted to stay on top of progress updates so I could be ready outside when they arrived.
So, I made a simple Tampermonkey script that toggles auto-refresh on any site. There are existing browser extensions for this, but I don’t trust random internet strangers enough to allow them the necessary permissions. So, here we are. Hit CTRL+SHIFT+Y to toggle. “Y” can be changed to whatever.
Auto Refresh Page with Toggle
// ==UserScript==
// @name Auto Refresh Page with Toggle
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Auto-refresh the page every minute with an on/off toggle, defaulting to off
// @author Jimmy Pop (the roof, the roof, the roof is on fire)
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Set the interval time in milliseconds (60000 ms = 1 minute)
var interval = 60000;
var enabled = false;
var intervalId;
// Function to start the auto-refresh
function startAutoRefresh() {
intervalId = setInterval(function() {
location.reload();
}, interval);
console.log('Auto-refresh started');
}
// Function to stop the auto-refresh
function stopAutoRefresh() {
clearInterval(intervalId);
console.log('Auto-refresh stopped');
}
// Toggle function
function toggleAutoRefresh() {
enabled = !enabled;
if (enabled) {
startAutoRefresh();
} else {
stopAutoRefresh();
}
alert('Auto-refresh ' + (enabled ? 'enabled' : 'disabled'));
}
// Adding a keyboard shortcut (Ctrl+Shift+R) to toggle auto-refresh
document.addEventListener('keydown', function(e) {
if (e.ctrlKey && e.shiftKey && e.key === 'Y') {
toggleAutoRefresh();
}
});
})();