Skip to content

Instantly share code, notes, and snippets.

@olejorgenb
Last active November 23, 2024 17:32
Show Gist options
  • Save olejorgenb/483d632e81d818abbd61615b9823c5be to your computer and use it in GitHub Desktop.
Save olejorgenb/483d632e81d818abbd61615b9823c5be to your computer and use it in GitHub Desktop.
NRK TV: Set URL to reference player's current time
// 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()
@olejorgenb
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment