Instantly share code, notes, and snippets.
Last active
November 16, 2020 11:31
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save paulera/50769789249564c6fbdc86ab4b740b9e to your computer and use it in GitHub Desktop.
Tampermonkey script that adds a "Random" button to TV Shows episodes list in the streaming service ororo.tv
This file contains hidden or 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
/*** | |
This script works only in ororo.tv. It adds a "Random" button in "TV Show" episodes list. | |
To activate it: | |
method 1: On a TV Show episodes list page, open the console, copy and paste all this code, and press enter. | |
method 2: Create an entry in your bookmarks called "Ororo random episode" with the url exacty as below. Use it in TV Show episodes list. | |
javascript:function openRandomEpisode(){do{episodeInfo=getRandomEpisode()}while(window.episodes.length&&window.prioritizeUnwatched&&episodeInfo.watched&&!window.allEpisodesWatched);0==window.episodes.length&&episodeInfo.watched&&(console.log("Could not find an unwatched episode"),window.allEpisodesWatched=!0),activateSeason(episodeInfo.season),scrollToEpisode(episodeInfo),console.log("Start episode: Season "+episodeInfo.season+" Episode "+episodeInfo.number),episodeInfo.linkElement.click()}function getRandomEpisode(){return window.getRandomEpisodeCount++,console.log("Looking for a random episode (try #"+window.getRandomEpisodeCount+")"),0==window.episodes.length&&(window.episodes=$(".show-content__episode-list .js-season-tab .js-episode-wrapper .episode-box"),console.log("Acquiring list of episodes"),window.getRandomEpisodeCount=0),episodeIndex=Math.floor(Math.random()*window.episodes.length),$episode=$(window.episodes.splice(episodeIndex,1)),episodeInfo={element:$episode,season:$episode.parent().parent().parent().attr("id"),number:parseInt($episode.parent().find(".js-num-episode").html()),watched:$episode.find(".mark-watched").attr("class").indexOf(" watched")>0,linkElement:$episode.find("a.js-episode")},console.log("Chosen episode:"),console.log(episodeInfo),episodeInfo.watched?console.log("WATCHED"):console.log("NEW"),episodeInfo}function activateSeason(e){console.log("Activate season "+e),$($(".show-content__season-list").children()[e-1]).find("a").click()}function scrollToEpisode(e){console.log("Scrolling to episode"),duration=400,$("html,body").animate({scrollTop:e.element.offset().top-e.element.height()-$(".site-header").height(),easing:"swing"},duration),$(".show-content__episode-list .js-season-tab .js-episode-wrapper").css("background-color","transparent"),e.element.parent().css("background-color","#ddeaff")}window.episodes=[],window.getRandomEpisodeCount=0,window.allEpisodesWatched=!1,window.prioritizeUnwatched=!1,$(document).ready(function(){setTimeout(function(){$('<span class="random"><div class="ui button show-trailer__button"><i title="Random" class="fa fa-random"></i> Random</div></span>').insertAfter(".poster-image").click(openRandomEpisode),$(".show-trailer").css("display","inline").css("margin-bottom","15px"),$(".random").css("display","inline-block").css("margin-bottom","15px")},50)}); | |
method 3: Use the extension Tampermonkey (Chrome) or Greasemonkey (Firefox) and add this whole code as a new userscript. | |
This is provided "as it is" with no license, support whatsoever. | |
***/ | |
// ==UserScript== | |
// @name Ororo.tv random episode | |
// @namespace http://paulera.com.br | |
// @version 1.0 | |
// @description Add a "Random" button in ororo.tv episodes list for TV Shows | |
// @author Paulo Amaral | |
// @match https://ororo.tv/en/shows/* | |
// @grant none | |
// ==/UserScript== | |
window.episodes = []; | |
window.getRandomEpisodeCount = 0; | |
window.allEpisodesWatched = false; | |
window.prioritizeUnwatched = false; // set to true to pick from unwatched first if any | |
function openRandomEpisode() { | |
do { | |
episodeInfo = getRandomEpisode(); | |
} while (window.episodes.length && window.prioritizeUnwatched && episodeInfo.watched && !window.allEpisodesWatched); | |
if (window.episodes.length == 0 && episodeInfo.watched) { | |
console.log("Could not find an unwatched episode"); | |
window.allEpisodesWatched = true; | |
} | |
activateSeason(episodeInfo.season); | |
scrollToEpisode(episodeInfo); | |
console.log("Start episode: Season " + episodeInfo.season + " Episode " + episodeInfo.number); | |
episodeInfo.linkElement.click(); | |
} | |
function getRandomEpisode() { | |
window.getRandomEpisodeCount++; | |
console.log("Looking for a random episode (try #" + window.getRandomEpisodeCount + ")"); | |
if (window.episodes.length == 0) { | |
window.episodes = $(".show-content__episode-list .js-season-tab .js-episode-wrapper .episode-box"); | |
console.log("Acquiring list of episodes"); | |
window.getRandomEpisodeCount = 0; | |
} | |
episodeIndex = Math.floor(Math.random() * window.episodes.length); | |
$episode = $(window.episodes.splice(episodeIndex, 1)); | |
episodeInfo = { | |
"element": $episode, | |
"season": $episode.parent().parent().parent().attr('id'), | |
"number": parseInt($episode.parent().find(".js-num-episode").html()), | |
"watched": $episode.find(".mark-watched").attr('class').indexOf(" watched") > 0, | |
"linkElement": $episode.find("a.js-episode") | |
}; | |
console.log("Chosen episode:"); | |
console.log (episodeInfo); | |
if (episodeInfo.watched) { | |
console.log ("WATCHED"); | |
} else { | |
console.log ("NEW"); | |
} | |
return episodeInfo; | |
} | |
function activateSeason(seasonNumber) { | |
console.log("Activate season " + seasonNumber); | |
$($(".show-content__season-list").children()[seasonNumber - 1]).find("a").click(); | |
} | |
function scrollToEpisode(episodeInfo) { | |
console.log("Scrolling to episode"); | |
duration = 400; // miliseconds | |
$('html,body').animate({ | |
scrollTop: episodeInfo.element.offset().top - episodeInfo.element.height() - $(".site-header").height(), | |
easing: 'swing' | |
}, duration); | |
$(".show-content__episode-list .js-season-tab .js-episode-wrapper").css('background-color','transparent'); | |
episodeInfo.element.parent().css('background-color','#ddeaff'); | |
} | |
$(document).ready(function() { | |
setTimeout(function() { | |
$('<span class="random"><div class="ui button show-trailer__button"><i title="Random" class="fa fa-random"></i> Random</div></span>') | |
.insertAfter(".poster-image").click(openRandomEpisode); | |
$('.show-trailer').css('display', 'inline').css('margin-bottom','15px'); | |
$('.random').css('display', 'inline-block').css('margin-bottom','15px'); | |
}, 50); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment