Last active
November 23, 2024 17:32
-
-
Save olejorgenb/483d632e81d818abbd61615b9823c5be to your computer and use it in GitHub Desktop.
NRK TV: Set URL to reference player's current time
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
// bookmarklet_title: NRK TV: Set URL to current time | |
// bookmarklet_about: Change the browser URL to reference to the current time. Useful to bookmark or share a video position. (shame on NRK for not exposing the better) | |
// https://gist.github.com/olejorgenb/483d632e81d818abbd61615b9823c5be | |
function main() { | |
const videoElements = document.getElementsByTagName("video") | |
if (videoElements.length !== 1) { | |
alert("More than one video element in page") | |
return | |
} | |
const video = videoElements[0] | |
const t = video.currentTime | |
const mins = Math.floor(t / 60) | |
const s = Math.floor(t % 60) | |
const timeRef = `#t=${mins}m${s}s` | |
let avspiller = "" | |
if (!location.pathname.endsWith("/avspiller")) { | |
avspiller = "/avspiller" | |
} | |
history.pushState({}, null, location.pathname + avspiller + timeRef) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://bookmarkl.ink/olejorgenb/483d632e81d818abbd61615b9823c5be