Skip to content

Instantly share code, notes, and snippets.

@mschmitt
Last active December 1, 2023 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mschmitt/b340605fbe20257be0bc06d1bc614d04 to your computer and use it in GitHub Desktop.
Save mschmitt/b340605fbe20257be0bc06d1bc614d04 to your computer and use it in GitHub Desktop.
Reload-At-Wallclock.user.js
// ==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