Skip to content

Instantly share code, notes, and snippets.

@lucatronica
Last active February 14, 2021 12:52
Show Gist options
  • Save lucatronica/ddddfebda3f355a5a940be024a9564a4 to your computer and use it in GitHub Desktop.
Save lucatronica/ddddfebda3f355a5a940be024a9564a4 to your computer and use it in GitHub Desktop.
Convert Twitch VOD timestamps to local time, and adds a display that shows the local time for given point in the VOD.
// [INSTRUCTIONS]
// Read through this and make sure it's safe to run!
// Set the "vodStart" date to the time the VOD started.
// Paste and run it in your browser console (ctrl+shift+i) on the twitch VOD.
(() => {
// [CHANGE THIS]
// Set this string to the start time of the VOD (try using an "I'm live!" tweet to get an accurate time for this).
let vodStart = new Date(1613241580000); // new Date(Date.parse("5:39:40 AM Feb 14 2021"));
// [DO NOT CHANGE BELOW]
clearInterval(window.lucaID);
function format(n) {
return String(n).padStart(2, "0");
}
function convertElTime(el) {
let ns = el.textContent.split(":").map(s => Number(s));
let hours,mins,seconds;
if (ns.length === 2) {
hours = 0;
[mins, seconds] = ns;
} else {
[hours, mins, seconds] = ns;
}
let d = new Date(vodStart.getTime() + (seconds + mins * 60 + hours * 3600) * 1000);
return `${format(d.getHours())}:${format(d.getMinutes())}:${format(d.getSeconds())}`;
}
let currentVodTimeEl = document.querySelector("[data-a-target='player-seekbar-current-time']");
let listEl = document.querySelector(".video-chat__message-list-wrapper").firstElementChild.firstElementChild;
let currentTimeEL = document.getElementById("luca-vod-time");
if (!currentTimeEL) {
currentTimeEL = document.createElement("div");
currentTimeEL.id = "luca-vod-time";
}
currentTimeEL.style.cssText = "z-index: 9999; position: absolute; top: 0; padding: 4px; background: #181818; border: 1px solid #404040; font-size: 150%;";
document.body.append(currentTimeEL);
window.lucaID = setInterval(() => {
// Set local time element from VOD time.
currentTimeEL.textContent = convertElTime(currentVodTimeEl);
// Convert chat timestamps to local time.
for (let el of listEl.children) {
if (!el.dataset.ts) {
el.dataset.ts = "1";
let tse = el.querySelector("button p");
tse.textContent = convertElTime(tse);
}
}
}, 500);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment