Created
March 7, 2011 15:09
-
-
Save satyr/858606 to your computer and use it in GitHub Desktop.
keyconfig to KeySnail
This file contains hidden or 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
#!coco | |
`#!node` | |
PREFIX = \keyconfig.main.xxx_key__ | |
user_pref = (name, pref) -> | |
return if name.lastIndexOf PREFIX, 0 | |
[mods, k, vk, code, win] = pref.split \][ | |
return if mods is \! or not code | |
switch win | |
case '' then type = \Global | |
case \chrome://browser/content/browser.xul then type = \View | |
default return | |
key = '' | |
key += \M- if ~mods.indexOf \alt | |
key += \C- if ~mods.indexOf \control | |
if ~mods.indexOf \shift | |
then vk and key += \S- | |
else k.=toLowerCase() | |
key += k || "<#{ vk.slice(3)toLowerCase() }>" | |
console.log "\nkey.set#{type}Key(%s, function(){\n%s\n}, %s)", | |
JSON.stringify key | |
code.trim()replace /^/mg ' ' | |
JSON.stringify name.slice PREFIX.length | |
if process.argv.2 | |
then eval "#{ require(\fs)readFileSync that }"replace /^[^]*?(?=user_)/ '' | |
else console.log "usage: #{module.filename} prefs.js >> .keysnail.js" |
This file contains hidden or 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
#!node | |
var PREFIX, user_pref, that; | |
PREFIX = 'keyconfig.main.xxx_key__'; | |
user_pref = function(name, pref){ | |
var mods, k, vk, code, win, type, key, _ref; | |
if (name.lastIndexOf(PREFIX, 0)) { | |
return; | |
} | |
_ref = pref.split(']['), mods = _ref[0], k = _ref[1], vk = _ref[2], code = _ref[3], win = _ref[4]; | |
if (mods === '!' || !code) { | |
return; | |
} | |
switch (win) { | |
case '': | |
type = 'Global'; | |
break; | |
case 'chrome://browser/content/browser.xul': | |
type = 'View'; | |
break; | |
default: | |
return; | |
} | |
key = ''; | |
if (~mods.indexOf('alt')) { | |
key += 'M-'; | |
} | |
if (~mods.indexOf('control')) { | |
key += 'C-'; | |
} | |
if (~mods.indexOf('shift')) { | |
vk && (key += 'S-'); | |
} else { | |
k = k.toLowerCase(); | |
} | |
key += k || "<" + vk.slice(3).toLowerCase() + ">"; | |
return console.log("\nkey.set" + type + "Key(%s, function(){\n%s\n}, %s)", JSON.stringify(key), code.trim().replace(/^/mg, ' '), JSON.stringify(name.slice(PREFIX.length))); | |
}; | |
if (that = process.argv[2]) { | |
eval(("" + require('fs').readFileSync(that)).replace(/^[^]*?(?=user_)/, '')); | |
} else { | |
console.log("usage: " + module.filename + " prefs.js >> .keysnail.js"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment