Google: Custom sorted by date results?

Koslov

[H]ard|Gawd
Joined
Aug 31, 2003
Messages
1,889
Does anyone know an addon or userscripts to customize the default Google "search by date" list:

Past hour
Past 24 hours
Past week
Past month
Past year


I'd like to customize it to add "Past 2 months, 6 months, 2 years, etc..). It really bothers me. I know I can do a custom search but it takes too long do it manually multiple times per day.
 
I made this just to see if it could do what you wanted, and it works. You can use this with the FireFox Greasemonkey addon. It adds a "Past 2 Weeks" link, and when you click it it fills out the date range and clicks Go for the user. You could extend this to add other custom ranges if you wish.
Code:
// ==UserScript==
// @name        Google Search Helper
// @namespace   http://sgraffite.com
// @include     /^https?://www\.google\.com/.*$/
// @require     https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js
// @version     1
// ==/UserScript==
$(document).ready(function(){
	$('.hdtb-mn-hd').click(function(){
		// ----------------
		// Add custom links
		// ----------------
		// Past 2 Weeks link
		$('#cdr_opt','#hdtbMenus').after('<li class="hdtbItm"><a id="cdr_custom1" href="#custom_date_range1">Past 2 Weeks</a></li>');
		$(this).off('click');
		
		// ---------------------------
		// Hook events to custom links
		// ---------------------------
		// Hook Past 2 Weeks
		$('#cdr_custom1').click(function(){	
			$('#cdrlnk').click(function(){
				var TwoWeeksAgo = new Date().addWeeks(-2);
				var CurrentDate = new Date();
				var TwoWeeksAgoString =((TwoWeeksAgo.getMonth() + 1).toString() + '/' + (TwoWeeksAgo.getDate()).toString() + '/' + (TwoWeeksAgo.getFullYear()).toString());
				var CurrentDate =((CurrentDate.getMonth() + 1).toString() + '/' + (CurrentDate.getDate()).toString() + '/' + (CurrentDate.getFullYear()).toString());
				// Delay the setting of the values slightly
				setTimeout(function(){setElValue('#cdr_min',TwoWeeksAgoString)},50);
				setTimeout(function(){setElValue('#cdr_max',CurrentDate)},50);
				setTimeout(function(){submitForm('#cdr_frm')},100);
			}).click();
		});
	});
});
// Sets an element's value.
function setElValue(el,value){
	$(el).prop('value',value);
}
// Submits a form
function submitForm(formEl){
	$(formEl).submit();
}
// Subtract weeks from a Date object (stolen from Stackoverflow).
Date.prototype.addWeeks = function(value){
    var milliseconds = this.getTime();
    return new Date(milliseconds + (value * 1000 * 60 * 60 * 24 * 7));
};

If Google changes the structure of the page or the names of the element IDs it could possibly break this script.
 
I made this just to see if it could do what you wanted, and it works. You can use this with the FireFox Greasemonkey addon. It adds a "Past 2 Weeks" link, and when you click it it fills out the date range and clicks Go for the user. You could extend this to add other custom ranges if you wish.
Code:
// ==UserScript==
// @name        Google Search Helper
// @namespace   http://sgraffite.com
// @include     /^https?://www\.google\.com/.*$/
// @require     https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js
// @version     1
// ==/UserScript==
$(document).ready(function(){
	$('.hdtb-mn-hd').click(function(){
		// ----------------
		// Add custom links
		// ----------------
		// Past 2 Weeks link
		$('#cdr_opt','#hdtbMenus').after('<li class="hdtbItm"><a id="cdr_custom1" href="#custom_date_range1">Past 2 Weeks</a></li>');
		$(this).off('click');
		
		// ---------------------------
		// Hook events to custom links
		// ---------------------------
		// Hook Past 2 Weeks
		$('#cdr_custom1').click(function(){	
			$('#cdrlnk').click(function(){
				var TwoWeeksAgo = new Date().addWeeks(-2);
				var CurrentDate = new Date();
				var TwoWeeksAgoString =((TwoWeeksAgo.getMonth() + 1).toString() + '/' + (TwoWeeksAgo.getDate()).toString() + '/' + (TwoWeeksAgo.getFullYear()).toString());
				var CurrentDate =((CurrentDate.getMonth() + 1).toString() + '/' + (CurrentDate.getDate()).toString() + '/' + (CurrentDate.getFullYear()).toString());
				// Delay the setting of the values slightly
				setTimeout(function(){setElValue('#cdr_min',TwoWeeksAgoString)},50);
				setTimeout(function(){setElValue('#cdr_max',CurrentDate)},50);
				setTimeout(function(){submitForm('#cdr_frm')},100);
			}).click();
		});
	});
});
// Sets an element's value.
function setElValue(el,value){
	$(el).prop('value',value);
}
// Submits a form
function submitForm(formEl){
	$(formEl).submit();
}
// Subtract weeks from a Date object (stolen from Stackoverflow).
Date.prototype.addWeeks = function(value){
    var milliseconds = this.getTime();
    return new Date(milliseconds + (value * 1000 * 60 * 60 * 24 * 7));
};

If Google changes the structure of the page or the names of the element IDs it could possibly break this script.


Where's the up-vote button?
 
Sorry I'm a bit late.
Thanks a lot for the script. I really appreciate
 
Back
Top