Skip to content

Instantly share code, notes, and snippets.

@panphora
Last active January 22, 2020 17:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panphora/2dcd1e23b6ee3893a03ff242e3d89d4d to your computer and use it in GitHub Desktop.
Save panphora/2dcd1e23b6ee3893a03ff242e3d89d4d to your computer and use it in GitHub Desktop.
var $activeEpisodes = $(".episodecell");
var episodesReversedElements = $activeEpisodes.toArray().reverse();
var lastPodcastName;
episodesReversedElements.forEach(function (elem) {
var $activeEpisode = $(elem);
var podcastName = $activeEpisode.find(".titlestack div:first-child").text();
var podcastImgSrc = $activeEpisode.find(".art").attr("src");
if (podcastName !== lastPodcastName) {
makeActivePodcastCell(podcastName, podcastImgSrc);
}
lastPodcastName = podcastName;
});
function makeActivePodcastCell (podcastName, imgSrc) {
var $episodeCell = $activeEpisodes.first();
var $cell = $episodeCell.clone();
$cell.find(".art").attr("src", imgSrc);
$cell.find(".caption2.singleline").text("");
$cell.find(".title.singleline").text(podcastName);
$cell.insertAfter(".ocseparatorbar:first");
$cell.on("click", function (event) {
event.preventDefault();
replaceWithEpisodes($cell, podcastName);
});
}
function replaceWithEpisodes ($elem, podcastName) {
var episodesWithPodcastName = episodesReversedElements.filter(function (elem) {
return $(elem).find(".titlestack div:first-child").text() === podcastName;
});
$elem.replaceWith($(episodesWithPodcastName).show());
}
$activeEpisodes.hide();
// update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment