Trakt Watchlist Downloader

Trakt.tv torrent site(s) added to the Watch Now modal. This is a fix of https://greasyfork.org/scripts/17991

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         Trakt Watchlist Downloader
// @namespace    https://gist.githubusercontent.com/epsimatic/8ab8d0f0089e627fc146709b02dd428c/raw
// @version      0.5
// @description  Trakt.tv torrent site(s) added to the Watch Now modal. This is a fix of https://greasyfork.org/scripts/17991
// @author       Tusk & Epsimatic
// @match        https://trakt.tv/*
// @grant        none
// ==/UserScript==
/* jshint -W097 */
'use strict';
var torrent_sites = [
    {
        name: 'Rutracker',
        color: 'white',
        image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAMAAAD0WI85AAABgFBMVEVHcEwzMzM3NzU0NDTqpL3uss3qu9ff+Mfvx+SCdnrn5Nk1NTTG6aU2NjXzzezf+8Q0NDTO5bfJ9J9+iXQ1NTXR8rE0NDQ0NDTt4uLn/s/f+cbtm7Lyw+Hs5OIzMzO7mq/m8/jtj6fn/9Dv0Ouz44aKeYbn/9DwzOrowt3d9sTxxeOtv5uKe4jHpb3vyefvxePj+8pWWFPk/MwyMjKRlom9qbS9o7pvcGl9fXuhqazp9vmjspO+x8ozMzOY6U7zREznHTLpIzbvN0N4wDrrKjtoqzPwPkntMD+P3Uf2T1P0SlBxuDeT4kpipi5bnSrn/9CBzEBtsjV9xj3whJmF0UNfoiyJ10TW8L32U1g/Pz7yzeyo6G3wdonwaXurkKOahZV1aXVVWlFLS0iOm4KBulS64Ji90qma0Gyo04OOxGNXUVZkZWFYgza984nyWmZ0fG2frpBNaDaW11xAaOTatM48YNpaNTg5WM+ANzylOkDoMkZBUTR8m+6vwejPO0NcdtaaYgX7AAAAPXRSTlMAgv68/fj+/v0INEr9F0Pynv77/WT7zzQRcN3+7iPr/Pv+Xln+/EhouMXN/kH7g6Sr4JDbZLx5t5L7kMz5IRlQKAAADARJREFUeNrtmWlXGskagLGBXpDIJoKCClFc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uD+gzn0GC8kMYEiEAbjpERF4BF3SiCYKsuctFusHqOutAk5YyJgcrIDZUykU6OstDly0SvCeBXgPXerHZrGqyK5XmUiePVQNCRzfiN/dMqHKR0RkUdEJgKvacnm3V0sxx+SgDGJZA6JzVwvl8v1k4rSLiqCQ697b7PVyjCz6xWhxLVsJwBcTNuUykm9vLsLVRVbgxAHFFMR6f28cFKOfNktgwg0xBqCzUG4kgKgyBMTa0HkPcl8PunhM1dHhDSueGScuLHHrEeFw0CDI2+hR3pE3O9PKWkmIn0qLIji1eEpIb98KATgM14kfa35qq06X3I0iuT4OA270aBjvirA3uYoEm7wQ4mR1jccpfmqotiqpWNC0i1aSuge7XrbrgqyUm2nSzZBUKrzWGPs0zGFoEgv/UOnR4Xx8cLRaRpqDZreniJFMifin00+ftIvD1n7cb1FPEdEov59jP7HmxCAs7ogpSL16wllbHkIag7SpzZGkGWoJ3XqDb7q0y9zBOH0+iE9w9W5L8dB+Ri2Q8as/ZKrjwFVnjFo1WPFZX3foAQ5td5cPpbP+Q3eOayy6A+FcU3jT8d0f43k6ndJT0t0r1z9z/6jA4tcz4qkx3Kaes4regvp7ys8j+N5pZkcW1CNiyb3hBik6TuR0+v+dSR2+KdM+0N0f4j5xQysbQi+BPTpXhoDfBgXZcoqJXQnNmAWvjhm/KvPgF1/SHp5Im4+Ge7ViHquOM6le3lIo+NiMqpul3cwVQppWLtfJK63h1dihjca+Ix4hS+aL9SDbXTpYqOBeyVoSC/Wg+1UuEWqu9HLR9JpaGhoaGhoaGhoaGhoaGhoaGhoaGj8P/M/dMuw/8+UzHUAAAAASUVORK5CYII=',
        link: 'https://rutracker.org/forum/tracker.php?nm=%s'
    },
    {
        name: 'The Pirate Bay',
        color: 'black',
        image: 'data:image/svg+xml,%3Csvg%20clip-rule%3D%22evenodd%22%20fill-rule%3D%22evenodd%22%20stroke-linejoin%3D%22round%22%20stroke-miterlimit%3D%221.41421%22%20viewBox%3D%220%200%20450%20225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22m115.527%20220.222c-2.072-.582-3.694-1.973-4.843-4.155l-.59-1.119.106-6.983c.058-3.84.102-8.03.096-9.311l-.01-2.327-1.332-2.963c-2.468-5.489-3.412-8.991-3.406-12.635.006-2.654.396-4.419%201.413-6.355%202.095-3.986%207.797-7.57%2012.09-7.599%201.327-.009%201.749.087%202.916.662%202.332%201.148%204.287%203.517%205.358%206.49.245.681.861%203%201.37%205.153l.924%203.915%202.617-.027c2.689-.027%205.409-.393%2025.682-3.461%204.656-.705%2013.417-2.023%2019.469-2.93l11.004-1.649.055-.728c.031-.4-.027-.854-.129-1.009-.225-.345-3.009-.828-10.507-1.822-3.142-.417-7.189-.993-8.993-1.28-1.804-.288-7.518-1.145-12.697-1.906-5.179-.76-11.178-1.664-13.331-2.009-4.05-.647-7.254-1.112-13.967-2.024-2.153-.293-5.295-.763-6.983-1.046-6.785-1.137-11.408-1.606-11.966-1.214-.363.254-1.052%201.319-2.438%203.768-1.955%203.453-3.447%205.475-5.69%207.714-3.119%203.112-5.384%204.104-9.32%204.08-3.77-.022-6.795-1.31-9.267-3.944-2.625-2.796-2.569-4.685.304-10.329%201.407-2.764%202.834-4.916%205.286-7.97%201.033-1.287%202.199-2.87%202.591-3.517l.712-1.176-.684-3.758c-1.425-7.826-.734-12.076%202.529-15.563%202.166-2.315%204.805-3.544%208.508-3.964%202.337-.265%203.93-.035%205.73.825%204.218%202.015%205.707%205.29%206.307%2013.866.277%203.957.481%204.719%201.408%205.259.484.282%205.367%201.171%2017.246%203.139%209.114%201.51%2022.142%203.691%2028.95%204.847%2027.638%204.691%2043.746%207.323%2054.491%208.906%203.142.462%207.713%201.181%2010.157%201.597%206.071%201.033%208.736%201.052%2013.755.097%2010.534-2.002%2070.595-15.083%2083.164-18.113%201.745-.42%205.173-1.195%207.616-1.722%204.647-1.002%206.444-1.653%207.03-2.548.191-.292.425-1.094.519-1.782.425-3.104%202.069-7.726%203.55-9.979%203.151-4.791%207.95-6.862%2013.45-5.805%202.209.425%203.101.821%204.265%201.893%201.852%201.708%202.515%203.754%202.485%207.671-.018%202.393-.137%203.289-.915%206.878-.511%202.362-.899%204.724-.907%205.524-.017%201.725.278%202.398%203.157%207.201%202.821%204.705%204.464%208.027%204.747%209.6.29%201.609.123%204.487-.309%205.322-1.028%201.987-5.284%203.686-9.257%203.694-3.673.008-6.373-.986-9.223-3.394-1.71-1.445-2.422-2.299-4.419-5.289-1.314-1.968-1.605-2.278-2.483-2.642l-.995-.412-2.278.476c-1.253.262-3.659.701-5.347.975-1.688.273-4.782.835-6.877%201.248s-8.666%201.605-14.602%202.65c-20.515%203.609-23.076%204.067-25.711%204.596-3.503.704-4.339%201.274-3.078%202.099.905.593%202.401.927%207.513%201.676%202.74.402%207.424%201.114%2010.407%201.582%209.457%201.486%2015.386%202.337%2016.273%202.337%201.361%200%201.979-.478%203.623-2.804%201.77-2.505%205.392-6.21%207.342-7.511%201.728-1.153%203.053-1.536%205.307-1.532%202.864.005%204.707.658%207.363%202.615%201.522%201.122%202.607%202.5%203.269%204.154.622%201.554.679%205.553.092%206.448-.203.311-.507.954-.675%201.431-.589%201.667-2.978%205.107-5.975%208.603-1.921%202.24-1.675%201.407-2.166%207.324-.772%209.315-2.622%2013.692-6.618%2015.659-1.923.946-4.138%201.409-6.714%201.402-4.05-.011-6.114-.953-7.938-3.622-1.659-2.428-1.985-3.762-2.596-10.623-.114-1.275-.315-2.253-.531-2.583-.485-.741-2.647-1.383-8.641-2.566-2.715-.535-6.364-1.299-8.11-1.698-1.745-.398-5.554-1.195-8.464-1.77-5.188-1.025-11.573-2.355-21.479-4.475-2.735-.585-6.211-1.309-7.724-1.607-1.513-.299-4.217-.872-6.011-1.275-1.792-.402-5.078-1.1-7.3-1.55-2.222-.451-5.184-1.072-6.58-1.38-3.282-.725-4.447-.699-9.339.206-4.961.918-30.344%205.974-34.571%206.886-5.178%201.117-23.386%204.845-38.196%207.82-3.491.701-7.348%201.508-8.57%201.793-1.222.286-2.936.627-3.809.76s-2.444.466-3.492.742c-1.047.275-2.993.703-4.323.952-2.682.5-3.797.967-4.409%201.844-.664.954-.879%201.853-1.328%205.547-.233%201.928-.614%204.2-.845%205.049-.826%203.034-2.309%205.246-4.145%206.179-.96.488-1.276.528-4.524.571-2.576.035-3.787-.036-4.619-.27zm25.675-76.05-12.062-.114-1.587-.818c-6.017-3.102-8.33-6.849-8.994-14.569l-.14-1.632-1.757-.958-1.756-.957-.157-10.05c-.202-12.945.009-22.805.502-23.393.19-.227%201.012-.678%201.827-1.001l1.481-.589.136-1.901c.075-1.046.147-17.784.159-37.194l.023-35.293.659-1.316c2.685-5.358%207.562-9.26%2012.121-9.696.943-.091%2043.453-.171%2094.465-.178l92.749-.013%202.08%201.029c2.69%201.332%203.824%202.124%205.563%203.885%201.565%201.585%202.898%203.66%203.585%205.58.397%201.112.466%201.941.618%207.493.093%203.433.189%2018.003.213%2032.377.023%2014.373.1%2028.133.171%2030.578l.129%204.443%201.27.674c.698.371%201.412.889%201.587%201.152.274.412.326%202.697.38%2016.621.044%2011.316-.006%2016.272-.167%2016.572-.126.236-.885.76-1.687%201.163l-1.457.734-.114%201.116c-.062.614-.17%201.736-.239%202.492-.409%204.471-2.112%207.779-5.602%2010.884-2.205%201.961-3.065%202.242-8.255%202.701-2.814.249-152.273.4-175.744.178zm32.725-3.893c2.986-.703%205.044-2.943%205.681-6.182.619-3.142-1.183-6.692-4.131-8.143-.904-.444-1.351-.518-3.168-.518-2.443%200-3.273.237-4.773%201.365-3.955%202.972-4.187%208.471-.5%2011.841%201.87%201.708%204.217%202.266%206.891%201.637zm106.552-.306c1.418-.732%203.371-2.683%204.028-4.024.496-1.012.589-1.468.586-2.895%200-1.448-.097-1.893-.657-3.081-.774-1.643-2.366-3.322-3.818-4.025-.778-.378-1.485-.516-2.96-.581-1.741-.077-2.06-.029-3.14.465-.769.352-1.714%201.066-2.625%201.982-1.243%201.25-1.487%201.629-1.919%202.985-.456%201.432-.475%201.665-.238%202.95.628%203.41%202.526%205.669%205.475%206.517%201.477.424%204.167.275%205.268-.293zm-81.028-3.082c1.865-.679%203.257-2.204%203.957-4.333.536-1.628.385-4.851-.289-6.146-.656-1.262-2.352-2.913-3.569-3.475-.838-.388-1.382-.463-3.329-.463-2.145%200-2.417.047-3.461.597-3.133%201.65-4.799%205.2-3.986%208.495.598%202.426%202.242%204.426%204.379%205.328%201.646.695%204.387.694%206.298%200zm55.765.398c2.256-.587%203.988-2.145%205.284-4.752.979-1.967.945-3.213-.148-5.426-.983-1.991-2.754-3.875-4.033-4.291-.466-.152-1.82-.328-3.01-.391-2.038-.109-2.231-.083-3.32.45-1.347.659-3.157%202.528-3.809%203.933-.362.78-.44%201.355-.434%203.174.007%201.915.08%202.368.524%203.28.964%201.976%202.879%203.469%205.182%204.04%201.444.358%202.342.354%203.764-.017zm-78.358-48.15c3.858-.602%209.813-4.972%2011.668-8.565%203.635-7.037%202.688-15.311-2.371-20.719-3.551-3.796-7.04-5.367-12.753-5.741-2.675-.176-4.24.094-6.675%201.15-4.791%202.078-7.786%204.836-9.792%209.016-1.345%202.803-1.731%204.755-1.61%208.137.087%202.451.196%203.152.746%204.831.814%202.484%202.034%204.542%203.806%206.421%202.379%202.521%206.749%205.082%209.314%205.458%201.745.256%206.06.262%207.667.012zm103.373%200c3.751-.534%208.654-3.969%2011.261-7.891%203.086-4.642%203.67-10.955%201.498-16.187-1.639-3.949-4.68-7.045-9.183-9.347-2.258-1.155-3.982-1.499-7.571-1.511-3.09-.011-4.497.194-5.951.866-.465.215-1.374.635-2.019.934-1.542.714-4.081%202.909-5.724%204.949-2.504%203.109-3.79%206.684-3.79%2010.54%200%205.278%201.742%209.507%205.317%2012.906%202.476%202.356%205.945%204.345%208.227%204.719%201.607.264%206.146.276%207.935.022zm-33.454-13.212c.891-1.169%201.002-2.429.931-10.648-.058-6.64-.109-7.637-.426-8.215-.71-1.298.2-1.247-22.388-1.247-11.347%200-20.993.077-21.435.17-.591.125-.864.321-1.033.741-.309.768-.479%209.721-.284%2014.929.148%203.953.18%204.181.609%204.427.438.251%209.268.382%2035.926.534l7.54.043.56-.735z%22%20fill%3D%22%23fff%22%20fill-rule%3D%22nonzero%22%2F%3E%3C%2Fsvg%3E',
        link: 'https://thepiratebay.org/search/%s/0/3/0'
    }
];

$('html').on('show.bs.modal', '#watch-now-modal', function (e) {
    var checkExist = setInterval(function() {
        var streaming_links = $('#watch-now-modal').find('.streaming-links');
        console.debug("Waiting to insert...");
        if (streaming_links.length) {
            clearInterval(checkExist);
            console.log("Element found", streaming_links);
            addSites();
            setHeader(streaming_links);
        }
    }, 100);
});

function setHeader(streaming_links) {
    var place = streaming_links.find('.title').last();
    place.text(place.text() + ' or download');
}

function addSites() {
    var name_of_item = $('#watch-now-modal').find('h1').text();
    for(var i=0;i < torrent_sites.length;i++) {
        var link = parse(torrent_sites[i].link, name_of_item);
        addSite(torrent_sites[i].name, torrent_sites[i].color, torrent_sites[i].image, link);
    }
}

function addSite(name, color, image, link) {
    $('#watch-now-modal').find('a[data-source]').last().after(`<a target="_blank" href="${link}"><div class="icon" style="background-color:${color};"><img src="${image}" alt="${name}"></div><div class="price">${name}<br><i>(free)</i></div></a>`);
}

function parse(str) {
    var args = [].slice.call(arguments, 1),
        i = 0;

    return str.replace(/%s/g, function() {
        return args[i++];
    });
}