Created
January 24, 2023 21:12
-
-
Save r3Fuze/99e7f4ceee6bd8bd8a408bb4dbe3eb73 to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name Syntax.fm timestamp seek | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Make timestamps seek the playback instead of loading new page | |
// @author fz | |
// @match https://syntax.fm/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
const convertTimeToSeconds = (time) => { | |
const minutes = time.split(":")[0] | |
const seconds = time.split(":")[1] | |
return parseInt(minutes, 10) * 60 + parseInt(seconds, 10) | |
} | |
const onClickEvent = (e) => { | |
e.preventDefault() | |
const time = convertTimeToSeconds(e.target.href.split("#t=")[1]) | |
audio.fastSeek(time) | |
} | |
const addListeners = () => { | |
document.querySelectorAll("a[href^='#t']").forEach((a) => { | |
a.addEventListener("click", onClickEvent) | |
}) | |
} | |
const audio = document.querySelector("audio") | |
addListeners() | |
const observer = new MutationObserver((mutations) => { | |
mutations.forEach((mutation) => { | |
if (!mutation.addedNodes) return | |
addListeners() | |
}) | |
}) | |
observer.observe(document.querySelector(".showNotes"), { | |
childList: true, | |
subtree: true, | |
attributes: false, | |
characterData: false, | |
}) | |
document.querySelectorAll(".showList .show").forEach((show) => { | |
if (show.classList.contains("show--dummy")) return | |
const episodeNumber = parseInt(show.querySelector(".show__link .show__displayNumber").innerText.split(" ")[1], 10) | |
const playedTime = JSON.parse(localStorage.getItem(`lastPlayed${episodeNumber}`)) | |
if (playedTime?.lastPlayed > 0) { | |
show.style.backgroundColor = "rgb(235, 255, 192)" | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment