OpenSubtitles Direct Downloads

Creates direct download links for subtitles on opensubtitles.org

Stan na 29-04-2020. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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);