Преглед изворни кода

Moved from cfx to jpm, improved code

master
mort пре 6 година
родитељ
комит
88923c7ac2
7 измењених фајлова са 84 додато и 66 уклоњено
  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 Прегледај датотеку

@@ -0,0 +1,2 @@
#Mouseless
For a mouseless future.

+ 66
- 36
data/onload.js Прегледај датотеку

@@ -1,3 +1,12 @@
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 = {
scroll_up: {code: 84},
scroll_down: {code: 78},
@@ -17,15 +26,19 @@ var keys = {
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
//the "speed dial"-ish pages.
var onWebPage = (document.body !== undefined);
@@ -132,18 +145,19 @@ var blobList = {

var blobElem = document.createElement("div");
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.blobs[key] = {
@@ -215,29 +229,41 @@ setInterval(function() {
currentUrl = location.href;
}, 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) {
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;
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)) {
active.blur();
} else {
@@ -255,9 +281,13 @@ window.addEventListener("keydown", function(evt) {
}

//Handle other key presses

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

//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)
blobList.loadBlobs();
blobList.needLoadBlobs = false;

lib/main.js → index.js Прегледај датотеку


+ 0
- 25
install.rdf Прегледај датотеку

@@ -1,25 +0,0 @@

<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 Прегледај датотеку


+ 8
- 4
package.json Прегледај датотеку

@@ -1,9 +1,13 @@
{
"name": "mouseless-plugin",
"title": "Mouseless",
"id": "jid1-tCi0cNSM24lhnw",
"name": "mouseless",
"version": "0.2.0",
"description": "For a mouseless future.",
"main": "index.js",
"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 Прегледај датотеку

@@ -1,4 +1,4 @@
var main = require("./main");
var main = require("../");

exports["test main"] = function(assert) {
assert.pass("Unit test running!");
@@ -9,4 +9,11 @@ exports["test main async"] = function(assert, 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);

Loading…
Откажи
Сачувај