TPB

Add YouTube link and IMDb rating to top/207|all

目前為 2015-06-07 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @version     1.0.1   
// @name    TPB
// @description     Add YouTube link and IMDb rating to top/207|all
// @namespace     https://greasyfork.org/users/3159  
// @include     https://thepiratebay.*/top/207
// @include     https://thepiratebay.*/top/all
// ==/UserScript==
style = document.createElement('style');
style.innerText = ".youtube{color:#b2491a;cursor:pointer}.imdb{color:grey}#bg{background:rgba(0, 0, 0,.8);position:fixed;top:0;left:0;z-index:9001;width:100%;height:100%;display:none}iframe{border:0;width:640px;height:390px;max-width:90%;max-height:90%;margin:auto;position:absolute;top:0;left:0;bottom:0;right:0}";
document.head.appendChild(style);

function filter(x) {
	x = x.replace(/\./g, ' '); //dots to spaces
	x = x.replace(/\(/g, ''); // ( to nothing
	y = x.replace(/(S[0-9].*?)\ .*/, '$1'); //remove after season
	z = x.match(/18|19|20[0-9]{2}/); // year
	y != x ? x = y : (y = x.replace(/(.*?.)((18|19|20)[0-9]{2}).*/, '$1$2'), x = x.split(' ' + z)[0]); // if no season then year
	results = [y, x, z];
	return results;
}

function iIMDb(ir, n, ii) {
	if (ir) {
		l = document.getElementsByClassName('imdb')[n - 1];
		l.href = "http://imdb.com/title/" + ii + "/";
		l.children[0].innerHTML = ir;
	}
}

list = document.getElementsByTagName('tr');
for (i = 1; i < list.length; i++) {
	q = list[i].children[1];
	//YouTube
	yt = document.createElement('a');
	yt.className = "youtube";
	yt.innerHTML = "<em>Yt</em> ";
	q.appendChild(yt);
	bg = document.createElement("div");
	bg.id = "bg";
	bg.onclick = function () {
		bg.style.display = "none";
		bg.innerHTML = "";
	};
	document.body.appendChild(bg);
    f1 = filter(list[i].children[1].children[0].className ? list[i].children[1].children[0].children[0].innerHTML : list[i].children[1].children[0].innerHTML[0]); // name
	eval("yt.onclick=function(){bg.style.display='block';bg.innerHTML='<iframe src=//youtube.com/embed/?listType=search&list=" + escape(f1) + "&autohide=1></iframe>'};");
	//IMDb
	f2 = filter(list[i].children[1].children[0].className ? list[i].children[1].children[0].children[0].innerHTML : list[i].children[1].children[0].innerHTML[0])[1]; // id
	f3 = filter(list[i].children[1].children[0].className ? list[i].children[1].children[0].children[0].innerHTML : list[i].children[1].children[0].innerHTML[0])[2]; // year
	imdb = document.createElement('a');
	imdb.className = "imdb";
	imdb.innerHTML = "<code></code>";
	q.appendChild(imdb);
	eval("var r" + i + "= new XMLHttpRequest;r" + i + ".open('GET', 'http://www.omdbapi.com/?t='+f2+'&y='+f3, true);r" + i + ".onreadystatechange = function () {var num" + i + "=JSON.parse(r" + i + ".responseText).imdbRating;var ii" + i + "=JSON.parse(r" + i + ".responseText).imdbID;iIMDb(num" + i + "," + i + ",ii" + i + ");};r" + i + ".send();");
}