diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..8a0aa38
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,6 @@
+# Auto detect text files and perform LF normalization
+* text eol=lf
+
+*.gif binary
+*.png binary
+*.jpg binary
diff --git a/cssreload.mozcmd b/cssreload.mozcmd
index 5255b07..3722489 100644
--- a/cssreload.mozcmd
+++ b/cssreload.mozcmd
@@ -8,8 +8,8 @@
// @url https://github.com/auchenberg/css-reloader
// @license Creative Commons Attribution 3.0 Unported License
- let document = context.environment.document || context.environment.contentDocument;
- let elements = document.querySelectorAll("link[rel=stylesheet][href]");
+ let contentDoc = context.environment.document || context.environment.contentDocument;
+ let elements = contentDoc.querySelectorAll("link[rel=stylesheet][href]");
for (let i = 0; i < elements.length; i++) {
let element = elements[i];
let h = element.href.replace(/[?&]cssReloader=([^&$]*)/, "");
diff --git a/darken.mozcmd b/darken.mozcmd
index c5e439e..3272da3 100644
--- a/darken.mozcmd
+++ b/darken.mozcmd
@@ -15,7 +15,6 @@
License under Public Domain Dedication
http://creativecommons.org/publicdomain/zero/1.0/
*/
-
[
{
name: "darken",
diff --git a/escape.mozcmd b/escape.mozcmd
index 403bfed..0fe03a4 100644
--- a/escape.mozcmd
+++ b/escape.mozcmd
@@ -21,10 +21,10 @@
],
returnType: "string",
exec: function(args, context) {
- let win = context.environment.window || context.environment.contentDocument.defaultView;
+ let contentWin = context.environment.window || context.environment.contentDocument.defaultView;
let string = args.string;
if (!string)
- string = win.location.href;
+ string = contentWin.location.href;
let escaped = encodeURIComponent(string);
let clipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"].
getService(Ci.nsIClipboardHelper);
diff --git a/extension/bootstrap.js b/extension/bootstrap.js
index e449d1e..88d0d5e 100644
--- a/extension/bootstrap.js
+++ b/extension/bootstrap.js
@@ -12,7 +12,7 @@ const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
Cu.import("resource:///modules/devtools/gcli.jsm");
Cu.import("resource://gre/modules/Services.jsm");
-/** unused for now
+/** for future use
Cu.import("resource://gre/modules/AddonManager.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
@@ -66,8 +66,8 @@ var mozcmd = {
// @url https://github.com/auchenberg/css-reloader
// @license Creative Commons Attribution 3.0 Unported License
- let document = context.environment.document || context.environment.contentDocument;
- let elements = document.querySelectorAll("link[rel=stylesheet][href]");
+ let contentDoc = context.environment.document || context.environment.contentDocument;
+ let elements = contentDoc.querySelectorAll("link[rel=stylesheet][href]");
for (let i = 0; i < elements.length; i++) {
let element = elements[i];
let h = element.href.replace(/[?&]cssReloader=([^&$]*)/, "");
@@ -136,10 +136,10 @@ var mozcmd = {
],
returnType: "string",
exec: function(args, context) {
- let win = context.environment.window || context.environment.contentDocument.defaultView;
+ let contentWin = context.environment.window || context.environment.contentDocument.defaultView;
let string = args.string;
if (!string)
- string = win.location.href;
+ string = contentWin.location.href;
let escaped = encodeURIComponent(string);
let clipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"].
getService(Ci.nsIClipboardHelper);
@@ -181,13 +181,13 @@ var mozcmd = {
],
returnType: "string",
exec: function(args, context) {
- let win = context.environment.window || context.environment.contentDocument.defaultView;
+ let contentWin = context.environment.window || context.environment.contentDocument.defaultView;
let prefname = "javascript.enabled";
let prefs = Services.prefs;
let jsEnabled = prefs.getBoolPref(prefname);
prefs.setBoolPref(prefname, !jsEnabled);
if (args.reload)
- win.location.reload();
+ contentWin.location.reload();
return "JavaScript is " + (!jsEnabled ? "enabled" : "disabled") + ".";
}
},
@@ -247,19 +247,19 @@ var mozcmd = {
],
exec: function(args, context) {
let environment = context.environment;
- let document = environment.document || environment.contentDocument;
- let chromeWindow = environment.chromeWindow || environment.chromeDocument.defaultView;
+ let contentDoc = environment.document || environment.contentDocument;
+ let chromeWin = environment.chromeWindow || environment.chromeDocument.defaultView;
let url;
if (args.url)
url = args.url;
else
- url = document.URL;
+ url = contentDoc.location.href;
if (!/^[a-z0-9]+:/i.test(url))
url = "http://" + url; // Use 'http' by default
- chromeWindow.switchToTabHavingURI("view-source:" + url, true);
+ chromeWin.switchToTabHavingURI("view-source:" + url, true);
}
},
@@ -268,23 +268,17 @@ var mozcmd = {
description: "View rendered source of current page.",
exec: function(args, context) {
let environment = context.environment;
- let document = environment.document || environment.contentDocument;
- let chromeWindow = environment.chromeWindow || environment.chromeDocument.defaultView;
-
- let doctypeElem = "";
- let doctype = document.doctype;
- if (doctype) {
- doctypeElem += "\n";
- }
- let source = doctypeElem + document.documentElement.outerHTML;
- let isHTML = document.createElement("div").tagName === "DIV";
+ let contentDoc = environment.document || environment.contentDocument;
+ let chromeWin = environment.chromeWindow || environment.chromeDocument.defaultView;
+
+ let domSerializer = Cc["@mozilla.org/xmlextras/xmlserializer;1"].
+ createInstance(Ci.nsIDOMSerializer);
+ let source = domSerializer.serializeToString(contentDoc);
+ let isHTML = contentDoc.createElement("div").tagName === "DIV";
let contentType = isHTML ? "text/html" : "application/xml";
let dataURI = "data:" + contentType + ";charset=utf-8" + ","
+ encodeURIComponent(source);
- chromeWindow.switchToTabHavingURI("view-source:" + dataURI, true);
+ chromeWin.switchToTabHavingURI("view-source:" + dataURI, true);
}
},
@@ -299,20 +293,20 @@ var mozcmd = {
description: "Domain name to lookup. If no domain specified, lookup current web site."
}
],
- returnType: "string",
+ //returnType: "string",
exec: function(args, context) {
let environment = context.environment;
- let content = environment.window || environment.contentDocument.defaultView;
- let window = environment.chromeWindow || environment.chromeDocument.defaultView;
+ let contentWin = environment.window || environment.contentDocument.defaultView;
+ let chromeWin = environment.chromeWindow || environment.chromeDocument.defaultView;
let hostname;
if (!args.domain)
- hostname = content.location.hostname;
+ hostname = contentWin.location.hostname;
else
hostname = args.domain;
if (!hostname) {
- return content.location.protocol + " scheme is not supported.";
+ return contentWin.location.protocol + " scheme is not supported.";
}
let eTLDsvc = Services.eTLD;
@@ -322,7 +316,7 @@ var mozcmd = {
} catch (ex) {
eTLD = URI.asciiHost;
}
- window.switchToTabHavingURI("http://whois.domaintools.com/" + eTLD, true);
+ chromeWin.switchToTabHavingURI("http://whois.domaintools.com/" + eTLD, true);
//return eTLD;
}
},
@@ -352,19 +346,19 @@ var mozcmd = {
returnType: "string",
exec: function(args, context) {
let environment = context.environment;
- let window = environment.chromeWindow || environment.chromeDocument.defaultView;
- let document = environment.chromeDocument;
- let browserWin = document.documentElement;
- let screen = window.screen;
+ let chromeWin = environment.chromeWindow || environment.chromeDocument.defaultView;
+ let chromeDoc = environment.chromeDocument;
+ let browserWin = chromeDoc.documentElement;
+ let screen = chromeWin.screen;
function centerScreen() {
- window.moveTo((screen.availWidth - browserWin.width) / 2,
- (screen.availHeight - browserWin.height) / 2);
+ chromeWin.moveTo((screen.availWidth - browserWin.width) / 2,
+ (screen.availHeight - browserWin.height) / 2);
}
let width = args.width, height = args.height, center = args.center;
if (width && height) {
- window.resizeTo(width, height);
+ chromeWin.resizeTo(width, height);
if (center)
centerScreen();
return "Resized to " + width + "x" + height;
@@ -373,7 +367,7 @@ var mozcmd = {
if (center)
centerScreen();
- switch (window.windowState) {
+ switch (chromeWin.windowState) {
case 3: // normal
return browserWin.width + "x" + browserWin.height;
case 1: // maximized
@@ -384,12 +378,12 @@ var mozcmd = {
}
function startup(data, reason) {
- for (var i in mozcmd)
+ for (let i in mozcmd)
gcli.addCommand(mozcmd[i]);
}
function shutdown(data, reason) {
- for (var i in mozcmd)
+ for (let i in mozcmd)
gcli.removeCommand(mozcmd[i]);
}
diff --git a/extension/install.rdf b/extension/install.rdf
index 457b745..11dbc15 100644
--- a/extension/install.rdf
+++ b/extension/install.rdf
@@ -6,7 +6,7 @@
2
true
mozcmd
- 0.2.1
+ 0.3
Add more commands for Developer Toolbar (GCLI).
LouCypher
https://github.com/LouCypher/mozcmd
diff --git a/jsenabled.mozcmd b/jsenabled.mozcmd
index 9c59dff..29dc9d9 100644
--- a/jsenabled.mozcmd
+++ b/jsenabled.mozcmd
@@ -20,13 +20,13 @@
],
returnType: "string",
exec: function(args, context) {
- let win = context.environment.window || context.environment.contentDocument.defaultView;
+ let contentWin = context.environment.window || context.environment.contentDocument.defaultView;
let prefname = "javascript.enabled";
let prefs = Services.prefs;
let jsEnabled = prefs.getBoolPref(prefname);
prefs.setBoolPref(prefname, !jsEnabled);
if (args.reload)
- win.location.reload();
+ contentWin.location.reload();
return "JavaScript is " + (!jsEnabled ? "enabled" : "disabled") + ".";
}
}
diff --git a/locale.mozcmd b/locale.mozcmd
index 0708572..59c39b3 100644
--- a/locale.mozcmd
+++ b/locale.mozcmd
@@ -21,7 +21,15 @@
],
returnType: "string",
exec: function(args, context) {
- let prefname = "general.useragent.locale";
+ let prefname = "general.useragent.locale"; // See AMO warning below
+ /*
+ AMO warning from add-on validator:
+ ---
+ Potentially unsafe preference branch referenced
+ Warning: Extensions should not alter preferences in this preference branch
+ ---
+ I couldn't find another way to change browser locale without using preferences
+ */
let prefs = Services.prefs;
let msgPrefix = "Browser language: '";
let msgSuffix = "'";
diff --git a/view-source.mozcmd b/view-source.mozcmd
index bfc8769..95c7252 100644
--- a/view-source.mozcmd
+++ b/view-source.mozcmd
@@ -22,19 +22,19 @@
],
exec: function(args, context) {
let environment = context.environment;
- let document = environment.document || environment.contentDocument;
- let chromeWindow = environment.chromeWindow || environment.chromeDocument.defaultView;
+ let contentDoc = environment.document || environment.contentDocument;
+ let chromeWin = environment.chromeWindow || environment.chromeDocument.defaultView;
let url;
if (args.url)
url = args.url;
else
- url = document.URL;
+ url = contentDoc.location.href;
if (!/^[a-z0-9]+:/i.test(url))
url = "http://" + url; // Use 'http' by default
- chromeWindow.switchToTabHavingURI("view-source:" + url, true);
+ chromeWin.switchToTabHavingURI("view-source:" + url, true);
}
},
@@ -43,23 +43,17 @@
description: "View rendered source of current page.",
exec: function(args, context) {
let environment = context.environment;
- let document = environment.document || environment.contentDocument;
- let chromeWindow = environment.chromeWindow || environment.chromeDocument.defaultView;
+ let contentDoc = environment.document || environment.contentDocument;
+ let chromeWin = environment.chromeWindow || environment.chromeDocument.defaultView;
- let doctypeElem = "";
- let doctype = document.doctype;
- if (doctype) {
- doctypeElem += "\n";
- }
- let source = doctypeElem + document.documentElement.outerHTML;
- let isHTML = document.createElement("div").tagName === "DIV";
+ let domSerializer = Cc["@mozilla.org/xmlextras/xmlserializer;1"].
+ createInstance(Ci.nsIDOMSerializer);
+ let source = domSerializer.serializeToString(contentDoc);
+ let isHTML = contentDoc.createElement("div").tagName === "DIV";
let contentType = isHTML ? "text/html" : "application/xml";
let dataURI = "data:" + contentType + ";charset=utf-8" + ","
+ encodeURIComponent(source);
- chromeWindow.switchToTabHavingURI("view-source:" + dataURI, true);
+ chromeWin.switchToTabHavingURI("view-source:" + dataURI, true);
}
}
]
diff --git a/whois.mozcmd b/whois.mozcmd
index 5b98a85..2e805be 100644
--- a/whois.mozcmd
+++ b/whois.mozcmd
@@ -19,20 +19,20 @@
description: "Domain name to lookup. If no domain specified, lookup current web site."
}
],
- returnType: "string",
+ //returnType: "string",
exec: function(args, context) {
let environment = context.environment;
- let content = environment.window || environment.contentDocument.defaultView;
- let window = environment.chromeWindow || environment.chromeDocument.defaultView;
+ let contentWin = environment.window || environment.contentDocument.defaultView;
+ let chromeWin = environment.chromeWindow || environment.chromeDocument.defaultView;
let hostname;
if (!args.domain)
- hostname = content.location.hostname;
+ hostname = contentWin.location.hostname;
else
hostname = args.domain;
if (!hostname) {
- return content.location.protocol + " scheme is not supported.";
+ return contentWin.location.protocol + " scheme is not supported.";
}
let eTLDsvc = Services.eTLD;
@@ -42,7 +42,7 @@
} catch (ex) {
eTLD = URI.asciiHost;
}
- window.switchToTabHavingURI("http://whois.domaintools.com/" + eTLD, true);
+ chromeWin.switchToTabHavingURI("http://whois.domaintools.com/" + eTLD, true);
//return eTLD;
}
}
diff --git a/winsize.mozcmd b/winsize.mozcmd
index c74d256..06ba8cf 100644
--- a/winsize.mozcmd
+++ b/winsize.mozcmd
@@ -33,19 +33,19 @@
returnType: "string",
exec: function(args, context) {
let environment = context.environment;
- let window = environment.chromeWindow || environment.chromeDocument.defaultView;
- let document = environment.chromeDocument;
- let browserWin = document.documentElement;
- let screen = window.screen;
+ let chromeWin = environment.chromeWindow || environment.chromeDocument.defaultView;
+ let chromeDoc = environment.chromeDocument;
+ let browserWin = chromeDoc.documentElement;
+ let screen = chromeWin.screen;
function centerScreen() {
- window.moveTo((screen.availWidth - browserWin.width) / 2,
- (screen.availHeight - browserWin.height) / 2);
+ chromeWin.moveTo((screen.availWidth - browserWin.width) / 2,
+ (screen.availHeight - browserWin.height) / 2);
}
let width = args.width, height = args.height, center = args.center;
if (width && height) {
- window.resizeTo(width, height);
+ chromeWin.resizeTo(width, height);
if (center)
centerScreen();
return "Resized to " + width + "x" + height;
@@ -54,7 +54,7 @@
if (center)
centerScreen();
- switch (window.windowState) {
+ switch (chromeWin.windowState) {
case 3: // normal
return browserWin.width + "x" + browserWin.height;
case 1: // maximized