Search Kongregate Forum

Adds Forum & Thread-Specific Searching

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 or Violentmonkey 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           Search Kongregate Forum
// @namespace      http://userscripts.org/user100
// @include        http://www.kongregate.com/forums/*
// @version 0.0.1.20160306135440
// @description Adds Forum & Thread-Specific Searching
// ==/UserScript==

addSearchBox();
changeTarget(document.body);
document.addEventListener("DOMNodeInserted",function(e){changeTarget(e.target);},false);

function addSearchBox()
{
	var form=document.createElement("form");
	form.id="search";
	form.method="GET";
	form.target="_blank";
	form.action="http://www.google.com/search";
	form.setAttribute("style","border:1px solid black;padding:1px;");
	form.innerHTML="<dl><dt><input type='text' name='q' tabindex='1' class='hintable' style='font-size:11px;'/><input type='hidden' name='as_q' value='site:"+location.host+location.pathname+"' /><input type='hidden' name='num' value='100'/><input type='hidden' name='newwindow' value='1'/></dt><dd><input type='submit' value='Search' tabindex='2' class='spritesite'/></dd></dl>";
	var el=document.getElementById("sidebar");
	el.insertBefore(form,el.firstChild);
}

function changeTarget(container)
{
	var text=location.host+location.pathname;
	Array.forEach(container.getElementsByTagName("a"),function(l){if (l.href.indexOf(text)!=-1) l.target="_blank";});
}