Created
March 20, 2021 02:09
-
-
Save betaveros/42079a064002360d32cce4b48a1c13b5 to your computer and use it in GitHub Desktop.
pancakescon timezone converter
This file contains hidden or 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 pancakescon timezone converter | |
// @version 1 | |
// @namespace https://beta.vero.site/ | |
// @include https://pancakescon.com/attend/ | |
// @grant none | |
// @description poorly translate the times to your local time zone on pancakescon.com | |
// ==/UserScript== | |
function signed(n) { | |
return ((n >= 0) ? '+' : '') + n; | |
} | |
function pad2(s) { | |
s = String(s); | |
return '0'.repeat(Math.max(0, 2 - s.length)) + s; | |
} | |
const tds = document.querySelectorAll('figure.is-style-stripes table td:first-child'); | |
const utcOffset = -new Date().getTimezoneOffset(); // UTC to local | |
// why is this negative?? one can only speculate... | |
// https://stackoverflow.com/questions/21102435/why-does-javascript-date-gettimezoneoffset-consider-0500-as-a-positive-off | |
const offset = utcOffset + 300; // UTC-5 to local | |
for (let td of tds) { | |
td.textContent = td.textContent.replaceAll(/\b\d{4}\b/g, (s) => { | |
let allMins = 60 * Number(s.substr(0, 2)) + Number(s.substr(2, 4)) + offset; | |
let days = Math.floor(allMins / 1440); | |
let dayMins = allMins - (days * 1440); | |
let res = pad2(Math.floor(dayMins / 60)) + ':' + pad2(dayMins % 60); | |
if (days !== 0) res = '(' + signed(days) + ')' + res; | |
return res; | |
}); | |
} | |
document.querySelector('figure.is-style-stripes table th:first-child').textContent = 'UTC' + signed(utcOffset/60); | |
for (let disclaimer of document.querySelectorAll('strong')) { | |
console.log(disclaimer.textContent); | |
if (disclaimer.textContent.startsWith('All times')) { | |
disclaimer.style.textDecoration = 'line-through'; | |
disclaimer.parentNode.appendChild(document.createTextNode(' Questionably converted to UTC' + signed(utcOffset/60))); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment