Last active
March 31, 2021 15:17
-
-
Save paolobasso99/3c6c0d897c4065b09ace799fbe0cfbca to your computer and use it in GitHub Desktop.
Inject Jackett links to Trakt
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
| /* For buttons */ | |
| #info-wrapper .affiliate-links .section a.appendedFollowShows .icon .fa { | |
| font-size: 22px; | |
| padding-top: 7px; | |
| } | |
| #info-wrapper .affiliate-links .section a.appendedTorrent .icon .fa { | |
| font-size: 22px; | |
| padding-top: 7px; | |
| } |
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
| const JACKETT_HOST = "jackett.bassopaolo.com" | |
| /** | |
| * A function that return the current page type (dashboard, movie, show, season or episode). | |
| * | |
| * @return The current page type as a String. | |
| */ | |
| function getPageType() | |
| { | |
| if($("#comment-type").hasClass("dashboard")){ | |
| return "dashboard"; | |
| } | |
| return $("#comment-type").val(); | |
| } | |
| /** | |
| * A function that given any one digit natural number it return the two digit corresponded number. | |
| * it does not perform anything if the number already has two or more digits. | |
| * | |
| * @param number The number to format | |
| * @return The two digits corresponded number | |
| */ | |
| function doubleDigit(number) | |
| { | |
| if(number.length < 2){ | |
| return ("0" + number).slice(-2); | |
| } | |
| return number; | |
| } | |
| /** | |
| * A function that given any string replaces spaces with "-". | |
| * For example: "Breaking Bad" -> "Breaking-Bad" | |
| * | |
| * @param string The string to format | |
| * @return The Kebab-Case of the string | |
| */ | |
| function toKebabCase(string) | |
| { | |
| string.replace(/\w\S*/g, function(txt){ | |
| return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); | |
| }); | |
| return string.replace(/\s+/g, '-'); | |
| } | |
| function initTorrentButtons() | |
| { | |
| // Define initial vars | |
| var rarbgBaseUrl = "https://rarbg.to/torrents.php?search="; | |
| var jackettBaseUrl = "https://" + JACKETT_HOST + "/UI/Dashboard#search="; | |
| var info = {}; | |
| var urls = { | |
| rarbg: "", | |
| jackett: "" | |
| }; | |
| var toAppend = ""; | |
| var wrapper = $("#overview .row .affiliate-links .section"); | |
| // Build urls object | |
| switch (getPageType()) | |
| { | |
| case 'season': | |
| info.infoContainer = $('div[itemtype="http://schema.org/TVSeason"]').first(); | |
| info.seasonNumber = info.infoContainer.children("meta[itemprop='url']").attr("content").split("/").pop(); | |
| info.seasonNumber = doubleDigit(info.seasonNumber); | |
| info.serieName = info.infoContainer.find('span[itemprop="partOfSeries"] meta[itemprop="name"]').attr("content"); | |
| // Build urls | |
| urls.rarbg = rarbgBaseUrl + info.serieName + " s" + info.seasonNumber; | |
| urls.jackett = jackettBaseUrl + info.serieName + " s" + info.seasonNumber; | |
| break; | |
| case 'episode': | |
| info.infoContainer = $('div[itemprop="episode"][itemtype="http://schema.org/TVEpisode"]').first(); | |
| info.episodeNumber = info.infoContainer.children('meta[itemprop="episodeNumber"]').attr("content"); | |
| info.episodeNumber = doubleDigit(info.episodeNumber); | |
| info.seasonNumber = info.infoContainer.find('span[itemprop="partOfSeason"] meta[itemprop="sameAs"]').attr("content").split("/").pop(); | |
| info.seasonNumber = doubleDigit(info.seasonNumber); | |
| info.serieName = info.infoContainer.find('span[itemprop="partOfSeries"] meta[itemprop="name"]').attr("content"); | |
| // Build urls | |
| urls.rarbg = rarbgBaseUrl + info.serieName + " s" + info.seasonNumber + "e" + info.episodeNumber; | |
| urls.jackett = jackettBaseUrl + info.serieName + " s" + info.seasonNumber + "e" + info.episodeNumber; | |
| break; | |
| default: | |
| info.pageUrl = window.location.href; | |
| info.pageSlug = info.pageUrl.split("/").pop() | |
| info.imdbUrl = $("#info-wrapper .sidebar .external li a:contains('IMDB')").attr("href"); | |
| info.imdbId = info.imdbUrl.split("/").pop(); | |
| // Build urls | |
| urls.rarbg = rarbgBaseUrl + info.imdbId; | |
| urls.jackett = jackettBaseUrl + info.pageSlug; | |
| break; | |
| } | |
| // Build HTML | |
| if(urls.rarbg.length) | |
| { | |
| toAppend += '\ | |
| <a class="appendedTorrent one-liner" target="_blank" href="'+ urls.rarbg +'">\ | |
| <div class="icon">\ | |
| <div class="fa fa-download"></div>\ | |
| </div>\ | |
| <div class="text">\ | |
| <div class="site">RARBG</div>\ | |
| </div>\ | |
| </a>\ | |
| '; | |
| } | |
| if(urls.jackett.length) | |
| { | |
| toAppend += '\ | |
| <a class="appendedTorrent one-liner" target="_blank" href="'+ urls.jackett +'">\ | |
| <div class="icon">\ | |
| <div class="fa fa-download"></div>\ | |
| </div>\ | |
| <div class="text">\ | |
| <div class="site">Jackett</div>\ | |
| </div>\ | |
| </a>\ | |
| '; | |
| } | |
| // If wrapper does not exist, create one | |
| if(!wrapper.length) | |
| { | |
| toAppend = '\ | |
| <div class="section">\ | |
| <div class="title">Videos</div>\ | |
| '+ toAppend +'\ | |
| </div>\ | |
| '; | |
| wrapper = $("#overview .row .affiliate-links"); | |
| } | |
| // Append html | |
| wrapper.append(toAppend); | |
| } | |
| function initFollowShowsButton() { | |
| // Define initial vars | |
| var baseUrl = "https://followshows.com/followShow?show="; | |
| var followUrl = ""; | |
| var toAppend = ""; | |
| var wrapper = $("#overview .row .affiliate-links .section"); | |
| // Build urls object | |
| if(['show', 'season', 'episode'].indexOf(getPageType()) >= 0){ | |
| var showName = $('span[itemprop="partOfSeries"] meta[itemprop="name"]').attr("content"); | |
| // Build urls | |
| followUrl = baseUrl + toKebabCase(showName); | |
| } | |
| // Build HTML | |
| if(followUrl.length) | |
| { | |
| toAppend += '\ | |
| <a class="appendedFollowShows one-liner" target="_blank" href="'+ followUrl +'">\ | |
| <div class="icon">\ | |
| <div class="fa fa-calendar"></div>\ | |
| </div>\ | |
| <div class="text">\ | |
| <div class="site">FollowShows</div>\ | |
| </div>\ | |
| </a>\ | |
| '; | |
| } | |
| // If wrapper does not exist, create one | |
| if(!wrapper.length) | |
| { | |
| toAppend = '\ | |
| <div class="section">\ | |
| <div class="title">Videos</div>\ | |
| '+ toAppend +'\ | |
| </div>\ | |
| '; | |
| wrapper = $("#overview .row .affiliate-links"); | |
| } | |
| // Append html | |
| wrapper.append(toAppend); | |
| } | |
| // Init when page is load | |
| $(document).ready(function(){ | |
| // Check if in the right page for torrents | |
| var regex = RegExp('trakt\.tv\/(movies|shows)'); | |
| if(regex.test(window.location.href)) | |
| { | |
| // Check if torrent buttons already exists | |
| if(!$("#overview .row .affiliate-links .section .appendedTorrent").length) | |
| { | |
| initTorrentButtons(); | |
| } | |
| // Check if torrent buttons already exists | |
| if(!$("#overview .row .affiliate-links .section .appendedFollowShows").length) | |
| { | |
| initFollowShowsButton(); | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment