KG - homepage additions

see latest uploads from your choice of directors & users on homepage (edit script to choose which)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        KG - homepage additions
// @namespace   KG
// @include     http*://*karagarga.in/
// @grant	GM_addStyle
// @version     0.6
// @description see latest uploads from your choice of directors & users on homepage (edit script to choose which)
// ==/UserScript==

// ----------- user setup ----------- 
// to add extra search terms:   ["name 1", "name 2", "etc"];
// to disable a search:   []
// to find all latest uploads:   [""]

var artists = ["alfred hitchcock"];
var users = ["d1fferent"];
var numberOfHits = 3;    // maximum of 15

// ----------- end setup ----------- 


var dirSearchURL = "https://karagarga.in/browse.php?sort=added&search_type=director&d=DESC&search=";
var userSearchURL = "https://karagarga.in/browse.php?sort=added&search_type=uploader&d=DESC&search=";

GM_addStyle(".gmlinks a:link { color:#cc0000 !important; } "
		+ ".gmsearch { margin-bottom: .8em !important; } ");

// find our insert target
var links = document.links;
for (i=0; i < links.length; i++) { 
	if (links[i].href.indexOf('slideshow.php') != -1) { 
		var target = links[i].parentNode;
	} 
}

for (var i in artists) {
	search(artists[i], dirSearchURL);
}
for (var i in users) {
	search(users[i], userSearchURL);
}

function search(string, url) {
	url = url + string;
        var x = new XMLHttpRequest();
        x.open("GET",url);
        x.onload = function() { 
		insert(this.responseXML, string, url);
        }
        x.responseType = "document";
        x.send();
}

function insert(result, string, url) {
	var rows = result.querySelectorAll("table#browse tr");
	var newBox = document.createElement('div');
	newBox.className = "gmsearch";
	newBox.innerHTML += "<a href=' " + url + " '>" + string + "</a>";
	var newTable = document.createElement('table');
	newBox.appendChild(newTable);
	for (i=1; i < parseInt(numberOfHits * 2) && i < rows.length; i=i+2) {  // every other row is hidden and unneeded, ignore it
		var row = rows[i];
		while (row.cells.length > 4) { // get rid of cells we don't want
			row.deleteCell(4);
		}
		row.deleteCell(2); // and one more
		var dropdown = row.querySelector("span[onclick^='toggle']")
		if (dropdown) {
			dropdown.innerHTML = ""; // and the dropdown
		}
		row.cells[1].className = "gmlinks";
		newTable.appendChild(row);
	}

	target.insertBefore(newBox, target.firstChild);
}


// var target = document.querySelector('table.main table td');	 // lefthand column, goes wrong when there's a PM alert 
// document.querySelectorAll('h2')[2]  // stuck torrents heading