Browse Source

Moved from cfx to jpm, improved code

master
mort 8 years ago
parent
commit
88923c7ac2
7 changed files with 84 additions and 66 deletions
  1. 2
    0
      README.md
  2. 66
    36
      data/onload.js
  3. 0
    0
      index.js
  4. 0
    25
      install.rdf
  5. BIN
      mouseless-plugin.xpi
  6. 8
    4
      package.json
  7. 8
    1
      test/test-index.js

+ 2
- 0
README.md View File

#Mouseless
For a mouseless future.

+ 66
- 36
data/onload.js View File

var conf = {
scroll_speed: 0.4,
scroll_speed_fast: 1.1,
scroll_friction: 0.8,
chars: "SANOTEHUCP",
input_whitelist: ["checkbox", "radio", "hidden", "submit", "reset", "button", "file", "image"],
location_change_check_timeout: 2000
}

var keys = { var keys = {
scroll_up: {code: 84}, scroll_up: {code: 84},
scroll_down: {code: 78}, scroll_down: {code: 78},
history_forward: {code: 83, ctrlKey: true} history_forward: {code: 83, ctrlKey: true}
} }


var conf = {
scroll_speed: 0.4,
scroll_speed_fast: 1.1,
scroll_friction: 0.8,
chars: "SANOTEHUCP",
input_whitelist: ["checkbox", "radio", "hidden", "submit", "reset", "button", "file", "image"],
location_change_check_timeout: 2000
function isMatch(k, evt) {
if ((k.code === evt.keyCode)
&& (!!k.ctrlKey == evt.ctrlKey)
&& (!!k.shiftKey == evt.shiftKey)
&& (!!k.altKey == evt.altKey)
&& (!!k.metaKey == evt.metaKey)) {
return true;
}

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);


var blobElem = document.createElement("div"); var blobElem = document.createElement("div");
blobElem.innerHTML = key; blobElem.innerHTML = key;
blobElem.style =
"position: absolute;"+
"background-color: yellow;"+
"border: 1px solid black;"+
"border-radius: 10px;"+
"padding-left: 3px;"+
"padding-right: 3px;"+
"color: black;"+
"top: "+pos.top+"px;"+
"left: "+pos.left+"px;"+
"line-height: 12px;"+
"font-size: 8pt;";
blobElem.style = [
"position: absolute",
"background-color: yellow",
"border: 1px solid black",
"border-radius: 10px",
"padding-left: 3px",
"padding-right: 3px",
"color: black",
"top: "+pos.top+"px",
"left: "+pos.left+"px",
"line-height: 12px",
"font-size: 12px"
].join(" !important;");
blobList.container.appendChild(blobElem); blobList.container.appendChild(blobElem);


blobList.blobs[key] = { blobList.blobs[key] = {
currentUrl = location.href; currentUrl = location.href;
}, conf.location_change_check_timeout); }, conf.location_change_check_timeout);


function isMatch(k, evt) {
if ((k.code === evt.keyCode)
&& (!!k.ctrlKey == evt.ctrlKey)
&& (!!k.shiftKey == evt.shiftKey)
&& (!!k.altKey == evt.altKey)
&& (!!k.metaKey == evt.metaKey)) {
return true;
}
var pressedKeys = [];


return false;
function inArray(arr, val) {
return (arr.indexOf(val) !== -1);
} }


var pressedKeys = [];
function isValidElem(elem) {
var tag = elem.tagName.toLowerCase();

if (tag === "textarea")
return false;

if (tag === "select")
return false;

if (elem.contentEditable.toLowerCase() === "true")
return false;

if ((tag === "input")
&& (!inArray(conf.input_whitelist, elem.type.toLowerCase()))) {
return false;
}

return true;
}


window.addEventListener("keydown", function(evt) { window.addEventListener("keydown", function(evt) {
if (/about:.+/.test(location.href))
return;


//We don't want to do anything if the user is tpying in an input field,
//unless the key is to deselect an input field
var active = document.activeElement; var active = document.activeElement;
if ((active.tagName === "TEXTAREA")
|| (active.tagName === "INPUT" && conf.input_whitelist.indexOf(active.type.toLowerCase) === -1)
|| (/true/i.test(active.contentEditable))) {


//We don't want to do anything if the user is tpying in an input field,
//unless the key is to deselect an input field
if (!isValidElem(active)) {
if (isMatch(keys.elem_deselect, evt)) { if (isMatch(keys.elem_deselect, evt)) {
active.blur(); active.blur();
} else { } else {
} }


//Handle other key presses //Handle other key presses

//Deselect element
if (onWebPage && isMatch(keys.elem_deselect, evt)) {
active.blur();

//Show/hide/reload blobs //Show/hide/reload blobs
if (onWebPage && !blobList.visible && isMatch(keys.blobs_show, evt)) {
} else if (onWebPage && !blobList.visible && isMatch(keys.blobs_show, evt)) {
if (blobList.needLoadBlobs) if (blobList.needLoadBlobs)
blobList.loadBlobs(); blobList.loadBlobs();
blobList.needLoadBlobs = false; blobList.needLoadBlobs = false;

lib/main.js → index.js View File


+ 0
- 25
install.rdf View File


<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">

<Description about="urn:mozilla:install-manifest">
<em:id>keyless@mort.coffee</em:id>
<em:version>1.0</em:version>
<em:bootstrap>true</em:bootstrap>
<em:type>2</em:type>

<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>1.5</em:minVersion>
<em:maxVersion>4.0.*</em:maxVersion>
</Description>
</em:targetApplication>
<!-- Front End MetaData -->
<em:name>Keyless</em:name>
<em:description>A plugin for keyless browsing.</em:description>
<em:creator>Martin Dørum Nygaard</em:creator>
<em:homepageURL>http://www.mort.coffee/</em:homepageURL>
</Description>
</RDF>

BIN
mouseless-plugin.xpi View File


+ 8
- 4
package.json View File

{ {
"name": "mouseless-plugin",
"title": "Mouseless", "title": "Mouseless",
"id": "jid1-tCi0cNSM24lhnw",
"name": "mouseless",
"version": "0.2.0",
"description": "For a mouseless future.", "description": "For a mouseless future.",
"main": "index.js",
"author": "Martin Dørum Nygaard", "author": "Martin Dørum Nygaard",
"license": "MIT",
"version": "0.1"
"engines": {
"firefox": ">=38.0a1",
"fennec": ">=38.0a1"
},
"license": "MIT"
} }

test/test-main.js → test/test-index.js View File

var main = require("./main");
var main = require("../");


exports["test main"] = function(assert) { exports["test main"] = function(assert) {
assert.pass("Unit test running!"); assert.pass("Unit test running!");
done(); done();
}; };


exports["test dummy"] = function(assert, done) {
main.dummy("foo", function(text) {
assert.ok((text === "foo"), "Is the text actually 'foo'");
done();
});
};

require("sdk/test").run(exports); require("sdk/test").run(exports);

Loading…
Cancel
Save