Skip to content

Instantly share code, notes, and snippets.

@rekire
Created November 19, 2013 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rekire/7541860 to your computer and use it in GitHub Desktop.
Save rekire/7541860 to your computer and use it in GitHub Desktop.
GreaseMoney Script for paging the google results. So you can scroll thrue all pages without clicking.
// ==UserScript==
// @name GoogleAutoPager
// @namespace http://ma.la/
// @author ma.la <timpo@ma.la>
// @include http?://www.google.*/search*
// @include https://encrypted.google.com/search*
// @include https://www.google.com/webhp*
// @exclude http?://www.google.*/*tbm=isch*
// @grant GM_xmlhttpRequest
// @description Add autoloading for next page to Google search result. DblClick to enable/disable it.
// ==/UserScript==
// Released under the Rekisoft Public License
// http://www.rekisoft.eu/licenses/rkspl.html
// ver 0.1 @ 2005-06-23
// experimental release
// ver 0.2 @ 2005-06-23
// double click to start.
// ver 0.3 @ 2005-12-02 - modified by beerboy <http://beerboy.org/>
// convert XMLHttpRequest to GM_xmlhttpRequest.
// ver 0.4 @ 2006-02-04 - modified by Gimite <http://gimite.ddo.jp/>
// support Opera 8.5.
// looks better.
// enable to configure whether automatically enable it.
// ver 0.5 @ 2006-10-22 - modified by Gimite <http://gimite.ddo.jp/>
// support new HTML of Google search results.
// ver 0.6 @ 2006-11-19 - modified by Gimite <http://gimite.ddo.jp/>
// support new HTML of Google search results.
// ver 0.7 @ 2006-11-20 - apply patch provided by macaw <http://wildlifesanctuary.blog38.fc2.com/>
// support Safari 2.0
// ver 0.8 @ 2007-01-14 - modified by Gimite <http://gimite.ddo.jp/>
// open all links in new tab or window.
// ver 0.9 @ 2010-06-06 - by Rekire <http://www.rekisoft.eu/>
// https compatible and new window disabled.
// ver 0.9.1 @ 2010-06-26 - by Rekire <http://www.rekisoft.eu/>
// https url update.
// ver 0.9.2 @ 2010-08-16 - by Rekire <http://www.rekisoft.eu/>
// addes links on https page for http maps and image search
// ver 0.9.3 @ 2011-04-16 - by Rekire <http://www.rekisoft.eu/>
// fix for changed source code
// ver 0.9.4 @ 2011-06-20 - by Rekire <http://www.rekisoft.eu/>
// ssl picture search support
// ver 0.9.5 @ 2011-11-09 - by Rekire <http://www.rekisoft.eu/>
// fixed header
// ver 0.9.6 @ 2011-11-10 - by Rekire <http://www.rekisoft.eu/>
// fixed header update
// ver 0.9.7 @ 2012-10-10 - by Rekire <http://www.rekisoft.eu/>
// updated domain list, removed click logging, removed old code
// ver 1.0 @ 2013-01-02 - by Rekire <http://www.rekisoft.eu/>
// removed click logging
// ver 1.0.1 @ 2013-11-19 - by Rekire <http://www.rekisoft.eu/>
// design improvments, click logging again removed
(function(){
var addNewStyle = function(newStyle) {
var styleElement = document.getElementById('styles_js');
if(!styleElement) {
styleElement = document.createElement('style');
styleElement.type = 'text/css';
styleElement.id = 'styles_js';
document.getElementsByTagName('head')[0].appendChild(styleElement);
}
styleElement.appendChild(document.createTextNode(newStyle));
}
// fix headers
if(location.href.indexOf("tbm=isch")==-1) {
addNewStyle("#mngb {position:fixed; top:0; right:0; left:0;}");
addNewStyle("#searchform {position:fixed;}");
addNewStyle("#gsr {padding-top:4em}");
addNewStyle("#hdtbSum, #hdtb, #appbar {background:none !important}");
}
// hide cookie policy note
addNewStyle("#taw {display:none !important}");
// console
if(console==null) {
console=new object();
console.debug=window.alert;
} else {
//var x=console.debug;
//console.debug=function(a,b,c,d,e,f,g,h,i) {x(a,b,c,d,e,f,g,h,i); alert(a+"###"+b+"###"+c+"###"+d+"###"+e+"###"+f+"###"+g+"###"+h+"###"+i);};
}
// <Configuration>
//
// Change the following "true" to "false" if you don't want to enable it automatically.
var GOOGLE_AUTO_PAGER_DEFAULT_ENABLE = true;
//
// </Configuration>
var base = location.protocol+"//"+location.host+"/search";
var offset;
var num;
var query;
var insertPoint;
var Enable = GOOGLE_AUTO_PAGER_DEFAULT_ENABLE ? 1 : -1;
var watch_scroll = function(){
try{
var sc = window.pageYOffset;
var wh = window.innerHeight ? window.innerHeight : document.body.clientHeight;
var total = (document.body.scrollHeight - wh);
var remain = total - sc;
// window.status = remain;
if(remain < 500 && Enable == 1){
do_request()
}
}catch(e){
}
var self = arguments.callee;
setTimeout(self,100);
// document.getElementById("ab_name").innerHTML+=".";
};
// remove logging
var script = document.createElement('script');
script.type = "text/javascript";
script.innerHTML = "setTimeout('function rwt() {return true}',333)";
document.getElementsByTagName('head')[0].appendChild(script);
var do_request = function(){
if(this.requested == offset){return}
// instance search fix
if(location.hash!="") {
var newq=location.hash.match(/[#&]q=[^&]*/).toString();
query=query.replace(/q=[^&]*/, newq.substring(1));
}
this.requested = offset;
var xmlhttp;
var on_load = function(v){
var end_flag = 0;
var start = v.indexOf(">",v.indexOf('id="rso"')) + 1;
var end = v.indexOf("</ol>",start);
if(v.indexOf("<p id=ofr>") != -1){
end_flag = 1;
}
document.getElementById("ires").getElementsByTagName("ol")[0].innerHTML+=v.slice(start,end);
start = v.indexOf('<div id="navcnt">');
end = v.indexOf("</div>",start);
document.getElementById("nav").innerHTML=v.slice(start,end);
//console.debug("loading ... " + offset +" - " + (offset+num) + " done.");
window.status = "loading ... " + offset +" - " + (offset+num) + " done.";
if(!end_flag){
offset += num;
}
}
GM_xmlhttpRequest({
method:"GET",
url:base + query.replace(/start=\d*/,"start=" + offset),
onload: function(d){ on_load(d.responseText); }
});
};
var init_autopager = function(){
var div = document.getElementsByTagName("div");
var len = div.length;
for(var i=0;i<len;i++){
if(div[i].className == "n"){
insertPoint = div[i];
}
}
var next = document.getElementById("nav");
var seiten=next.getElementsByTagName("a");
var href=seiten[seiten.length-1].href;
query = href.substr(href.indexOf("?"));
offset = (query.match(/start=(\d*)/))[1] - 0;
var tmp = query.match(/num=(\d*)/);
num = tmp?tmp[1]-0:10;
//console.debug(query,offset,num);
};
// init
if(window.location.href.indexOf(base) != -1){
if(document.body.attachEvent){
document.body.attachEvent(
'ondblclick',function(){
Enable *= -1;
window.status = (Enable==1)?"Enabled":"Disabled"
}
);
}else{
document.body.addEventListener(
'dblclick',function(){
Enable *= -1;
window.status = (Enable==1)?"Enabled":"Disabled"
},true
);
}
init_autopager();
watch_scroll();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment