Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.