Skip to content

Instantly share code, notes, and snippets.

@zentooo
Created November 11, 2010 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zentooo/672808 to your computer and use it in GitHub Desktop.
Save zentooo/672808 to your computer and use it in GitHub Desktop.
let PLUGIN_INFO =
<VimperatorPlugin>
<name>instant previews</name>
<description>This script allows you to use Instant Viewer feature of Google Search with Vimperator.</description>
<version>0.1.0</version>
<author>zentooo</author>
<license>Creative Commons</license>
<detail><![CDATA[
== Subject ==
This script allows you use Google's Instant Viewer with Vimperator.
]]></detail>
</VimperatorPlugin>;
(function(lib, ly) {
var searchReg = "www\.google\.co\.[a-z]{2}/search";
commands.addUserCommand( ["instant"], "enable Google Instant Viewer plugin", function(args) {
var tab = getBrowser().mCurrentTab,
wrapped = tab.linkedBrowser.contentWindow.wrappedJSObject,
event = wrapped.document.createEvent("MouseEvents"),
vscs;
tab.current = tab.current || -1;
tab.first = tab.first || true;
event.initMouseEvent("mouseover", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
mappings.addUserMap([modes.NORMAL], ["j"], "iterate search results", function() {
vscs = wrapped.document.getElementsByClassName("vsc");
if ( tab.current === -1 ) {
if ( tab.first === true ) {
event.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
vscs[0].dispatchEvent(event);
tab.first = false;
}
event.initMouseEvent("mouseover", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
tab.offset = ly.getElementPosition(vscs[0]).top * 2;
tab.current = 0;
}
else if ( tab.current < vscs.length - 1 ) {
tab.current++;
vscs[tab.current].dispatchEvent(event);
buffer.scrollTo(0, ly.getElementPosition(vscs[tab.current]).top - tab.offset);
}
}, { matchingUrls: [ searchReg ] });
mappings.addUserMap([modes.NORMAL], ["k"], "reverse iterate search results", function() {
tab.offset = tab.offset || ly.getElementPosition(vscs[0]).top * 2;
if ( tab.current > -1 ) {
tab.current--;
vscs = wrapped.document.getElementsByClassName("vsc");
vscs[tab.current].dispatchEvent(event);
buffer.scrollTo(0, ly.getElementPosition(vscs[tab.current]).top - tab.offset);
}
}, { matchingUrls: [ searchReg ] });
mappings.addUserMap([modes.NORMAL], ["gg"], "go to the top", function() {
tab.current = -1;
buffer.scrollTo(0, 0);
}, { matchingUrls: [ searchReg ] });
mappings.addUserMap([modes.NORMAL], ["<C-m>"], "open tab.current item with a new tab", function() {
var href = vscs[tab.current].attributes.getNamedItem("rawurl").nodeValue;
lib.open(href, { where: lib.NEW_TAB });
}, { matchingUrls: [ searchReg ] });
}
);
autocommands.add("LocationChange", searchReg, ":instant");
})(liberator, liberator.plugins.libly.$U);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment