Last active
April 26, 2016 09:49
-
-
Save muffinresearch/cc81f80c612317873f5cf0297a372fa4 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
// INSTALL THE ADD-ON | |
let data = { | |
noscript: { | |
id: '{73a6fe31-595d-460b-a920-fcc0f8843232}', | |
installURL: 'https://addons.mozilla.org/firefox/downloads/latest/722/addon-722-latest.xpi?src=dp-btn-primary' | |
}, | |
mutetabs: { | |
id: 'mute-all-inactive-tabs@evilpie.tomschuster.name', | |
installURL: 'https://addons.mozilla.org/firefox/downloads/file/394320/mute_all_inactive_tabs-0.1.1.xpi?src=ss', | |
} | |
} | |
function logEvent(e) { | |
console.log(e); | |
} | |
function install(name) { | |
return window.navigator.mozAddonManager.createInstall({url: data[name].installURL}) | |
.then(installobj => { | |
installobj.addEventListener('onDownloadStarted', logEvent); | |
installobj.addEventListener('onDownloadProgress', logEvent); | |
installobj.addEventListener('onDownloadEnded', logEvent); | |
installobj.addEventListener('onInstallStarted', logEvent); | |
installobj.addEventListener('onInstallFailed', logEvent); | |
installobj.addEventListener('onInstallEnded', logEvent); | |
installobj.addEventListener('onInstallCancelled', logEvent); | |
installobj.addEventListener('onExternalInstall', logEvent); | |
installobj.install(); | |
return installobj; | |
}); | |
} | |
// CHECK ITS THERE | |
function lookup(name) { | |
return window.navigator.mozAddonManager.getAddonByID(data[name].id) | |
.then((addon) => { | |
if (!addon) { | |
console.log('no add-on found'); | |
} else { | |
console.log(addon); | |
} | |
}); | |
} | |
// UNINSTALL THE ADD-ON | |
function uninstall(name) { | |
return lookup(name) | |
.then((addon) => { | |
return addon.uninstall() | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment