Last active
July 21, 2019 19:05
-
-
Save cuylerstuwe/cf117bf020092a203c78f53bbf09ca1c 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 - Mark Finished Shows | |
// @namespace salembeats | |
// @version 1.4 | |
// @description UPDATE: Fix for episode URL formatting (episodes under 100 have leading zeroes in the URL). | |
// @author Cuyler Stuwe (salembeats) | |
// @include https://syntax.fm/* | |
// ==/UserScript== | |
const FINISHED_SHOW_STYLE = ` | |
opacity: 0.2; | |
`; | |
async function main() { | |
const audioEl = document.querySelector("audio"); | |
const audioPlayerEl = audioEl.parentElement; | |
const audioPlayerTitleEl = audioPlayerEl.querySelector(".player__title"); | |
const scrapeCurrentEpisodeNumber = () => audioPlayerTitleEl.innerText.match(/(?=\d+:)\d+/)[0]; | |
const formatNumberToEpisodeUrlFormat = number => (+number).toLocaleString("en-US", {minimumIntegerDigits: 3}); | |
const showLinkElForEpisode = episodeNumber => document.querySelector(`[href^="/show/${formatNumberToEpisodeUrlFormat(episodeNumber)}/"]`); | |
const markShowAsFinished = episodeNumber => { showLinkElForEpisode(episodeNumber).style = FINISHED_SHOW_STYLE; }; | |
const storeShowAsFinished = episodeNumber => { localStorage[episodeNumber] = true; }; | |
audioEl.addEventListener("ended", e => { | |
const endedEpisodeNumber = scrapeCurrentEpisodeNumber(); | |
storeShowAsFinished(endedEpisodeNumber); | |
markShowAsFinished(endedEpisodeNumber); | |
}); | |
const markAllStoredFinishedShowsAsSuch = () => { | |
const allSavedKeys = Object.keys(localStorage); | |
allSavedKeys.forEach(savedKey => Number.isInteger(+savedKey) && localStorage[savedKey] ? markShowAsFinished(savedKey) : (0)); | |
}; | |
markAllStoredFinishedShowsAsSuch(); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1.3:
Fix include path, so that the script always triggers when necessary.