Search selection gesture for firefox

This is my "Hello world" of blog posts. I have now taken the dark path of blogging. And ain't nothing better to kick things off with a little snippet of javascript that helped me solve a big problem - how to do a search on selected text with a mouse gesture.

I've been using Mouse Gestures Redox for over a year now and am very pleased with it. A few days ago i thought to myself - wouldn't it be great if i could selected some text and with the same continuous movement perform a search on it? Mouse Gestures Redox allows custom javascript to be run as a gesture and here's what i wrote:

// Get selected text from the HTML DOM
var selectedText = window._content.document.getSelection();
if(!selectedText)
 return;

// Get the searchbar element from the Firefox UI XUL DOM
var searchbar = document.getElementById('searchbar');
if (!searchbar)
 return;

// Perform search
searchbar.value = selectedText;
searchbar.handleSearchCommand();

I have assigned this script to a gesture "R" meaning dragging to the right - really convenient. I'm sure this script is not only applicable for Mouse Gestures Redox but to other gestures add-ons as well.

Helping a brother out,
Mihkel

0 comments: