Last active
December 1, 2023 10:31
-
-
Save mschmitt/b340605fbe20257be0bc06d1bc614d04 to your computer and use it in GitHub Desktop.
Reload-At-Wallclock.user.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Reload at Wallclock | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Reload at Wallclock | |
// @author You | |
// @match http://worldtimeapi.org/api/timezone/Europe/Berlin.txt | |
// @match https://tickets.events.ccc.de/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Edit here: ///////////////////////////////////// | |
var target_datetime='1970-12-02T15:00:00.000+0100'; | |
/////////////////////////////////////////////////// | |
var target = new Date(target_datetime); | |
console.log("Userscript: " + target_datetime + " parsed as " + target.toLocaleString() + ", " + target.getMilliseconds() + "ms"); | |
var now = new Date(); | |
if (target < now){ | |
console.log("Userscript: Too late to reload at " + target.toLocaleString() + ", " + target.getMilliseconds() + "ms"); | |
} else { | |
console.log("Userscript: Valid reload time: " + target.toLocaleString() + ", " + target.getMilliseconds() + "ms"); | |
var diff_ms = target - now; | |
setTimeout(function() { location.reload() }, diff_ms); | |
console.log("Userscript: Timeout set. Will reload in: " + diff_ms + " ms"); | |
window.setInterval(function() { console.log("Userscript: " + Math.floor((target - new Date()) / 1000) + " s remaining.") }, 10000); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment