Test

By Kyle Day Last update Jun 20, 2009 — Installed 202 times. Daily Installs: 0, 0, 0, 1, 0, 0, 0, 1, 1, 2, 0, 2, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1

There are 13 previous versions of this script.

// ==UserScript==
// @name           Google Search Sidebar for FF3 - Wikipedia, Dictionary.com, Flickr, and Youtube Results
// @namespace       
// @description    Adds a sidebar with search results from Dictionary.com, Wikipedia, Flickr, and Youtube. Please report any bugs.
// @include http://www.google.com/*
// @include http://www.google.ae/*
// @include http://www.google.com.af/*
// @include http://www.google.com.ag/*
// @include http://www.google.com.ai/*
// @include http://www.google.am/*
// @include http://www.google.com.ar/*
// @include http://www.google.as/*
// @include http://www.google.at/*
// @include http://www.google.com.au/*
// @include http://www.google.az/*
// @include http://www.google.ba/*
// @include http://www.google.com.bd/*
// @include http://www.google.be/*
// @include http://www.google.bg/*
// @include http://www.google.com.bh/*
// @include http://www.google.bi/*
// @include http://www.google.com.bn/*
// @include http://www.google.com.bo/*
// @include http://www.google.com.br/*
// @include http://www.google.bs/*
// @include http://www.google.co.bw/*
// @include http://www.google.com.by/*
// @include http://www.google.com.bz/*
// @include http://www.google.ca/*
// @include http://www.google.cd/*
// @include http://www.google.cg/*
// @include http://www.google.ch/*
// @include http://www.google.ci/*
// @include http://www.google.co.ck/*
// @include http://www.google.cl/*
// @include http://www.google.cn/*
// @include http://www.google.com.co/*
// @include http://www.google.co.cr/*
// @include http://www.google.com.cu/*
// @include http://www.google.cz/*
// @include http://www.google.de/*
// @include http://www.google.dj/*
// @include http://www.google.dk/*
// @include http://www.google.dm/*
// @include http://www.google.com.do/*
// @include http://www.google.com.ec/*
// @include http://www.google.ee/*
// @include http://www.google.com.eg/*
// @include http://www.google.es/*
// @include http://www.google.com.et/*
// @include http://www.google.fi/*
// @include http://www.google.com.fj/*
// @include http://www.google.fm/*
// @include http://www.google.fr/*
// @include http://www.google.ge/*
// @include http://www.google.gg/*
// @include http://www.google.com.gi/*
// @include http://www.google.gl/*
// @include http://www.google.gm/*
// @include http://www.google.gp/*
// @include http://www.google.gr/*
// @include http://www.google.com.gt/*
// @include http://www.google.gy/*
// @include http://www.google.com.hk/*
// @include http://www.google.hn/*
// @include http://www.google.hr/*
// @include http://www.google.ht/*
// @include http://www.google.hu/*
// @include http://www.google.co.id/*
// @include http://www.google.ie/*
// @include http://www.google.co.il/*
// @include http://www.google.im/*
// @include http://www.google.co.in/*
// @include http://www.google.is/*
// @include http://www.google.it/*
// @include http://www.google.je/*
// @include http://www.google.com.jm/*
// @include http://www.google.jo/*
// @include http://www.google.co.jp/*
// @include http://www.google.co.ke/*
// @include http://www.google.com.kh/*
// @include http://www.google.ki/*
// @include http://www.google.kg/*
// @include http://www.google.co.kr/*
// @include http://www.google.kz/*
// @include http://www.google.la/*
// @include http://www.google.li/*
// @include http://www.google.lk/*
// @include http://www.google.co.ls/*
// @include http://www.google.lt/*
// @include http://www.google.lu/*
// @include http://www.google.lv/*
// @include http://www.google.com.ly/*
// @include http://www.google.co.ma/*
// @include http://www.google.md/*
// @include http://www.google.mn/*
// @include http://www.google.ms/*
// @include http://www.google.com.mt/*
// @include http://www.google.mu/*
// @include http://www.google.mv/*
// @include http://www.google.mw/*
// @include http://www.google.com.mx/*
// @include http://www.google.com.my/*
// @include http://www.google.com.na/*
// @include http://www.google.com.nf/*
// @include http://www.google.com.ng/*
// @include http://www.google.com.ni/*
// @include http://www.google.nl/*
// @include http://www.google.no/*
// @include http://www.google.com.np/*
// @include http://www.google.nr/*
// @include http://www.google.nu/*
// @include http://www.google.co.nz/*
// @include http://www.google.com.om/*
// @include http://www.google.com.pa/*
// @include http://www.google.com.pe/*
// @include http://www.google.com.ph/*
// @include http://www.google.com.pk/*
// @include http://www.google.pl/*
// @include http://www.google.pn/*
// @include http://www.google.com.pr/*
// @include http://www.google.pt/*
// @include http://www.google.com.py/*
// @include http://www.google.com.qa/*
// @include http://www.google.ro/*
// @include http://www.google.ru/*
// @include http://www.google.rw/*
// @include http://www.google.com.sa/*
// @include http://www.google.com.sb/*
// @include http://www.google.sc/*
// @include http://www.google.se/*
// @include http://www.google.com.sg/*
// @include http://www.google.sh/*
// @include http://www.google.si/*
// @include http://www.google.sk/*
// @include http://www.google.sn/*
// @include http://www.google.sm/*
// @include http://www.google.st/*
// @include http://www.google.com.sv/*
// @include http://www.google.co.th/*
// @include http://www.google.com.tj/*
// @include http://www.google.tk/*
// @include http://www.google.tm/*
// @include http://www.google.to/*
// @include http://www.google.tp/*
// @include http://www.google.com.tr/*
// @include http://www.google.tt/*
// @include http://www.google.com.tw/*
// @include http://www.google.com.ua/*
// @include http://www.google.co.ug/*
// @include http://www.google.co.uk/*
// @include http://www.google.com.uy/*
// @include http://www.google.co.uz/*
// @include http://www.google.com.vc/*
// @include http://www.google.co.ve/*
// @include http://www.google.vg/*
// @include http://www.google.co.vi/*
// @include http://www.google.com.vn/*
// @include http://www.google.vu/*
// @include http://www.google.ws/*
// @include http://www.google.co.yu/*
// @include http://www.google.co.za/*
// @include http://www.google.co.zm/*
// @include http://www.google.co.zw/*
// @require http://userscripts.org/scripts/source/44063.user.js
// ==/UserScript==

/********************************
 * Google Search Sidebar v1.6.5 *
 ********************************/
GM_log('init');

function addSidebar() {
// Stops execution if sidebar already exists (a bug that happens sometimes)
if ($('gSearchSidebar')) return;

// remove ads if present
if ($('3po')) $('3po').dispose();
if($('mbEnd')) $('mbEnd').dispose();
if($('mbb10')) $('mbb10').dispose();
if($('tads')) $('tads').dispose();

// Fix SearchWiki positioning
if ($('wml')) $('wml').setStyle('clear','both');

GM_log('getting query');
// Get the search query
var query;
inputs = $$('#sft input');
inputs.each(function(input) {
	if (input.get('type') == 'text')
		query = input.get('value');
});

GM_log('create sidebar');
// Create our new sidebar
new Element('div').set('id','gSearchSidebar').inject($$('span#search').getParent(), 'after');

GM_log('get dictionary');
// Steal content from Dictionary.com. An API of some sort would be better as it doesn't work perfectly.

GM_xmlhttpRequest({
    method: 'GET',
    url: 'http://dictionary.reference.com/browse/' + encodeURIComponent(query),
	headers: {
        'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        'Accept': 'text/html',
    },
    onload: function(response) {
        if (response.status === 200) {
			var word, definition, pron;
			hiddeniframe = new Element('iframe').setStyle('display','none').inject(document.body);
			hiddeniframe.contentWindow.document.body.innerHTML = response.responseText;
			html = hiddeniframe.contentWindow.document.body;
			hiddeniframe.dispose();
			if ($(html).getElements('.luna-Ent h2.me')[0]) {
				word = $(html).getElements('.luna-Ent h2.me')[0].innerHTML;
				definition = $(html).getElements('.luna-Ent .body')[0].innerHTML;
				if (definition.length > 600)
					definition = definition.substring(0,600) + '<span> ...</span>';
				pron = $(html).getElements('.luna-Ent span.show_spellpr span.pron')[0].innerHTML;
			}
			
			if (word && definition && pron) {
				dictcontainer = new Element('div').set('id','dictcontainer');
				new Element('h1').set('html', '<a href="'+ this.url +'" target="_blank">Dictionary.com</a>').inject(dictcontainer);
				new Element('p').set('html', '<span class="me">' + word + '</span>&nbsp;&nbsp;<span class="pron">[' + pron + ']</span><br />' + definition).inject(dictcontainer);
				dictcontainer.inject('gSearchSidebar', 'top');
			}
		}
    }
});

// Grab Wikipedia data from Yahoo Search - Got idea here: http://www.hackdiary.com/archives/000070.html
// Again an API would work better as this has some flaws

GM_xmlhttpRequest({
    method: 'GET',
    url: 'http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=GoogleSearchSidebar&site=en.wikipedia.org&query='+ encodeURIComponent(query) +'&results=1&output=json&callback=eval',
    headers: {
        'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        'Accept': 'text/javascript',
    },
    onload: function(response) {
        if(response.status === 200) {
			wikipedia = eval(response.responseText);
			
			if (result = wikipedia.ResultSet.Result[0]) {
				if (!result.Title.match(/^.+:/)) {
					wikipediacontainer = new Element('div').set('id', 'wikipediacontainer');
					new Element('h1').set('html', '<a href="'+ result.Url +'" target="_blank">Wikipedia</a>').inject(wikipediacontainer);
		
					// Steal wikipedia's logo for aesthetics
					new Element('img')
						.set('src','http://en.wikipedia.org/images/wiki-en.png')
						.setStyles({'float':'left','width':'101px','height':'116px'})
						.inject(wikipediacontainer);
			
					// Insert Wikipedia title
					new Element('h2').set('html', result.Title.replace(/ - Wikipedia, the free encyclopedia$/,'').replace(/&amp;amp;/g,'&amp;')).inject(wikipediacontainer);
		
					// Insert the article summary text into the page
					text = new Element('p').set('html', result.Summary.replace(/&amp;amp;/g, '&amp;')+ ' ').inject(wikipediacontainer);
					new Element('a').set({'href':result.Url,'target':'_blank'}).set({'text' : 'View Entry'}).inject(text);
					new Element('div').setStyle('clear','both').inject(wikipediacontainer);
					
					if ($('dictcontainer')) wikipediacontainer.inject('dictcontainer', 'after');
					else wikipediacontainer.inject('gSearchSidebar', 'top');
				}
			}
		}
    }
});

// Grab JSON data from flickr

GM_xmlhttpRequest({
    method: 'GET',
    url: 'http://api.flickr.com/services/rest?method=flickr.photos.search&api_key=33db8eb821f12753b480df732f0e3b11&text=' + encodeURIComponent(query) + '&sort=relevance&per_page=12&format=json&jsoncallback=eval',
    headers: {
        'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        'Accept': 'text/plain',
    },
    onload: function(response) {
		if (response.status === 200) {
			flickr = eval(response.responseText);
			if(flickr.photos.total > 0) {
				photocontainer = new Element('div').set('id','flickrcontainer');
				new Element('h1').set('html', '<a href="http://www.flickr.com/search/?q='+ encodeURIComponent(query) +'&m=text" target="_blank">Flickr</a>').setStyle('clear','both').inject(photocontainer);
				flickr.photos.photo.forEach(function(photo) {
					photo_url = 'http://farm' + photo.farm + '.static.flickr.com/' + photo.server + '/' + photo.id + '_' + photo.secret;
					flickr_url = "http://www.flickr.com/photos/" + photo.owner + "/" + photo.id;
					thumb = new Element('img').set('src', photo_url + '_s.jpg');
					thumb.setStyles({'float':'left','margin-right':'3px','margin-bottom':'3px','border-style':'none'});
					photolink = new Element('a').set({'href':flickr_url,'target':'blank'}).adopt(thumb);
					photolink.adopt(thumb);
					photocontainer.adopt(photolink);
				});
				if ($('youtubecontainer')) photocontainer.inject('youtubecontainer', 'before');
				else photocontainer.inject('gSearchSidebar');
				new Element('div').setStyle('clear','both').inject(photocontainer);
			}
		}
    }
});

// Grab JSON Data from YouTube

GM_xmlhttpRequest({
    method: 'GET',
    url: 'http://gdata.youtube.com/feeds/videos?max-results=4&alt=json&vq='+ encodeURIComponent(query),
    headers: {
        'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        'Accept': 'text/plain'
    },
    onload: function(response) {
        if (response.status === 200) {
			youtube = eval('('+ response.responseText +')');
			if (youtube.feed.openSearch$totalResults.$t > 0) {
				youtubecontainer = new Element('div').set('id','youtubecontainer');
				new Element('h1').set('html', '<a href="http://www.youtube.com/results?search_query='+ encodeURIComponent(query) +'&search=Search" target="_blank">YouTube</a>').inject(youtubecontainer);
				
				youtube.feed.entry.each(function(entry) {
					thumb_url = entry.media$group.media$thumbnail[0].url;
					video_url = entry.media$group.media$player[0].url;
					description = entry.media$group.media$description.$t;
					title = entry.media$group.media$title.$t;
					if (description.length > 125) {
						description = description.substring(0,125);
						description += ' ...';
					}
					
					thumb = new Element('img').set('src',thumb_url).setStyles({
						'float':'left',
						'margin-bottom':'5px',
						'width':'98px',
						'height':'73px',
						'border-style':'none'
					});
				
					videolink = new Element('a').set({'href':video_url,'target':'_blank'}).adopt(thumb);
					videolink.inject(youtubecontainer);
					
					new Element('h2').setStyles({
						'float':'right',
						'width':'215px'
					}).adopt(new Element('a').set({'text':title, 'href':video_url,'target':'_blank'})).inject(youtubecontainer);
				
					new Element('p').set('text', description).setStyles({
						'float':'right',
						'width':'215px'
					}).inject(youtubecontainer);
					
					youtubecontainer.inject('gSearchSidebar');
					new Element('div').setStyle('clear','both').inject(youtubecontainer);
				});
			}
		}
    }
});

// Add some style ;)

styles = 'body { min-width:940px; }';
styles += '#gSearchSidebar { overflow:hidden; margin:0 0 50px; float:right; width:320px; }';
styles += '#gSearchSidebar p { margin-top:5px; }';
styles += '#gSearchSidebar h1 { font-size:1em; margin:0 0 10px; background-color:#ebeff9; border-top:1px solid #6b90da; padding:5px }';
styles += '#gSearchSidebar h1 a { text-decoration:none; font-weight:bold; color:#000; }';
styles += '#gSearchSidebar h2 { font-size:0.9em; color:#333; margin:0; padding:0; }';
styles += '#res { overflow:hidden; }';
styles += '#gSearchSidebar p { font-size:0.9em; line-height:1.3em; padding:0; }';
styles += '#flickrcontainer, #wikipediacontainer { padding-bottom:15px; }';
styles += '.me { font-weight:bold; font-size:1.2em; }';
styles += '.pg { color: #581; display:inline; font-style:italic; }';
styles += '.luna-Ent { color: #333; font-size:1em; margin-left:1em; }';
styles += '.ital-inline, .alt-ital { font-style:italic; }';
styles += '.pron { color:#800; font-family: Verdana, "Arial Unicode MS", "Lucida Sans Unicode", Helvetica, Arial, sans-serif;}';
styles += '#res { width:600px; float:left; margin-bottom:15px; margin-top:-11px; }';
styles += 'div.t.n.bt { clear: both; }';

GM_addStyle(styles);
}
addSidebar();