Skip to content

Instantly share code, notes, and snippets.

@vayn
Created June 27, 2011 23:14
Show Gist options
  • Save vayn/1050089 to your computer and use it in GitHub Desktop.
Save vayn/1050089 to your computer and use it in GitHub Desktop.
FireGestures script for google image search
/**
* Author:
* Vayn a.k.a. VT <[email protected]>
* http://vayn.is-programmer.com
*
* URL:
* http://p.vim-cn.com/cbG/js
*
* File: googleImageSearch.js
* Create Date: 2011年 06月 27日 星期一 09:29:57 CST
*/
var srcNode = FireGestures.sourceNode;
var imgURL = getComputedStyle(srcNode, '').getPropertyValue('background-image');
if (imgURL == 'none')
imgURL = FireGestures.getImageURL(srcNode);
else
imgURL = imgURL.replace(/"|'/g,"").replace(/url\(|\)$/ig, "");
if (!imgURL)
throw "Not on a image";
// check the URL is safe
FireGestures.checkURL(imgURL, srcNode.ownerDocument);
imgURL = 'http://www.google.com/searchbyimage?image_url='
+ encodeURIComponent(imgURL) + '&num=10'
// open image in new tab
var background = gPrefService.getBoolPref("browser.tabs.loadInBackground");
if (event.shiftKey || event.ctrlKey)
background = !background;
gBrowser.loadOneTab(imgURL, null, null, null, background, false);
@vayn
Copy link
Author

vayn commented Jun 27, 2011

@son0fhobs
Copy link

The description seems a bit vague, and reading the code, I could quite figure out what the initial event/variable it's starting with. Do you think you could notate the exact purpose? Thanks!

@vayn
Copy link
Author

vayn commented Aug 22, 2011

This script is written for FireGestures https://addons.mozilla.org/en-us/firefox/addon/firegestures/
It enables you to search image in web page or background when you use a predefined gesture on it.
Please read this article and its doc for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment