-
-
Save barrackdo/1942753 to your computer and use it in GitHub Desktop.
[sleipnir] OneKeyActionKai
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name One Key Action Kai | |
// @description Add Action OneKey. | |
// @include * | |
// @type SleipnirScript | |
// ==/UserScript== | |
/* | |
This script is Sleipnir 2 only. | |
Original Script is "OneKeyAcrion" written by 8th713 | |
Source : https://gist.github.com/220347 | |
Reference : http://8th713.tumblr.com/post/225746259 | |
*/ | |
(function(){ | |
var keyConfig = new Array(); | |
var fso = new ActiveXObject('Scripting.FileSystemObject'); | |
var usrRsrc = fso.BuildPath(sleipnir.UserFolder, "UserResource"); | |
var okaPath = fso.BuildPath(usrRsrc, "OneKeyAction"); | |
var txtPath = fso.BuildPath(okaPath, "settings.txt"); | |
if(!fso.FolderExists(usrRsrc)) { | |
fso.CreateFolder(usrRsrc); | |
} | |
if(!fso.FolderExists(okaPath)) { | |
fso.CreateFolder(okaPath); | |
} | |
if(!fso.FileExists(txtPath)) { | |
try{ | |
var strm = fso.CreateTextFile(txtPath, true, false); | |
for(var i = 0; i < 0xff; i++) { | |
strm.WriteLine("\t"); | |
} | |
strm.Write("\t"); | |
}finally{ | |
strm.Close(); | |
} | |
} | |
var stream = fso.OpenTextFile(txtPath, 1, false, -2); | |
var text = stream.ReadAll().split(/\r\n/); | |
stream.Close(); | |
for(var i = 0; i < text.length; i++){ | |
keyConfig.push(text[i].split("\t")[1]); | |
} | |
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(keyConfig[e.keyCode].length == 0) { | |
Status = "設定されていません"; | |
}else if(!(/:/.test(keyConfig[e.keyCode])) || keyConfig[e.keyCode].match(/\(.*:.*\)/) != null) { | |
sleipnir.api.ExecuteAction(keyConfig[e.keyCode]); | |
}else if(keyConfig[e.keyCode].indexOf(":") == 0) { | |
sleipnir.api.NewWindow(keyConfig[e.keyCode].replace(/^:/, ''), true); | |
}else { | |
sleipnir.api.URL = 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