Skip to content

Commit

Permalink
Added vrs (view rendered source) command
Browse files Browse the repository at this point in the history
  • Loading branch information
LouCypher committed Oct 7, 2013
1 parent 22f780e commit 4856261
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
25 changes: 24 additions & 1 deletion extension/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,29 @@ function startup(data, reason) {
}
})

// view rendered source
gcli.addCommand({
name: "vrs",
description: "View rendered source of current page.",
exec: function(args, context) {
let document = context.environment.document;
let doctypeElem = "";
let doctype = document.doctype;
if (doctype) {
doctypeElem += "<!DOCTYPE " + doctype.name;
doctypeElem += doctype.publicId ? (' PUBLIC "' + doctype.publicId + '"') : "";
doctypeElem += doctype.systemId ? (' "' + doctype.systemId + '"') : "";
doctypeElem += ">\n";
}
let source = doctypeElem + document.documentElement.outerHTML;
let isHTML = document.createElement("div").tagName === "DIV";
let contentType = isHTML ? "text/html" : "application/xml";
let dataURI = "data:" + contentType + ";charset=utf-8" + ","
+ encodeURIComponent(source);
context.environment.chromeWindow.switchToTabHavingURI("view-source:" + dataURI, true);
}
})

// whois
gcli.addCommand({
name: "whois",
Expand Down Expand Up @@ -350,7 +373,7 @@ function startup(data, reason) {

function shutdown(data, reason) {
["anim", "chkupd", "cssreload", "darken", "escape", "unescape",
"jsenabled", "locale", "vs", "whois", "winsize"].
"jsenabled", "locale", "vs", "vrs", "whois", "winsize"].
forEach(function(cmd) {
gcli.removeCommand(cmd);
})
Expand Down
26 changes: 24 additions & 2 deletions view-source.mozcmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
[
{
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) {
Expand All @@ -32,5 +32,27 @@

context.environment.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 doctypeElem = "";
let doctype = document.doctype;
if (doctype) {
doctypeElem += "<!DOCTYPE " + doctype.name;
doctypeElem += doctype.publicId ? (' PUBLIC "' + doctype.publicId + '"') : "";
doctypeElem += doctype.systemId ? (' "' + doctype.systemId + '"') : "";
doctypeElem += ">\n";
}
let source = doctypeElem + document.documentElement.outerHTML;
let isHTML = document.createElement("div").tagName === "DIV";
let contentType = isHTML ? "text/html" : "application/xml";
let dataURI = "data:" + contentType + ";charset=utf-8" + ","
+ encodeURIComponent(source);
context.environment.chromeWindow.switchToTabHavingURI("view-source:" + dataURI, true);
}
}
]

0 comments on commit 4856261

Please sign in to comment.