-
Notifications
You must be signed in to change notification settings - Fork 12
/
OpenSubtitles_Direct_Downloads.user.js
58 lines (46 loc) · 2.23 KB
/
OpenSubtitles_Direct_Downloads.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// ==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 <eduard.braun2@gmx.de>
// @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);