// ==UserScript==
// @name iStock Forum Search using Google
// @namespace theasis
// @match http://*.istockphoto.com/forums.php*
// @match http://*.istockphoto.com/forum_threads.php*
// @match http://*.istockphoto.com/forum_messages.php*
// @match https://*.istockphoto.com/forums.php*
// @match https://*.istockphoto.com/forum_threads.php*
// @match https://*.istockphoto.com/forum_messages.php*
// @version 1.2
// iStockPhoto forum search greasemonkey script (c) Martin McCarthy 2013
// ==/UserScript==
// v1.0
// Initial version
// Martin McCarthy 12 Feb 2013
// v1.1
// Prevent it auto-scrolling to the search box
// Martin McCarthy 13 Feb 2013
// v1.2
// Tweaks for the Chrome store, no functional changes
// Martin McCarthy 19 Mar 2013
//
addSearchBox();
function doSearch() {
var ip=document.getElementById('theasisForumSearchInput');
var q=document.getElementById('theasisForumSearchQ');
q.value='site:www.istockphoto.com "forum home" '+ip.value;
}
function addSearchBox() {
var container = getHeadingContainer();
if (container!=null) {
var tsc = document.createElement("div");
tsc.id = "theasisSearchContainer";
tsc.style.float='right';
var frm = document.createElement("form");
frm.setAttribute("action",'http://www.google.com/search');
frm.setAttribute("method","get");
frm.onsubmit=doSearch;
frm.innerHTML="";
tsc.appendChild(frm);
container.insertBefore(tsc,container.firstChild);
}
}
function getHeadingContainer() {
var el = null;
var h1s = document.getElementsByTagName('h1');
if (h1s) {
el = h1s[0].parentNode;
}
return el;
}