Created
March 14, 2023 01:11
-
-
Save adntaha/59b455d947c6c4ff30ce10d920dddb9e to your computer and use it in GitHub Desktop.
Add a timestamp on the Twitch stream itself
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
(() => { | |
const liveTime = document.querySelector('.live-time'); | |
const style = document.createElement("style"); | |
style.id = 'on-video-time-style'; | |
style.textContent = `#on-video-time { | |
position: absolute; | |
padding: .5rem; | |
top: 0; | |
right: .3rem; | |
z-index: 9999; | |
color: white; | |
font-size: 3rem; | |
font-weight: bold; | |
text-shadow: 0 0 2px black; | |
}`; | |
document.head.appendChild(style); | |
const onVideoTime = document.createElement('div'); | |
onVideoTime.id = 'on-video-time'; | |
onVideoTime.textContent = liveTime.textContent; | |
const videoContainer = document.querySelector(".video-ref"); | |
videoContainer.insertBefore(onVideoTime, videoContainer.children[0]) | |
const observer = new MutationObserver((mutations) => { | |
for (const mutation of mutations) { | |
if (mutation.type === 'characterData') { | |
onVideoTime.textContent = mutation.target.textContent | |
} | |
} | |
}); | |
observer.observe(liveTime, { | |
characterData: true, | |
subtree: true | |
}); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment