KG - homepage additions

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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