Created
August 9, 2012 20:20
-
-
Save lmorchard/3307756 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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¯os§ion=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