DVDs ReleaseDates helper

Add external links

Pada tanggal 25 November 2017. Lihat %(latest_version_link).

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        DVDs ReleaseDates helper
// @namespace   V@no
// @description Add external links
// @include     http://www.dvdsreleasedates.com/*
// @version     1.2.1
// @grant       none
// ==/UserScript==

function $(id)
{
	return document.getElementById(id);
}

function urlencode(url)
{
	return encodeURI(url).replace(/%5B/g, '[').replace(/%5D/g, ']');
}

let links = [
		{
			name: "ThePirateBay",
			nameShort: "TPB",
			url: "https://thepiratebay.org/search/{S}/0/3/0",
			icon: ""
		},
		{
			name: "RARBG",
			nameShort: "RARBG",
			url: "https://rarbg.to/torrents.php?search={S}&order=data&by=DESC",
			icon: ""
		},
/*
		{
			name: "OMDB",
			nameShort: "OMDB",
			url: "http://www.omdbapi.com/?t={S}",
			icon: "",
			
		}
*/

];

function cleanup(t)
{
	t = t.replace(/[-:,]\s(season\s(\w+))$/i, season);
	t = t.replace(/\[[^\]]*\]/g, "");
	let l = ["4k", "ultra", "hd", "bd", "ultrahd", "edition"];
	for(let i = 0; i < l.length; i++)
	{
		t = t.replace(new RegExp("\\b" + l[i] + "\\b", "gi"), "");
	}
	return t;
}

function season(a, b, c, d)
{
	let n = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"],
			i = n.indexOf(c.toLowerCase());

	if (i == -1)
		i = c.replace(/[a-zA-Z]+/g, "");

	return " S" + i;
}

let td = document.getElementsByClassName("dvdcell");
for(let i = 0; i < td.length; i++)
{
	let title = "",
			a = td[i].getElementsByTagName("a");

	for(let t = 0; t < a.length; t++)
	{
		if (!a[t].children.length)
		{
			title = a[t].textContent;
			break;
		}
	}
	if (!title)
		continue;

	let div = document.createElement("div");

	div.className = "links";
	for(let n = 0; n < links.length; n++)
	{
		let a = document.createElement("a"),
				img = document.createElement("img"),
				item = links[n],
				dom = item.url.match(/\/\/([^\/{}]+)/)[1],
				icoUrl = item.icon || "http://www.google.com/s2/favicons?domain=" + dom;

		a.href = item.url.replace("{S}", urlencode(cleanup(title)));
		a.setAttribute("target", "_blank");
		img.src = icoUrl;
		img.title = item.name;
		a.appendChild(img);
		div.appendChild(a);
	}
	td[i].appendChild(div);
}


//create stylesheet. A little trick to have multiline text
var	style = document.createElement("style"),
		css = function(){/*
div.links
{
	display: block;
	text-align: center;
}
div.links > a
{
	padding-right: 2px;
	padding-left: 2px;
	border-right: 1px dotted silver;

}
div.links > a:last-child
{
	padding-right: 2px;
	border-right: 0;
}

*/};
style.innerHTML = css.toString().slice(14, -3).replace(/\*\/\/\*/g, "*/");
document.getElementsByTagName("head")[0].appendChild(style);