OpenSubtitles Direct Downloads

Creates direct download links for subtitles on opensubtitles.org

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        OpenSubtitles Direct Downloads
// @namespace   https://github.com/Ede123/userscripts
// @version     1.1.1
// @description Creates direct download links for subtitles on opensubtitles.org
// @icon        https://raw.githubusercontent.com/Ede123/userscripts/master/icons/OpenSubtitles.png
// @author      Eduard Braun <[email protected]>
// @license     GPL-3.0-or-later; https://www.gnu.org/licenses/gpl-3.0.txt
// @include     http://www.opensubtitles.org/*
// @include     https://www.opensubtitles.org/*
// @grant       GM_addStyle
// @run-at      document-start
// ==/UserScript==


// remove checkboxes for "OS Download Manager"
GM_addStyle('#checkbox1,#checkbox2{display:none}');

// remove advertising asking users to sign up ("In order to watch Movies and TV Series online, please sign up for free")
GM_addStyle('#loginBoxSubs{display:none}');


function modifyButton() {
    // check for download button on page
    var downloadButton = document.getElementById('bt-dwl') || document.getElementById('bt-dwl-bt');
    if(!downloadButton) return;

    // extract direct link from "dowSub()" function
    var re1 = /product_download_url=([^'"]+)'/;
    var downloadURL = document.body.innerHTML.match(re1)[1];
    downloadURL = decodeURIComponent(downloadURL);

    var re2 = /(.+)\/(vrf-[a-z0-9]+)$/;
    var match = downloadURL.match(re2);
    downloadURL = match[1].replace('download', 'download/' + match[2]);

    // create direct link avoiding advert page for "Open Subtitles MKV Player"
    downloadButton.href = downloadURL;
    downloadButton.removeAttribute("onclick");

    // remove event listeners from the download button (by cloning and replacing it)
    // to prevent any unwanted behavior
    downloadButton.parentNode.replaceChild(downloadButton.cloneNode(true), downloadButton);
}


// unfortunately site scripts seem to take some time to load, so a simple DOMContentLoaded is not enough
function checkLoaded(iteration) {
    if (iteration < 20) {
        if(document.body.innerHTML.indexOf('product_download_url') < 0) {
            setTimeout(checkLoaded, 500, iteration+1);
        } else {
            modifyButton();
        }

    }
}
document.addEventListener("DOMContentLoaded", function(){checkLoaded(0);}, false);