Skip to content

Instantly share code, notes, and snippets.

@petermac-
Last active September 12, 2015 18:36
Show Gist options
  • Save petermac-/4f8fb1b534266e713cee to your computer and use it in GitHub Desktop.
Save petermac-/4f8fb1b534266e713cee to your computer and use it in GitHub Desktop.
jsmonkey-gcsearch.user.js
// ==UserScript==
// @name jsmonkey-gcsearch additional Google search filters
// @namespace http://techexplored.com
// @description Adds 2 custom search filters to limit search results to the past 6 months or 2 years.
// @contributor petermac-
// @version 2014.05.09
//
// @icon http://www.google.com/favicon.ico
// @include /(http|https)?://.*\.google\.[^\/]+?/(#.*|search\?.*)?$/
// @grant none
// @run-at document-end
// ==/UserScript==
var timer, log, start;
function addElement() {
var search = document.getElementById('qdr_m').firstChild.getAttribute('href');
var beginURL = search.match(/.*(?=&tbs)/);
var filter_parent = document.getElementById('qdr_y').parentNode;
var insert_index = 5;
var url_6m = beginURL + "&tbs=qdr:m6";
var url_2y = beginURL + "&tbs=qdr:y2";
var filters = [url_6m, url_2y];
for (var filter in filters) {
var li = document.createElement('li');
li.setAttribute('class', 'hdtbItm');
var a = document.createElement('a');
a.setAttribute('class', 'q qs');
a.setAttribute('href', filter);
a.innerHTML = 'Past 6 months';
li.appendChild(a);
filter_parent.insertBefore(li, filter_parent.childNodes[insert_index]);
insert_index += 2;
}
}
log = document.getElementById("log");
function repeatXI(callback, interval, repeats, immediate) {
var timer, trigger;
trigger = function() {
callback();
--repeats || clearInterval(timer);
};
interval = interval <= 0 ? 1000 : interval; // default: 1000ms
repeats = parseInt(repeats, 10) || 0; // default: repeat forever
timer = setInterval(trigger, interval);
if ( !! immediate) { // Coerce boolean
trigger();
}
return timer;
}
function cb() {
var search = document.getElementById('qdr_y').parentNode;
var length = search.children.length;
if(length > 7) {
//console.log('element already added');
return true;
}
//console.log('element not yet added');
addElement();
}
if( timer ) { clearInterval(timer); }
start = (new Date).getTime();
var args = [ 4000, 0, true ];
timer = repeatXI.apply(null, [cb].concat(args));

jsmonkey-gcsearch

Adds 2 additional custom Google search options - 6 months & 2 years

Dependencies (determined by browser)

Firefox

Install Greasemonkey

Google Chrome

Install Tampermonkey

Setup

  1. Click on the view raw link of the jsmonkey-gcsearch.user.js file
  2. Click on install on the new tab that opened
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment