ghostwan / TV Showtime search episodes from 1337x and subtitles from subscene

// ==UserScript==
// @name         TV Showtime search episodes from 1337x and subtitles from subscene
// @version      1.0
// @description  Create links on each to-watch episodes to easily search and download it from 1337x. Fork from Everton Leite script
// @author       Ghostwan
// @include      /^.+tvshowtime\.com.+
// @grant        none
// ==/UserScript==

function update_dl_links(){
    $(".dl_links").remove();
    $("#to-watch .secondary-link").each(function(){
        episode = $(this).prev().children("a").html();
        if (episode.match(/^(a-Z)*S[0-9]+E[0-9]+/)){
            name = $(this).html();
            if (name.indexOf("(") >= 0){
                name = name.substring(0, name.indexOf("(") - 1);
            }
            url = encodeURIComponent(name + " " + episode);
            url1 = url.replace(/%26amp%3B/g, "%20").replace(/\./g, "%20").replace(/'/g, "").replace(/[%20]{5,}/g, ' ');
            url2 = url1.replace(new RegExp("%20", 'g'), "+");
            target = $(this).parent().parent().children(".nav");

            style = "font-size: 12px; position: absolute; font-weight: 700; font-family: ProximaNova;";
            dl_div = "<div class='dl_links' style='float: left; margin-top: 0px;'>";
            dl_div += " <a class='dl_button' onclick=\"window.open('http://subscene.com/subtitles/release?q=" + url1 + "');\" href='https://1337x.to/search/" + url2 + "/1/' style='margin-top: 0px; " + style + "' target='_blank'>Download</a>";
            dl_div += "</div>";
            $(target).prepend(dl_div);
        }
    });
    setTimeout(function(){
        update_dl_links();
    }, 3000);
}
update_dl_links();