location_change_check_timeout: 2000 | location_change_check_timeout: 2000 | ||||
} | } | ||||
var keys = { | |||||
scroll_up: {code: "T"}, | |||||
scroll_down: {code: "N"}, | |||||
scroll_up_fast: {code: 219, shiftKey: true}, | |||||
scroll_down_fast: {code: 221, shiftKey: true}, | |||||
var keys = {}; | |||||
blobs_show: {code: "D"}, | |||||
blobs_hide: {code: 27}, | |||||
blobs_click: {code: 13}, | |||||
blobs_click_new_tab: {code: 13, shiftKey: true}, | |||||
blobs_backspace: {code: 8}, | |||||
elem_deselect: {code: 27}, | |||||
change_tab_left: {code: "H"}, | |||||
change_tab_right: {code: "S"}, | |||||
move_tab_left: {code: "H", shiftKey: true}, | |||||
move_tab_right: {code: "S", shiftKey: true}, | |||||
history_back: {code: "H", ctrlKey: true}, | |||||
history_forward: {code: "S", ctrlKey: true} | |||||
} | |||||
for (var i in keys) { | |||||
if (typeof keys[i].code === "string") { | |||||
keys[i].code = keys[i].code.charCodeAt(0); | |||||
self.port.on("conf", function(c) { | |||||
for (var i in c) { | |||||
conf[i] = c[i]; | |||||
} | } | ||||
} | |||||
}); | |||||
self.port.on("keys", function(k) { | |||||
keys = k; | |||||
}); | |||||
function isMatch(k, evt) { | function isMatch(k, evt) { | ||||
if ((k.code === evt.keyCode) | |||||
if ((k.code === evt.key) | |||||
&& (!!k.ctrlKey == evt.ctrlKey) | && (!!k.ctrlKey == evt.ctrlKey) | ||||
&& (!!k.shiftKey == evt.shiftKey) | && (!!k.shiftKey == evt.shiftKey) | ||||
&& (!!k.altKey == evt.altKey) | && (!!k.altKey == evt.altKey) | ||||
return false; | return false; | ||||
} | } | ||||
//There's a lot we don't want to do if we're not on an actual webpage, but on | //There's a lot we don't want to do if we're not on an actual webpage, but on | ||||
//the "speed dial"-ish pages. | //the "speed dial"-ish pages. | ||||
var onWebPage = (document.body !== undefined); | var onWebPage = (document.body !== undefined); | ||||
return; | return; | ||||
} | } | ||||
var c = String.fromCharCode(evt.keyCode); | |||||
var c = evt.key; | |||||
if (conf.chars.indexOf(c) !== -1) { | if (conf.chars.indexOf(c) !== -1) { | ||||
blobList.appendKey(c); | blobList.appendKey(c); | ||||
evt.preventDefault(); | evt.preventDefault(); |
var tabs = require("sdk/tabs"); | var tabs = require("sdk/tabs"); | ||||
var self = require("sdk/self"); | var self = require("sdk/self"); | ||||
var simple_prefs = require("sdk/simple-prefs"); | |||||
var conf = {}; | |||||
var keys = {}; | |||||
function contains(arr, val) { | |||||
if (typeof arr !== "object") | |||||
return false; | |||||
return (arr.indexOf(val) !== -1); | |||||
} | |||||
function prepareConf(prefs) { | |||||
var keys = {}; | |||||
var conf = {}; | |||||
for (var i in prefs) { | |||||
var pref = prefs[i]; | |||||
if (i === "chars") { | |||||
conf[i] = pref; | |||||
continue; | |||||
} | |||||
var modifiers = pref.match(/<[^>]+>/g) || []; | |||||
var key = pref.replace(/<.+>/g, ""); | |||||
if (/^[A-Z]$/.test(key)) | |||||
modifiers.push("<Shift>"); | |||||
keys[i] = { | |||||
code: key, | |||||
shiftKey: contains(modifiers, "<Shift>"), | |||||
ctrlKey: contains(modifiers, "<Control>") | |||||
} | |||||
} | |||||
return {keys: keys, conf: conf}; | |||||
} | |||||
var res = prepareConf(simple_prefs.prefs); | |||||
conf = res.conf; | |||||
keys = res.keys; | |||||
simple_prefs.on("", function() { | |||||
var res = prepareConf(simple_prefs.prefs); | |||||
conf = res.conf; | |||||
keys = res.keys; | |||||
}); | |||||
tabs.on("ready", function(tab) { | tabs.on("ready", function(tab) { | ||||
var worker = tab.attach({ | var worker = tab.attach({ | ||||
contentScriptFile: self.data.url("onload.js") | contentScriptFile: self.data.url("onload.js") | ||||
}); | }); | ||||
worker.port.emit("conf", conf); | |||||
worker.port.emit("keys", keys); | |||||
function selectRelativeTab(n) { | function selectRelativeTab(n) { | ||||
var tabList = []; | var tabList = []; | ||||
var currentTabIndex; | var currentTabIndex; |
{ | { | ||||
"title": "Mouseless", | "title": "Mouseless", | ||||
"name": "mouseless", | "name": "mouseless", | ||||
"version": "0.3.2", | |||||
"version": "0.4.0", | |||||
"description": "For a mouseless future.", | "description": "For a mouseless future.", | ||||
"main": "index.js", | "main": "index.js", | ||||
"author": "Martin Dørum Nygaard", | "author": "Martin Dørum Nygaard", | ||||
"firefox": ">=38.0a1", | "firefox": ">=38.0a1", | ||||
"fennec": ">=38.0a1" | "fennec": ">=38.0a1" | ||||
}, | }, | ||||
"license": "MIT" | |||||
"license": "MIT", | |||||
"preferences": [ | |||||
{ | |||||
"name": "chars", "title": "Characters", | |||||
"type": "string", | |||||
"value": "sanotehucp" | |||||
}, { | |||||
"name": "scroll_up", "title": "Scroll Up", | |||||
"type": "string", | |||||
"value": "t" | |||||
}, { | |||||
"name": "scroll_down", "title": "Scroll Down", | |||||
"type": "string", | |||||
"value": "n" | |||||
}, { | |||||
"name": "scroll_up_fast", "title": "Scroll Up Fast", | |||||
"type": "string", | |||||
"value": "<Shift>{" | |||||
}, { | |||||
"name": "scroll_down_fast", "title": "Scroll Down Fast", | |||||
"type": "string", | |||||
"value": "<Shift>}" | |||||
}, { | |||||
"name": "blobs_show", "title": "Show Blobs", | |||||
"type": "string", | |||||
"value": "d" | |||||
}, { | |||||
"name": "blobs_hide", "title": "Hide Blobs", | |||||
"type": "string", | |||||
"value": "Escape" | |||||
}, { | |||||
"name": "blobs_click", "title": "Click", | |||||
"type": "string", | |||||
"value": "Enter" | |||||
}, { | |||||
"name": "blobs_click_new_tab", "title": "Open in New Tab", | |||||
"type": "string", | |||||
"value": "<Shift>Enter" | |||||
}, { | |||||
"name": "blobs_backspace", "title": "Blobs Backspace", | |||||
"type": "string", | |||||
"value": "Backspace", | |||||
"hidden": true | |||||
}, { | |||||
"name": "elem_deselect", "title": "Deselect Element", | |||||
"type": "string", | |||||
"value": "Escape", | |||||
"hidden": true | |||||
}, { | |||||
"name": "change_tab_left", "title": "Previous Tab", | |||||
"type": "string", | |||||
"value": "h" | |||||
}, { | |||||
"name": "change_tab_right", "title": "Next Tab", | |||||
"type": "string", | |||||
"value": "s" | |||||
}, { | |||||
"name": "move_tab_left", "title": "Move Tab Left", | |||||
"type": "string", | |||||
"value": "H" | |||||
}, { | |||||
"name": "move_tab_right", "title": "Move Tab Right", | |||||
"type": "string", | |||||
"value": "S" | |||||
}, { | |||||
"name": "history_back", "title": "Back", | |||||
"type": "string", | |||||
"value": "<Control>h" | |||||
}, { | |||||
"name": "history_forward", "title": "Forwards", | |||||
"type": "string", | |||||
"value": "<Control>s" | |||||
} | |||||
] | |||||
} | } |