-
-
Save dannydes/6962839 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"); | |
//from http://stackoverflow.com/questions/9996986/reading-writing-preferences - need to check over this in here | |
var prefsBranch = Components.classes["@mozilla.org/preferences-service;1"]. | |
getService(Components.interfaces.nsIPrefService). | |
getBranch("general.useragent."); | |
var mdnCommandParams = [ | |
{ | |
name: 'property', | |
type: 'string', | |
description: 'property name', | |
} | |
]; | |
function execMDNCommand(args, context, ref) { | |
var $this = this; | |
var promise = context.createPromise(); | |
var locale = prefsBranch.getComplexValue("locale", Components.interfaces.nsIPrefLocalizedString).data; //haven't tested - https://developer.mozilla.org/en-US/docs/Code_snippets/Preferences | |
var url = "https://developer.mozilla.org/" + locale + "/docs/" + ref + "/" + | |
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; | |
} | |
gcli.addCommand({ | |
name: 'cssdoc', | |
description: 'Documentation for CSS properties', | |
returnType: 'html', | |
params: mdnCommandParams, | |
exec: function(args, context) { | |
return execMDNCommand(args, context, 'CSS'); | |
} | |
}); | |
gcli.addCommand({ | |
name: 'domdoc', | |
description: 'Documentation for DOM methods and properties', | |
returnType: 'html', | |
params: mdnCommandParams, | |
exec: function(args, context) { | |
return execMDNCommand(args, context, 'DOM'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment