Skip to content

Instantly share code, notes, and snippets.

@8th713
Created October 28, 2009 08:00
Show Gist options
  • Save 8th713/220347 to your computer and use it in GitHub Desktop.
Save 8th713/220347 to your computer and use it in GitHub Desktop.
[sleipnir] OneKeyAction
// ==UserScript==
// @name OneKeyAction
// @description Add Action OneKey
// @include *
// @type SleipnirScript
// ==/UserScript==
(function(){
var keyConfig = {
66 : 'GoBack',
70 : 'GoForward',
67 : 'Close',
83 : 'http://www.sleipnirstart.com/'
};
var s = CreateObject("ScriptControl");
if(s){
s.Language = "JScript";
s.AddObject("ScriptControl", s);
s.AddObject("sleipnir", sleipnir, true);
s.AddObject("window", _window, true);
s.AddObject("keyConfig", keyConfig);
s.AddCode(main);
try{
s.Run("main");
}catch(e){
Output.Print(s.Error.Line + ": " + s.Error.Description, false);
}
}
function main(){
function keyUp(e){
var tag = e.srcElement.tagName;
var SCA = e.shiftKey||e.ctrlKey||e.altKey;
if(/^input|textarea$/i.test(tag)||SCA) return;
if(keyConfig[e.keyCode]!=undefined){
if(/:/.test(keyConfig[e.keyCode]))
sleipnir.api.URL = keyConfig[e.keyCode];
else
sleipnir.api.ExecuteAction(keyConfig[e.keyCode]);
};
};
window.attachEvent('onunload',function(){
scriptControl = null;
document.detachEvent('onkeyup',keyUp);
window.detachEvent('onunload', arguments.callee);
});
document.attachEvent('onkeyup',keyUp);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment