Skip to content

Commit

Permalink
Updated for backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
LouCypher committed Oct 7, 2013
1 parent af5a8f5 commit cc75aa0
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 33 deletions.
3 changes: 2 additions & 1 deletion cssreload.mozcmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
// @url https://github.com/auchenberg/css-reloader
// @license Creative Commons Attribution 3.0 Unported License

let elements = context.environment.document.querySelectorAll("link[rel=stylesheet][href]");
let document = context.environment.document || context.environment.contentDocument;
let elements = document.querySelectorAll("link[rel=stylesheet][href]");
for (let i = 0; i < elements.length; i++) {
let element = elements[i];
let h = element.href.replace(/[?&]cssReloader=([^&$]*)/, "");
Expand Down
4 changes: 2 additions & 2 deletions darken.mozcmd
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
else
opacity = (100 - darkLevel) / 100;

let browser = context.environment.chromeDocument.getElementById("browser"),
gBrowser = context.environment.chromeWindow.gBrowser;
let browser = context.environment.chromeDocument.getElementById("browser");
let gBrowser = context.environment.chromeDocument.getElementById("content");
if (opacity === 1 || gBrowser.style.opacity === opacity.toString()) {
browser.style.backgroundColor = "";
gBrowser.style.opacity = "";
Expand Down
4 changes: 2 additions & 2 deletions escape.mozcmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
],
returnType: "string",
exec: function(args, context) {
let win = context.environment.window || context.environment.contentDocument.defaultView;
let string = args.string;
if (!string)
string = context.environment.window.location.href;
string = win.location.href;
let escaped = encodeURIComponent(string);
let clipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"].
getService(Ci.nsIClipboardHelper);
Expand Down Expand Up @@ -52,5 +53,4 @@
return unescaped;
}
}

]
44 changes: 27 additions & 17 deletions extension/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ function startup(data, reason) {
// @url https://github.com/auchenberg/css-reloader
// @license Creative Commons Attribution 3.0 Unported License

let elements = context.environment.document.querySelectorAll("link[rel=stylesheet][href]");
let document = context.environment.document || context.environment.contentDocument;
let elements = document.querySelectorAll("link[rel=stylesheet][href]");
for (let i = 0; i < elements.length; i++) {
let element = elements[i];
let h = element.href.replace(/[?&]cssReloader=([^&$]*)/, "");
Expand Down Expand Up @@ -97,8 +98,6 @@ function startup(data, reason) {
}
],
exec: function(args, context) {
Services.prefs.clearUserPref("darken.data"); // Remove old prefs

let darkLevel = args["Dark level"];
if (darkLevel < 0) darkLevel = 0;
if (darkLevel > 100) darkLevel = 100;
Expand All @@ -109,8 +108,8 @@ function startup(data, reason) {
else
opacity = (100 - darkLevel) / 100;

let browser = context.environment.chromeDocument.getElementById("browser"),
gBrowser = context.environment.chromeWindow.gBrowser;
let browser = context.environment.chromeDocument.getElementById("browser");
let gBrowser = context.environment.chromeDocument.getElementById("content");
if (opacity === 1 || gBrowser.style.opacity === opacity.toString()) {
browser.style.backgroundColor = "";
gBrowser.style.opacity = "";
Expand All @@ -136,9 +135,10 @@ function startup(data, reason) {
],
returnType: "string",
exec: function(args, context) {
let win = context.environment.window || context.environment.contentDocument.defaultView;
let string = args.string;
if (!string)
string = context.environment.window.location.href;
string = win.location.href;
let escaped = encodeURIComponent(string);
let clipboardHelper = Cc["@mozilla.org/widget/clipboardhelper;1"].
getService(Ci.nsIClipboardHelper);
Expand Down Expand Up @@ -182,12 +182,13 @@ function startup(data, reason) {
],
returnType: "string",
exec: function(args, context) {
let win = 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)
context.environment.window.location.reload();
win.location.reload();
return "JavaScript is " + (!jsEnabled ? "enabled" : "disabled") + ".";
}
})
Expand Down Expand Up @@ -237,27 +238,31 @@ function startup(data, reason) {
// view source
gcli.addCommand({
name: "vs",
description: "View HTML source of current document or a specified URL.",
description: "View HTML source of current page or a specified URL.",
params: [
{
name: "url",
type: "string",
defaultValue: null,
description: "Web page URL to view its source. If no URL is entered,\
view source of current document."
view 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 url;
if (args.url)
url = args.url;
else
url = context.environment.document.URL;
url = document.URL;

if (!/^[a-z0-9]+:/i.test(url))
url = "http://" + url; // Use 'http' by default

context.environment.chromeWindow.switchToTabHavingURI("view-source:" + url, true);
chromeWindow.switchToTabHavingURI("view-source:" + url, true);
}
})

Expand All @@ -266,7 +271,10 @@ function startup(data, reason) {
name: "vrs",
description: "View rendered source of current page.",
exec: function(args, context) {
let document = context.environment.document;
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) {
Expand All @@ -280,7 +288,7 @@ function startup(data, reason) {
let contentType = isHTML ? "text/html" : "application/xml";
let dataURI = "data:" + contentType + ";charset=utf-8" + ","
+ encodeURIComponent(source);
context.environment.chromeWindow.switchToTabHavingURI("view-source:" + dataURI, true);
chromeWindow.switchToTabHavingURI("view-source:" + dataURI, true);
}
})

Expand All @@ -298,8 +306,9 @@ function startup(data, reason) {
],
returnType: "string",
exec: function(args, context) {
let content = context.environment.window;
let window = context.environment.chromeWindow;
let environment = context.environment;
let content = environment.window || environment.contentDocument.defaultView;
let window = environment.chromeWindow || environment.chromeDocument.defaultView;

let hostname;
if (!args.domain)
Expand Down Expand Up @@ -348,8 +357,9 @@ function startup(data, reason) {
],
returnType: "string",
exec: function(args, context) {
let window = context.environment.chromeWindow;
let document = context.environment.chromeDocument;
let environment = context.environment;
let window = environment.chromeWindow || environment.chromeDocument.defaultView;
let document = environment.chromeDocument;
let browserWin = document.documentElement;
let screen = window.screen;

Expand Down
4 changes: 2 additions & 2 deletions extension/install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<em:type>2</em:type>
<em:bootstrap>true</em:bootstrap>
<em:name>mozcmd</em:name><!-- Temporary name -->
<em:version>0.1</em:version>
<em:version>0.2</em:version>
<em:description>Add more commands for Developer Toolbar (GCLI).</em:description>
<em:creator>LouCypher</em:creator>
<em:homepageURL>https://github.com/LouCypher/mozcmd</em:homepageURL>
Expand Down Expand Up @@ -34,7 +34,7 @@
<em:targetApplication>
<Description><!--Firefox-->
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>24.0</em:minVersion>
<em:minVersion>17.0</em:minVersion>
<em:maxVersion>26.*</em:maxVersion>
</Description>
</em:targetApplication>
Expand Down
3 changes: 2 additions & 1 deletion jsenabled.mozcmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
],
returnType: "string",
exec: function(args, context) {
let win = 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)
context.environment.window.location.reload();
win.location.reload();
return "JavaScript is " + (!jsEnabled ? "enabled" : "disabled") + ".";
}
}
Expand Down
15 changes: 11 additions & 4 deletions view-source.mozcmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,31 @@
}
],
exec: function(args, context) {
let environment = context.environment;
let document = environment.document || environment.contentDocument;
let chromeWindow = environment.chromeWindow || environment.chromeDocument.defaultView;

let url;
if (args.url)
url = args.url;
else
url = context.environment.document.URL;
url = document.URL;

if (!/^[a-z0-9]+:/i.test(url))
url = "http://" + url; // Use 'http' by default

context.environment.chromeWindow.switchToTabHavingURI("view-source:" + url, true);
chromeWindow.switchToTabHavingURI("view-source:" + url, true);
}
},

{
name: "vrs",
description: "View rendered source of current page.",
exec: function(args, context) {
let document = context.environment.document;
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) {
Expand All @@ -52,7 +59,7 @@
let contentType = isHTML ? "text/html" : "application/xml";
let dataURI = "data:" + contentType + ";charset=utf-8" + ","
+ encodeURIComponent(source);
context.environment.chromeWindow.switchToTabHavingURI("view-source:" + dataURI, true);
chromeWindow.switchToTabHavingURI("view-source:" + dataURI, true);
}
}
]
5 changes: 3 additions & 2 deletions whois.mozcmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
],
returnType: "string",
exec: function(args, context) {
let content = context.environment.window;
let window = context.environment.chromeWindow;
let environment = context.environment;
let content = environment.window || environment.contentDocument.defaultView;
let window = environment.chromeWindow || environment.chromeDocument.defaultView;

let hostname;
if (!args.domain)
Expand Down
5 changes: 3 additions & 2 deletions winsize.mozcmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
],
returnType: "string",
exec: function(args, context) {
let window = context.environment.chromeWindow;
let document = context.environment.chromeDocument;
let environment = context.environment;
let window = environment.chromeWindow || environment.chromeDocument.defaultView;
let document = environment.chromeDocument;
let browserWin = document.documentElement;
let screen = window.screen;

Expand Down

0 comments on commit cc75aa0

Please sign in to comment.