Skip to content

Instantly share code, notes, and snippets.

@cuylerstuwe
Last active July 21, 2019 19:05
Show Gist options
  • Save cuylerstuwe/cf117bf020092a203c78f53bbf09ca1c to your computer and use it in GitHub Desktop.
Save cuylerstuwe/cf117bf020092a203c78f53bbf09ca1c to your computer and use it in GitHub Desktop.
// ==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();
@cuylerstuwe
Copy link
Author

1.3:

Fix include path, so that the script always triggers when necessary.

@cuylerstuwe
Copy link
Author

1.4:

Fix for episode URL formatting (episodes under 100 have leading zeroes in the URL):

Leading Zeroes Episode URL Example

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