Skip to content

Instantly share code, notes, and snippets.

@lmorchard
Created August 9, 2012 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lmorchard/3307756 to your computer and use it in GitHub Desktop.
Save lmorchard/3307756 to your computer and use it in GitHub Desktop.
Components.utils.import("resource:///modules/devtools/gcli.jsm");
gcli.addCommand({
name: 'cssdoc',
description: 'Documentation for CSS properties',
returnType: 'html',
params: [
{
name: 'property',
type: 'string',
description: 'property name',
}
],
exec: function(args, context) {
var $this = this;
var promise = context.createPromise();
var locale = 'en-US'; // TODO: Find how to dig this up out of chrome.
var url = "https://developer.mozilla.org/" + locale + "/docs/CSS/" +
encodeURIComponent(args.property);
var xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"];
let req = xhr.createInstance();
req.open('GET', url + "?raw&macros&section=Summary", true);
req.onreadystatechange = function () {
if (4==this.readyState) {
var content = this.responseText;
let req = xhr.createInstance();
req.open('GET', url + "$json", true);
req.onreadystatechange = function () {
if (4==this.readyState) {
var meta = JSON.parse(this.responseText);
promise.resolve([
"<div>",
"<h1><a href=\"", url, "\">", meta.title, "</a></h1>",
"<div>", content, "</div>",
"</div>"
].join(""));
}
};
req.send();
}
};
req.send();
return promise;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment