// ==UserScript==
// @author mungushume
// @version 1.3.0
// @name GoogleMonkeyROpera
// @namespace http://www.monkeyr.com
// @description Google - Multiple columns of results, Remove "Sponsored Links", Number results, Auto-load more results, Remove web search dialogues, Open external links in a new tab, self updating and all configurable from a simple user dialogue.
// @include http://www.google.*/webhp?*
// @include http://www.google.*/search?*
// @include http://www.google.*/ig?*
// @include http://www.google.*/
// @scriptsource http://userscripts.org/scripts/show/9310
// @scriptsource http://google.monkeyr.com/opera/script/1.3.0/googlemonkeyropera.user.js
/* StartHistory
v1.3.0 - 09 Oct 2009
- Bug fix: When searching using the "on page" search dialogs, the script was
not triggering properly. The fix implemented is only a band-aid and when google
implement more changes, it will fail. I am working on the issue when i get time
- Feature: Added an extra option in preferences to remove the "Related
Search" links that sometimes appear at the top of your search results.
- Feature: Added an extra option in the preferences to select the flow
direction of your results when you use multiple columns. Either left to right
or top to bottom newspaper style. If you use "Auto-load" the newspaper style
is automatically paginated to try and keep some clarity in your results.
- Bug fix: Added the include for "/ig?*" urls (iGoogle)
- Cleanup: Reduced the amount of code for the creation and styling of elements
using the function document.buildElement
- Feature: Now works on "/webhp?*" search urls
Thanks to gauravbaadshah for pointing this out!
- Bug fix: Removed Googles results width limiting
v1.2.0 - 02 Jun 2009
- Bug fix: The display of favicons for https links has been removed to stop
invalid certificate warnings whilst searching.
- Bug fix: Error removed when the main link of a result can't be found.
- Feature: Site description text of each search result, when one column of
results is selected, is increased to 95% of the containing cell width as this
seems to be more readable. Two or more columns of results is unchanged as i
found the data appeared to be more cluttered.
As requested by The_Steph.
- Bug fix(ish): Google personalised search (Promote, Remove) functionality
will now work on the initially loaded page of results. All further results
loaded dynamically using the "Auto load" option will NOT!
- Bug fix: "End of search results" wasn't showing up when you'd reached the
end of the results. Now fixed.
- Bug fix: Removal of duplicate "Did you mean:" links at the top of search
results when you've misspelled your search term(s).
v1.1.1.2 - 22 Nov 2008
- Bug fix: Another fix for the latest Google changes. Hopefully across the
board this time.
v1.1.1.1 - 21 Nov 2008
- Bug fix: Quick (ish) fix for the latest Google changes. Sorry on my hols!)
v1.1.1.0 - 03 Nov 2008
- Feature: Addition of favicons next to the main link. Configurable via a
checkbox in the preferences.
As requested by Pierre75007.
v1.1.0.0 - 03 Nov 2008
- Feature: Addition of GooglePreview images in your search results. Open up the
GoogleMonkeyR preferences to turn this feature on.
As requested by Nasir Jones.
- Bug fix: Open in new target now overpowers any settings specified in your
Google preferences.
v1.0.9.1 - 30 Oct 2008
- Bug fix: Ooops. I messed up the z-index of the preferences screen in the last
version. It was appearing behind the blocker. All fixed in this update.
v1.0.9 - 30 Oct 2008
- Feature: Moved the related searches and blog entries etc. to the top of the
results.
- Cleanup: Commented out a GM_log entry i left in in the last update.
- Bug fix: Version comparison now compares numbers rather than strings. Ooops.
- Bug fix: Base numbering of 2nd, 3rd, 4th... pages of results restored (when
auto load more results is turned off).
v1.0.8.9 - 23 Oct 2008
- Bug fix: Auto load more results is back up and running. Google has removed
the id attribute from the Next link at the bottom of their results page. Had
to find it a different way.
- Cleanup: encodeURI of the history information. (to maybe help with the crash)
- Cleanup: Removal of an extra preferences bind that seems to have crept in
at the end of the script (to maybe help with the crash)
v1.0.8.8 - 14 Oct 2008
- Bug fix: Results table and column widths should now be more stable. Less
re-sizing as links are clicked and/or more results auto-load.
- Bug fix: Refined the stylesheet code that gives the results the background
hue. This was to stop other elements getting the same hue.
- Bug fix: Added trackless link to each result regardless of whether your
logged into a Google account or not.
- Bug fix: With the google search dialogs removed sometimes a message reading
"Personalized based on your web history." overlays the GoogleMonkeyR link.
This has now been adjusted to sit below the links.
- Cleanup: XPath functions added to the document object.
v1.0.8.7 - 05 Oct 2008
- Cleanup: Change of the update url to point at the script meta file
"http://userscripts.org/scripts/source/9310.meta.js"
this will reduce the bandwidth to/from userscripts.org and speed up checks
- Cleanup: Change of several method names to aid readability
- Cleanup: "Update bar" code re-written more cleanly
v1.0.8.6 - 01 Oct 2008
- Cleanup: Change of includes to use "Magic top-level domains" instead of *'s
see http://wiki.greasespot.net/Magic_TLD for more info
- Cleanup: Change of update script to pick up history text more cleanly
v1.0.8.5 bug fix - 25 Sep 2008
- Bug fix: History update fix 2
v1.0.8.4 bug fix - 25 Sep 2008
- Bug fix: History update fix
v1.0.8.3 bug fix - 23 Sep 2008
- Bug fix: Final fix with the auto update script
v1.0.8.2 bug fix - 23 Sep 2008
- Bug fix: Another small bug fix with the auto update script
v1.0.8.1 bug fix - 23 Sep 2008
- Bug fix: Small bug fix with the auto update script
v1.0.8 - 23 Sep 2008
- Feature: The update feature of the script has been completely re-written
to notify the user when there are future updates. This update mechanism
will also work if (and when) Google decide to change their DOM again! The
basis for this update method comes from the "UserScript Update Notification"
script from Seifer. This code has been heavily modified and expanded for
the GoogleMonkeyR script.
v1.0.7 bug fix - 17 Sep 2008
- Bug fix: Roll up pack of bug fixes. Should be ok for now!
v1.0.6.3 beta bug fix - 21 Aug 2008
- Bug fix: Some localisations of Google changed again on the 19th Aug. The DOM structure has again
been modified. Oh when will they stop messing with it?
v1.0.6.2 beta bug fix - 13 Aug 2008
- Bug fix: Some localisations of Google changed again on the 12th Aug. The DOM structure has again
been modified. More changes to follow? I hope not!
This is a beta update to fix these problems but may have its own bugs!!!
- Feature: Added ability to change the background hue or the border color of the search results
v1.0.6.1 beta bug fix - 01 Aug 2008
- Bug fix: Some localisations of Google changed on the 31st July.
The DOM structure was quite heavily modified and somehow they messed up the
scroll to bottom of page detection.
This is a beta update to fix these problems but may have its own bugs!!!
- Bug fix: Autoload would flood requests to Google for the next page of results.
Now only one request is sent until a response is received
- Bug fix: Background hue now defaults to transparent rather than white.
Thanks to Lil Junior for the suggestion!
v1.0.6 - 19 Apr 2008
- Bug fix: Corrected the display of the preferences screen in Firefox 3
- Bug fix: Corrected the removal of web search dialogs (after an update on google)
- Bug fix: Natural numbering of 2nd, 3rd, 4th... pages of results.
Thanks to theMoJo for the natural numbering sample code!
v1.0.5 - 24 Oct 2007
- Bug fix: Natural indentation of multiple results from the same site restored
- Bug fix: Google news entries within results no longer breaks the layout and numbering
- Feature: Added ability to change (or remove) the background hue of the search results
NB* Color picker code borrowed, then heavily modified, from Flooble.com
v1.0.4 - 25 May 2007
- Bug fix: Removed the visually anoying bug where when you clicked on a "long" link it resized the whole
cell container before taking you to your link. Grrrr.
v1.0.3 - 20 May 2007
- Bug fix: "Open results in a new target" would only work for the initially loaded results, not subsequent
additions by the auto loader
- Bug fix: Limit the column width to always fit on screen without scroll. As requested by Edward Rapley
NB* This fix only works when your being reasonable! If you want 4 columns of results on an 800x600
screen you'll have trouble. Works best with the "Sponsored Links" removed
- Feature: Added an entry to the Greasemonkey user script commands to allow opening of the GoogleMonkeyR
preferences. This is just in case Google decide to alter their site in a way that removes the
GoogleMonkeyR link from the top of the page.
- Feature: Ability to disable Google tracking your search results
NB* Every time you click a link in your search results, the click gets reported back to Google for
their statisticians to ponder over. If you are signed in to a Google account this click will
be recorded in your search history. This allows you to remove this reporting to Google.
- Feature: When the Disable Google tracking option is not active, an extra "Trackless" link is added
in the "Cached", "Similar pages" links of each of the search results, so you can decide whether
to be tracked at the time!
v1.0.2 - 18 May 2007
- Now uses userscripts.org as the download location for future updates
v1.0.1 - 16 May 2007
- clean up of the code to use more of the this keyword rather than working round the issue by using the
document as a patsy
EndHistory */
// ==/UserScript==
/**
* Processing of the current page.
**/
var UIL =
{
scriptName : "GoogleMonkeyR",
scriptVersion : "1.3.0",
scriptId : "9310",
init : function()
{
var pageType = this.determineCurrentPageType();
if(pageType !== null)
{
this.registerControls();
this.processPage(pageType);
}
else
{
var self = arguments.callee;
setTimeout(self.bind(this),100);
}
},
nextResultsWatcher : function (e){
//console.log(e.attrName+ ' ' +e.newValue );
if (e.attrName=='href' && e.newValue.indexOf(location.host) != -1 && e.newValue.indexOf('start=') != -1 )
{
//console.log('nextResultsWatcher')
clearTimeout(this.reinit);
this.reinit = setTimeout(this.init.bind(this), 100);
}
},
determineCurrentPageType : function()
{
var pageType = null;
var loc = window.location.href.toLowerCase();
if (loc.indexOf("/ig?") != -1)
{
pageType = "igoogle";
}
else if (loc.indexOf("/webhp?") != -1)
{
if(document.getElementById('res'))
{
pageType = "search";
}
}
else if (loc.indexOf("/search?") != -1)
{
if(document.getElementById('res'))
{
pageType = "search";
}
}
else if (window.location.href==(window.location.protocol + '//' + window.location.hostname + '/'))
{
pageType = "home";
}
var el = document.getElementByXPath("//iframe[@onload='google.j.l()']"); if(el)el.parentNode.removeChild(el);
return pageType;
},
processPage : function(pageType)
{
if (pageType !== null)
{
var pageProcessor = pageType + "PageProcessor";
if (typeof(this[pageProcessor]) == "function")
{
this[pageType + "PageProcessor"]();
}
}
},
igooglePageProcessor : function()
{
if(UIL.Config.getHideSearch())
{
var searchEle = document.getElementById("gsea");
if(searchEle)
{
searchEle.style.display="none";
}
}
this.externalLinks(document, UIL.Config.getExtLinkiGoogle());
},
searchPageProcessor : function()
{
this.addStyle("@namespace url(http://www.w3.org/1999/xhtml); #cnt {max-width: none !important;}");
if(UIL.Config.getHideSearch())
{
var searchEle = document.getElementByXPath("//form[@id='tsf'] | //table[@id='sft']");
if(searchEle)
{
searchEle.style.display="none";
var personalised = document.getElementByXPath("//div[@id='ssb']/preceding-sibling::div[contains(@style, 'margin-top:')]");
if(personalised)
{
if(personalised.style.marginTop.substring(0,1) == "-")
{
personalised.style.marginTop = "0";
personalised.style.marginBottom = "0.1em";
}
}
}
searchEle = document.getElementByXPath("//table[contains(@class,'bb bt')] | //div[@id='bsf']");
if(searchEle)
{
searchEle.style.display="none";
}
}
if(UIL.Config.getRemSponsor())
{
this.addStyle("@namespace url(http://www.w3.org/1999/xhtml); .ta, .ra, #mbEnd, #tads { display: none !important; } #GoogleTabledResults {width: 100%};");
}
this.externalLinksResults = UIL.Config.getExtLinkSearch();
this.searchLinkTracking = UIL.Config.getSearchLinkTracking();
this.imagePreview = UIL.Config.getImagePreview();
this.favIcon = UIL.Config.getFavIcon();
this.buildResultTable();
if(UIL.Config.getAutoLoad())
{
this.initialiseAutoLoad();
if(this.insertLoadingImage())
{
//console.log('watchForScroll');
this.watchForScroll.bind(this)();
}
}
},
insertEndText : function()
{
var elem = document.buildElement('table',{id:"endtext" ,width: "100%", cellspacing: "2", cellpadding: "0", border: "0", "class": "t bt",
style:"font-weight:bold;text-decoration:blink"}, " End of the search results");
var res = document.getElementById("res");
res.parentNode.insertBefore(elem, res.nextSibling);
return elem;
},
requestMoreResults : function()
{
if (this.requested == this.startNumber)
{
return;
}
else
{
this.requested = this.startNumber;
this.loadingImage.style.display = "block";
this.UI.getURL(this.query.replace(/start=\d*/,"start=" + this.startNumber), this.processResults.bind(this));
}
},
remainingScroll : function()
{
var ele = document.documentElement;
var total = (ele.scrollHeight - ele.clientHeight);
if (total==0) {
ele = document.body;
total = (ele.scrollHeight - ele.clientHeight);
}
var sc = ele.scrollTop;
return total - sc;
},
watchForScroll : function()
{
var self = arguments.callee;
if (this.remainingScroll() < 500 && !this.requestingMoreResults) {
//console.log('requestMoreResults');
this.requestMoreResults();
this.requestingMoreResults=true;
}
setTimeout(self.bind(this),100);
},
insertLoadingImage : function()
{
//console.log('insertLoadingImage');
var nextLink = document.getElementByXPath("//table[@id='nav']//td[last()]/a");
var navbar = document.getElementByXPath("//table[@id='nav']//td/ancestor::table");
if(navbar)
{
navbar.style.display = "none";
}
if(!this.loadingImage && !this.endText)
{
nextLink.addEventListener("DOMAttrModified", this.nextResultsWatcher.bind(this), false);
nextLink.id="mynextlink";
var div = document.buildElement('div', {style:"width:114px;height:34px;background-image:url(" + UIL.RES.LOADING_GIF + ");background-repeat:no-repeat;margin:auto;padding:10px;display:none;"});
var p = document.buildElement('p', {style:"font-size:130%;font-weight:bold;padding:5px 0 0 40px;margin:0"}, "Loading");
div.appendChild(p);
navbar.parentNode.insertBefore(div, navbar);
this.loadingImage = div;
this.endText = this.insertEndText();
}
//console.log('insertLoadingImage '+nextLink);
this.endText.style.display = nextLink && (nextLink.href.indexOf('start=')!=-1) ? 'none' : 'block';
return nextLink
},
initialiseAutoLoad : function()
{
var nextLink = document.getElementByXPath("//table[@id='nav']//td[last()]/a[contains(@href,'start')]");
if(nextLink)
{
var href = nextLink.href;
this.startNumber = this._matchNum(href, '/start=(\d+)/', 10);
this.itemsQuantity = this._matchNum(href, '/num=(\d+)/', 10);
//console.log(this.startNumber+ ' ' +this.itemsQuantity);
this.query = href;
}
},
buildResultTable : function()
{
var tab = document.getElementById('GoogleTabledResults');
if(tab)
{
tab.parentNode.removeChild(tab);
}
else
{
var hue = UIL.Config.getResHue();
if(hue.length==0)
{
hue = "transparent";
}
var BGBorder;
if(UIL.Config.getBGBorder()=='background')
{
BGBorder = "background-color:";
}
else
{
BGBorder = "border: solid 0.01em";
}
var imagePreview = "";
if(this.imagePreview)
{
imagePreview = "min-height:102px;";
}
var fullWidthResults = "";
if(UIL.Config.getNumCol()<5)
{
fullWidthResults = ".s{max-width:98%!important;}";
}
this.addStyle("@namespace url(http://www.w3.org/1999/xhtml); #res ol li {display:none} a:visited {color:#AAAA8B !important;} li.g, div.g { margin-top: 0.15em !important; margin-right: 0.25em !important; margin-bottom: 0.15em !important; margin-left: 0.25em; -moz-border-radius: 10px ! important; " + BGBorder + " "+ hue +" ! important; padding: 0.5em ! important; } li.g {list-style-image:none;list-style-position:outside;list-style-type:none;"+imagePreview+"} "+fullWidthResults+";");
}
var searchesRelatedTo = UIL.Config.getSearchesRelatedTo() &&
document.getElementByXPath("//div[@id='res']//div[@class='e']");
if(searchesRelatedTo)
{
searchesRelatedTo.style.display = "none";
}
var didYouMean = document.getElementByXPath("//*[@id='res' or @id='topstuff' or @id='botstuff']/p/span[@class='spell']//parent::p");
if(didYouMean)
{
didYouMean.style.display = "none";
}
var resultsFor = document.getElementByXPath("//div[@id='res']//li/p[@class='g']/parent::*");
if(resultsFor)
{
resultsFor.style.display = "none";
}
var relatedSearches = document.getElementByXPath("//div[@id='res']/div[@id='trev']");
if(relatedSearches)
{
relatedSearches.style.display = "none";
}
var table = document.buildElement('table', {id:'GoogleTabledResults',cellspacing:'5%',cellpadding:'0'})
this.resultsTable = table;
var div = document.getElementByXPath("//div/div[@class='g']/parent::div | //div[@id='res']/div | //div[@id='res']/span[@id='search']");
if(div)
{
var start = window.location.search.match(/start=(\d+)/);
this.startBase = (start && start[1].retNum()) || 0;
this.lastI = 0;
this.startNumber = 0;
this.curRow = 0;
this.nextRow = 0;
this.requested = 0;
this.requestingMoreResults=false;
this.numResults = UIL.Config.getNumResults();
this.numColumns = UIL.Config.getNumCol();
this.newspaper = UIL.Config.getResultFlow() != "l2r";
this.autoLoad = UIL.Config.getAutoLoad();
div.parentNode.appendChild(table);
var list = document.getElementsByXPath("//div//li[starts-with(@class,'g')] | //div//li/div[@class='g']");
var length = list.length;
for (var i = 0; i < list.length; i++)
{
this.resultsToTable(list, i, length);
}
this.nextRow = this.curRow;
this.paginationBoundry();
this.lastI = i;
}
},
paginationBoundry : function()
{
if(this.newspaper && this.autoLoad)
{
var row = this.nextRow++;
this.resultsTable.insertRow(row);
var cell = this.resultsTable.rows[row].insertCell(0);
cell.setAttribute("valign", "top");
cell.setAttribute("width", "100%");
cell.setAttribute("colspan", this.numColumns);
var hr = document.createElement('hr');
cell.appendChild(hr);
}
},
resultsToTable : function(list, i, resLength)
{
var link = list[i];
if(this.numResults)
{
link.innerHTML = "" + (i + this.lastI + this.startBase + 1) + " " + link.innerHTML;
}
var col=0, row=0;
if(this.newspaper)
{
var rowsPfetch = Math.ceil(resLength / this.numColumns);
col = Math.floor(i / rowsPfetch);
row = Math.floor(i - (col * rowsPfetch) + this.nextRow );
this.curRow = ((this.curRow <= row) && (row+1)) || this.curRow;
}
else
{
col = (i + this.lastI) % this.numColumns;
row = Math.floor((i + this.lastI) / this.numColumns);
}
if(col==0)
{
this.resultsTable.insertRow(row);
}
var a = document.getElementByXPath(".//h3[@class='r']/a[@class='l' and @href]", link);
if(a)
{
if(this.externalLinksResults)
{
a.target = "_blank";
}
else
{
a.target = "_self";
}
if(this.searchLinkTracking)
{
a.removeAttribute("onmousedown");
}
if(this.favIcon)
{
var base = a.href.match(/http:\/\/[\w\.\-]+\//);
var fav = document.buildElement('img', {width:'16',height:'16',style:'margin-bottom:-3px;',src:base + "favicon.ico"});
a.parentNode.insertBefore(fav, a);
a.parentNode.insertBefore(document.createTextNode(' '), a);
}
if(this.imagePreview)
{
var a2 = a.cloneNode(false);
a2.removeAttribute('class');
var sl = a.href.match(/:\/\/www.(\w)|:\/\/(\w)/);
var bs = a.href.match(/(http:\/\/[\w\.\-]+)\/|(ftp:\/\/[\w\.\-]+)\/|(https:\/\/[\w\.\-]+)\//);
sl = sl[1] || sl[2];
bs = bs[1] || bs[2] || bs[3];
var img = document.buildElement('img', {align:'left',src:"http://"+ sl +".googlepreview.com/preview?s="+ bs +"&ra=1",
style:'border:1px solid #BBB;margin:2px 4px 5px 0px;width:111px;height:82px;'});
a2.appendChild(img);
a.parentNode.parentNode.insertBefore(a2, a.parentNode);
}
if(!this.searchLinkTracking)
{
var ele = document.getElementByXPath(".//span[@class='bl' or @class='gl']/a[last()]", link);
if (ele) {
var notrack = document.buildElement('a',
{href:a.href,'class':'fl',title:'Visit the link without Google tracking you'},'Trackless');
if(this.externalLinksResults)
{
notrack.target = "_blank";
}
else
{
notrack.target = "_self";
}
ele.parentNode.appendChild(document.createTextNode(" - "), ele.nextSibling);
ele.parentNode.appendChild(notrack, ele.nextSibling);
}
}
}
var cell = this.resultsTable.rows[row].insertCell(col);
cell.setAttribute("valign", "top");
var cellWidth = Math.floor(100 / this.numColumns) + "%";
cell.setAttribute("width", cellWidth);
//cell.setAttribute("id", i);
cell.appendChild(link);
},
processResults : function(responseText)
{
this.loadingImage.style.display = "none";
var nextResult = this.loadingImage.appendChild(document.createElement('div'));
nextResult.style.display = "none";
nextResult.innerHTML = responseText;
var list = document.getElementsByXPath(".//div[@id='res']/div//li[starts-with(@class,'g')] | .//div[@id='res']/div//li/div[@class='g']", nextResult);
var length = list.length;
for (var i = 0; i < list.length; i++)
{
this.resultsToTable(list, i, length);
}
this.nextRow = this.curRow;
this.paginationBoundry();
this.lastI += i;
var isNextExist = document.getElementByXPath(".//table[@id='nav']//td[last()]/a[@href]", nextResult);
if (isNextExist)
{
this.startNumber += this.itemsQuantity;
}
else
{
this.endText.style.display = 'block';
}
this.loadingImage.removeChild(nextResult);
this.requestingMoreResults=false;
},
externalLinks : function(scope, blank)
{
var thisdomain = window.location.host;
var links = scope.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
var a = links[i];
if (a.href && a.host && a.host != thisdomain) {
a.target = (blank ? "_blank" : "_self");
}
}
},
registerControls : function()
{
//console.log('registerControls');
var controls = document.getElementByXPath("//div[@id='guser']/nobr/a[1] | //p[@id='gb']/nobr/a[1]");
var link = document.getElementById('GoogleMonkeyRLink');
if (controls && !link)
{
var parent = controls.parentNode;
link = document.buildElement('a',{href:'#',id:'GoogleMonkeyRLink'},'GoogleMonkeyR','click',UIL.UI.preferencesShow.bind(UIL.UI));
var ghead = document.getElementById('ghead');
if(ghead)
{
var that = this;
ghead.addEventListener('DOMNodeRemoved', function(){setTimeout(that.registerControls.bind(that),50);}, false);
}
parent.insertBefore(link, controls);
parent.insertBefore(document.createTextNode(" | "), controls);
}
//GM_registerMenuCommand("GoogleMonkeyR Preferences", UIL.UI.preferencesShow.bind(UIL.UI));
},
addStyle : function(css)
{
if (typeof GM_addStyle != "undefined") {
GM_addStyle(css);
} else {
var heads = document.getElementsByTagName("head");
if (heads.length > 0) {
var node = document.createElement("style");
node.type = "text/css";
node.innerHTML = css;
heads[0].appendChild(node);
}
}
},
_matchNum : function (subject, test, def)
{
var out = subject.match(test);
return (out ? +(out[1]) : (def || 0));
}
};
/**
* Configuration.
**/
UIL.Config =
{
getBGBorder : function()
{
return this._getBooleanConfig("BGBorder", "background");
},
setBGBorder : function(BGBorder)
{
GM_setValue("BGBorder", BGBorder);
},
getResHue : function()
{
return this._getBooleanConfig("resHue", "#E5ECF9");
},
setResHue : function(resHue)
{
resHue = resHue.toUpperCase();
if(!resHue.match(/^#[0-9A-F]{6}$/))
{
resHue = "";
}
GM_setValue("resHue", resHue);
},
getNumCol : function()
{
return this._getBooleanConfig("numCol", 1);
},
setNumCol : function(numCol)
{
GM_setValue("numCol", numCol);
},
getRemSponsor : function()
{
return this._getBooleanConfig("remSponsor", false);
},
setRemSponsor : function(remSponsor)
{
GM_setValue("remSponsor", remSponsor);
},
getNumResults : function()
{
return this._getBooleanConfig("numResults", false);
},
setNumResults : function(numResults)
{
GM_setValue("numResults", numResults);
},
getAutoLoad : function()
{
return this._getBooleanConfig("autoLoad", false);
},
setAutoLoad : function(autoLoad)
{
GM_setValue("autoLoad", autoLoad);
},
getHideSearch : function()
{
return this._getBooleanConfig("hideSearch", false);
},
setHideSearch : function(hideSearch)
{
GM_setValue("hideSearch", hideSearch);
},
getExtLinkSearch : function()
{
return this._getBooleanConfig("extLinkSearch", false);
},
setExtLinkSearch : function(extLinkSearch)
{
GM_setValue("extLinkSearch", extLinkSearch);
},
getExtLinkiGoogle : function()
{
return this._getBooleanConfig("extLinkiGoogle", false);
},
setExtLinkiGoogle : function(extLinkiGoogle)
{
GM_setValue("extLinkiGoogle", extLinkiGoogle);
},
getSearchLinkTracking : function()
{
return this._getBooleanConfig("searchLinkTracking", false);
},
setSearchLinkTracking : function(searchLinkTracking)
{
GM_setValue("searchLinkTracking", searchLinkTracking);
},
getImagePreview : function()
{
return this._getBooleanConfig("imagePreview", false);
},
setImagePreview : function(imagePreview)
{
GM_setValue("imagePreview", imagePreview);
},
getFavIcon : function()
{
return this._getBooleanConfig("favIcon", false);
},
setFavIcon : function(favIcon)
{
GM_setValue("favIcon", favIcon);
},
getSearchesRelatedTo : function()
{
return this._getBooleanConfig("hideSearchesRelatedTo", false);
},
setSearchesRelatedTo : function(hideSearchesRelatedTo)
{
GM_setValue("hideSearchesRelatedTo", hideSearchesRelatedTo);
},
getResultFlow : function()
{
return this._getBooleanConfig("resultFlow", "l2r");
},
setResultFlow : function(resultFlow)
{
GM_setValue("resultFlow", resultFlow);
},
_getBooleanConfig : function(configName, defaultValue)
{
var config = GM_getValue(configName);
if (config === undefined)
{
GM_setValue(configName, defaultValue);
config = defaultValue;
}
return config;
}
};
/**
* Preferences User Interface (UI).
**/
UIL.UI =
{
preferencesShow : function(e)
{
if (e)
{
e.preventDefault();
e.stopPropagation();
}
this._loadBlocker();
var prefs = document.buildElement('iframe',
{id:'uil_preferences',name:'uil_preferences',
style:'position:fixed;top:5%;left:0px;right:0px;border:none;height:100%;width:100%;overflow:hidden;z-index:10001;',
src:UIL.RES.PREFS_HTML},null,'load',this.preferencesDocumentLoadHandler.bind(this));
document.body.appendChild(prefs);
this.prefs = prefs;
},
_loadBlocker : function()
{
if (this.blocker==null)
{
var blocker = document.buildElement('div',
{id:'uil_blocker',
style:'position:fixed;top:0px;left:0px;right:0px;bottom:0px;background-color:#000;opacity:0.5;z-index:10000;'});
this.blocker = blocker;
document.body.appendChild(blocker);
}
},
updateScript : function(e)
{
if (e)
{
e.preventDefault();
e.stopPropagation();
}
this._loadBlocker();
try{
window.location.replace("http://userscripts.org/scripts/source/"+ UIL.scriptId +".user.js");
}
catch(e)
{}
if(this.prefs)document.body.removeChild(this.prefs);
if(this.history)document.body.removeChild(this.history);
GM_setValue('skipVersion', 0);
setTimeout(this.refreshShow.bind(this),4000);
},
refreshShow : function()
{
var refresh = document.buildElement('iframe',
{style:'position:fixed;top:20%;left:0px;right:0px;border:none;height:100%;width:100%;overflow:hidden;z-index:10001;',
src:UIL.RES.REFRESH_HTML},'','load',this.refreshDocumentLoadHandler.bind(this));
this.refresh = refresh;
document.body.appendChild(refresh);
},
refreshDocumentLoadHandler : function()
{
this.refresh.contentDocument.getElementById("scriptName").innerHTML=UIL.scriptName;
},
hide : function()
{
if(this.history) document.body.removeChild(this.history);
if(this.prefs)document.body.removeChild(this.prefs);
if(this.blocker)document.body.removeChild(this.blocker);
this.history = null;
this.prefs = null;
this.blocker = null;
},
preferencesDocumentLoadHandler : function()
{
var form = this.prefs.contentDocument.forms.namedItem("preferences");
// Set up form state
form.elements.namedItem("numcol" + UIL.Config.getNumCol()).checked = true;
form.elements.namedItem("remsponsor").checked = UIL.Config.getRemSponsor();
form.elements.namedItem("numresults").checked = UIL.Config.getNumResults();
form.elements.namedItem("autoload").checked = UIL.Config.getAutoLoad();
form.elements.namedItem("hidesearch").checked = UIL.Config.getHideSearch();
form.elements.namedItem("extlinksearch").checked = UIL.Config.getExtLinkSearch();
form.elements.namedItem("extlinkigoogle").checked = UIL.Config.getExtLinkiGoogle();
form.elements.namedItem("searchlinktracking").checked = UIL.Config.getSearchLinkTracking();
form.elements.namedItem("ResHuefield").value = UIL.Config.getResHue();
form.elements.namedItem("imagepreview").checked = UIL.Config.getImagePreview();
form.elements.namedItem("favicon").checked = UIL.Config.getFavIcon();
form.elements.namedItem("remsearchesrelatedto").checked = UIL.Config.getSearchesRelatedTo();
//this.prefs.contentDocument.getElementById("ResHue").style.color = UIL.Config.getResHue();
this.prefs.contentDocument.getElementById("ResHue").style.background = UIL.Config.getResHue();
this.prefs.contentDocument.getElementById("BGBorderlink").innerHTML = UIL.Config.getBGBorder();
this.prefs.contentDocument.getElementById("flowimg").className = UIL.Config.getResultFlow();
// Set up event handlers
form.elements.namedItem("close_button").addEventListener("click", this.hide.bind(this), false);
form.elements.namedItem("save_button").addEventListener("click", this.preferencesSaveConfigurationHandler.bind(this), false);
this.prefs.contentDocument.getElementById("version").innerHTML=UIL.scriptVersion;
//this.getURL("http://userscripts.org/scripts/source/"+UIL.scriptId+".meta.js", this.updateTestOnPreferences.bind(this));
},
getURL : function(address, cb)
{
GM_xmlhttpRequest({
method :"GET",
url :address,//+"?"+Math.random(),
onload :function(xhr) { cb(xhr.responseText); }
});
},
updateCheckRequest : function()
{
var lastCheck = GM_getValue('lastCheck', 0);
if (this._currentTime() > (lastCheck + 86400)) //24 hours after last check
{
GM_setValue('delayUpdate', false);
this.getURL("http://userscripts.org/scripts/source/"+UIL.scriptId+".meta.js", this.updateTestOnPage.bind(this));
}
else
{
this.onSiteVersion = GM_getValue('onSiteVersion', 0);
var delayUpdate = GM_getValue('delayUpdate', false);
var skipVersion = GM_getValue('skipVersion', 0);
if ( this.versionCompare(UIL.scriptVersion, this.onSiteVersion) )
{
if ( this.versionCompare(skipVersion, this.onSiteVersion) && !delayUpdate )
{
this.updateMessageShow();
}
}
}
},
updateTestOnPage : function(text)
{
var skipVersion = GM_getValue('skipVersion', 0);
var onSiteVersion = text.match(/\/\/\s*@version\s*(\d.*)/);
this.onSiteVersion = (onSiteVersion===null) ? 0 : onSiteVersion[1];
GM_setValue('onSiteVersion', this.onSiteVersion);
var updateHistory = text.substring(text.search(/\/\*.*StartHistory/im));
updateHistory = updateHistory.substring(0, updateHistory.search(/EndHistory.*\*\//im))
GM_setValue('onSiteVersionHistory', encodeURI(updateHistory));
if ( this.versionCompare(UIL.scriptVersion, this.onSiteVersion) )
{
if ( this.versionCompare(skipVersion, this.onSiteVersion) )
{
this.updateMessageShow();
}
}
GM_setValue('lastCheck', this._currentTime());
},
updateTestOnPreferences: function(text)
{
var onSiteVersion = text.match(/\/\/\s*@version\s*(\d.*)/);
this.onSiteVersion = (onSiteVersion===null) ? 0 : onSiteVersion[1];
GM_setValue('onSiteVersion', this.onSiteVersion);
var updateHistory = text.substring(text.search(/\/\*/));
updateHistory = updateHistory.substring(0, updateHistory.search(/\*\//))
GM_setValue('onSiteVersionHistory', encodeURI(updateHistory));
var link = this.prefs.contentDocument.getElementById("check_update");
link.setAttribute("target", "_top");
if ( this.versionCompare(UIL.scriptVersion, this.onSiteVersion) )
{
link.addEventListener("click", this.historyShow.bind(this), false);
link.setAttribute("title", " see what's new with GoogleMonkeyR... ");
link.style.textDecoration = "blink";
link.innerHTML = "v"+this.onSiteVersion+" available";
}
else
{
link.setAttribute("href", "#");
link.setAttribute("title", " the history of GoogleMonkeyR ");
link.innerHTML = "history";
link.addEventListener("click", this.historyShow.bind(this), false);
link.parentNode.appendChild(document.createTextNode(" - "));
var link2 = document.buildElement('a',{href:"http://"+ location.hostname +"/preferences",
target:'_parent',title:' your Google preferences '},'prefs');
link.parentNode.appendChild(link2);
link.parentNode.appendChild(document.createTextNode(" - "));
var link3 = document.buildElement('a',{href:"https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=mungushume@hotmail.com&item_name=GreaseMonkey%20programming/beer%20fund&no_shipping=0&no_note=1&tax=0¤cy_code=GBP&lc=GB&bn=PP-DonationsBF&charset=UTF-8",
target:'_parent',title:' donate to the GoogleMonkeyR programming/beer fund '},'donate');
link.parentNode.appendChild(link3);
}
GM_setValue('lastCheck', this._currentTime());
},
versionCompare : function(ver1, ver2)
{
var maxVersionPartTest = 5;
var ver1Arr = (ver1+('.0'.repeat(maxVersionPartTest))).split(".",maxVersionPartTest);
var ver2Arr = (ver2+('.0'.repeat(maxVersionPartTest))).split(".",maxVersionPartTest);
//alert(ver1Arr.join(',') + ' - ' +ver2Arr.join(','));
for(var i=0; i ver2Arr[i].retNum() )
{
i = maxVersionPartTest
break;
}
}
return (i