TRAKT.TV add RARBG to link list

adds a RARBG link to the link sidebar

À partir de 2021-06-04. Voir la dernière version.

// ==UserScript==
// @name         TRAKT.TV add RARBG to link list
// @namespace    https://greasyfork.org/en/users/12725-alistair1231
// @version      0.2
// @description  adds a RARBG link to the link sidebar
// @author       Alistair1231
// @match        https://trakt.tv/*
// @icon         https://www.google.com/s2/favicons?domain=trakt.tv
// @grant        none
// @license GPL-3.0
// ==/UserScript==

function waitForSiteToLoad(){
    let value = document.querySelectorAll(".sidebar.affixable.affix .external a");
    if(value==null){
        setTimeout(waitForSiteToLoad,300);
        return;
    }
    return value;
}

function injectCode(path,linkArray){
    let imdbButton = Array.from(linkArray).filter(x=>x.innerHTML=="IMDB")[0];
    let rarbgButtonExist = Array.from(linkArray).filter(x=>x.innerHTML=="RARBG")[0];
    
    let imdbId = imdbButton.href.substring(26);

    let rarbgButton = document.createElement("a");
    rarbgButton.target = "_blank";
    rarbgButton.innerHTML = "RARBG";

    if (path == "shows")
        rarbgButton.href = `https://rarbg.to/tv/${imdbId}/`;
    else if (path == "movies")
        rarbgButton.href = `https://rarbg.to/torrents.php?imdb=${imdbId}`;

    if(rarbgButtonExist== null)
        imdbButton.after(rarbgButton);
}
function run(){
    let path = window.location.pathname.split('/')[1];
    let linkArray = document.querySelectorAll(".sidebar.affixable.affix .external a");
    
    linkArray=waitForSiteToLoad();
    try{
        injectCode(path,linkArray);
    }catch(err){}
}
(function () {
    'use strict';
    setInterval(run,700);
})();