Skip to content

Instantly share code, notes, and snippets.

@marshall
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshall/1bb4ee1aee30ec723fc6 to your computer and use it in GitHub Desktop.
Save marshall/1bb4ee1aee30ec723fc6 to your computer and use it in GitHub Desktop.
All FxOS apps as JSON
var schemes = {
"app:": "A",
"http:": "H",
"https:": "S",
"file:": "F"
};
var domains = {
".gaiamobile.org": "G"
};
var groupRegexes = {
"gaia": /app:\/\/([^\.]+).gaiamobile.org\/manifest.webapp/
};
var apps = {
others: []
};
function addApp(app) {
var url = app.manifestURL;
var hasMatch = false;
Object.keys(groupRegexes).forEach(function(key) {
var regex = groupRegexes[key];
var matches = regex.exec(url);
if (matches) {
if (!apps.hasOwnProperty(key)) {
apps[key] = [];
}
apps[key].push(matches[1]);
hasMatch = true;
}
});
if (!hasMatch) {
apps.others.push(miniURL(url));
}
}
function miniURL(url) {
// Obviously this isn't robust
var parts = url.split(/\/+/);
var scheme = parts[0];
if (!schemes.hasOwnProperty(scheme)) {
return url;
}
var mini = "$" + schemes[scheme] + "/";
var miniDomain = parts[1];
Object.keys(domains).forEach(function(domain) {
miniDomain = miniDomain.replace(domain, "$" + domains[domain]);
});
mini += miniDomain;
if (parts.length == 3 && parts[2] == "manifest.webapp") {
mini += "/$M";
} else {
var pathParts = parts.slice(2);
mini += "/" + pathParts.join("/");
}
return mini;
}
navigator.mozApps.mgmt.getAll().onsuccess = function() {
var urls = [];
var miniURLs = [];
this.result.forEach(function(app) {
urls.push(app.manifestURL);
miniURLs.push(miniURL(app.manifestURL));
addApp(app);
});
var json = JSON.stringify(urls);
var miniJSON = JSON.stringify(miniURLs);
var appsJSON = JSON.stringify(apps);
console.log("Original JSON", json);
console.log("Bytes", json.length);
console.log("Mini JSON", miniJSON);
console.log("Mini Bytes", miniJSON.length);
console.log("Apps JSON", appsJSON);
console.log("Apps Bytes", appsJSON.length);
console.log("App count", urls.length);
}
@marshall
Copy link
Author

marshall commented Jul 7, 2014

Example result from FxOS 2.1 simulator:

"Original JSON" "["app://bluetooth.gaiamobile.org/manifest.webapp","app://bookmark.gaiamobile.org/manifest.webapp","app://browser.gaiamobile.org/manifest.webapp","app://calendar.gaiamobile.org/manifest.webapp","app://callscreen.gaiamobile.org/manifest.webapp","app://camera.gaiamobile.org/manifest.webapp","app://clock.gaiamobile.org/manifest.webapp","app://collection.gaiamobile.org/manifest.webapp","app://communications.gaiamobile.org/manifest.webapp","app://costcontrol.gaiamobile.org/manifest.webapp","app://email.gaiamobile.org/manifest.webapp","app://emergency-call.gaiamobile.org/manifest.webapp","app://findmydevice.gaiamobile.org/manifest.webapp","app://fl.gaiamobile.org/manifest.webapp","app://fm.gaiamobile.org/manifest.webapp","app://ftu.gaiamobile.org/manifest.webapp","app://gallery.gaiamobile.org/manifest.webapp","app://homescreen.gaiamobile.org/manifest.webapp","app://keyboard.gaiamobile.org/manifest.webapp","https://marketplace.firefox.com/packaged.webapp","app://music.gaiamobile.org/manifest.webapp","app://operatorvariant.gaiamobile.org/manifest.webapp","app://pdfjs.gaiamobile.org/manifest.webapp","app://ringtones.gaiamobile.org/manifest.webapp","app://search.gaiamobile.org/manifest.webapp","app://settings.gaiamobile.org/manifest.webapp","app://sms.gaiamobile.org/manifest.webapp","app://system.gaiamobile.org/manifest.webapp","app://verticalhome.gaiamobile.org/manifest.webapp","app://video.gaiamobile.org/manifest.webapp","app://wallpaper.gaiamobile.org/manifest.webapp","app://wappush.gaiamobile.org/manifest.webapp"]"
"Bytes" 1532
"Mini JSON" "["$A/bluetooth$G/$M","$A/bookmark$G/$M","$A/browser$G/$M","$A/calendar$G/$M","$A/callscreen$G/$M","$A/camera$G/$M","$A/clock$G/$M","$A/collection$G/$M","$A/communications$G/$M","$A/costcontrol$G/$M","$A/email$G/$M","$A/emergency-call$G/$M","$A/findmydevice$G/$M","$A/fl$G/$M","$A/fm$G/$M","$A/ftu$G/$M","$A/gallery$G/$M","$A/homescreen$G/$M","$A/keyboard$G/$M","$S/marketplace.firefox.com/packaged.webapp","$A/music$G/$M","$A/operatorvariant$G/$M","$A/pdfjs$G/$M","$A/ringtones$G/$M","$A/search$G/$M","$A/settings$G/$M","$A/sms$G/$M","$A/system$G/$M","$A/verticalhome$G/$M","$A/video$G/$M","$A/wallpaper$G/$M","$A/wappush$G/$M"]"
"Mini Bytes" 628
"Apps JSON" "{"others":["$S/marketplace.firefox.com/packaged.webapp"],"gaia":["bluetooth","bookmark","browser","calendar","callscreen","camera","clock","collection","communications","costcontrol","email","emergency-call","findmydevice","fl","fm","ftu","gallery","homescreen","keyboard","music","operatorvariant","pdfjs","ringtones","search","settings","sms","system","verticalhome","video","wallpaper","wappush"]}"
"Apps Bytes" 400
"App count" 32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment