Skip to content

Commit

Permalink
Added update all option to context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverDecaf committed Nov 1, 2019
1 parent 6335203 commit 2f58fb0
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 4 deletions.
Binary file modified Chromium Web Store.crx
Binary file not shown.
5 changes: 3 additions & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
"author": "NeverDecaf",
"manifest_version": 2,
"name": "Chromium Web Store",
"version": "0.6.0",
"version": "0.7.0",
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqF/d41Q7agjkUzYq8ZGbQr8XW8mmEIMXOnR1uCTnYLL+Dm9Z+LO50xZukOISNy6zFxpI8ts/OGLsm+I2x9+UprUU4/EVdmxuwegFE6NBoEhHoRNYY0gbXZkaU8YY/XwzjVY/k18DDhl5NYPEnF6uq4Oyidg+xtd3W4+iGYczuOLER1Tp5y614zOTphcvFYhvUkCijQ6HT1TtRq/34SlFoRQqo4SFiLriK451xWIcfwiMLIekWrdoQa1v8dqIlMA3r6CKc0QykJpSYbiyormWiZ0hl2HLpkZ85mD9V0eDQ5RCtb6vkybK7INcq4yKQV4YkXhr9NpX9U4re4dlFQjEJQIDAQAB",
"description": "Allow installing/updating extensions from chrome web store on chromium based browsers. Click badge to check for updates.",
"permissions": [
"management",
"https://clients2.google.com/service/*",
"storage",
"alarms"
"alarms",
"contextMenus"
],
"browser_action": {
"default_icon": {
Expand Down
97 changes: 96 additions & 1 deletion src/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function updateBadge(modified_ext_id = null) {
}
});
updateUrls.push(updateUrl);

function getNewXhr() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
Expand Down Expand Up @@ -97,4 +98,98 @@ chrome.runtime.onStartup.addListener(function () {
chrome.alarms.onAlarm.addListener(function (alarm) {
if (alarm.name == 'cws_check_extension_updates')
updateBadge();
});
});

function updateAll(info) {
if (info.menuItemId == 'updateAll') {
chrome.storage.sync.get({
"auto_update": true,
"check_store_apps": true,
"check_external_apps": true
}, function (settings) {
chrome.management.getAll(function (e) {
var chromeVersion = /Chrome\/([0-9.]+)/.exec(navigator.userAgent)[1];
var webstoreUrl = 'clients2.google.com/service/update2/crx';
var updateUrl = 'https://clients2.google.com/service/update2/crx?response=updatecheck&acceptformat=crx2,crx3&prodversion=' + chromeVersion;
var installed_versions = {};
var updateUrls = [];
e.forEach(function (ex) {
if (ex.updateUrl) {
if (webstoreUrl == ex.updateUrl.replace(/^(?:https?:\/\/)?/i, "")) {
updateUrl += '&x=id%3D' + ex.id + '%26uc';
} else {
updateUrls.push(ex.updateUrl);
}
installed_versions[ex.id] = ex;
}
});
updateUrls.push(updateUrl);

function getNewXhr() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4) {
if (this.status == 200) {
xmlDoc = this.responseXML;
var updates = xmlDoc.getElementsByTagName('app');
let updateCount = 0;
for (var i = 0; i < updates.length; i++) {
if (updateCheck = updates[i].querySelector("*")) {
var updatever = updateCheck.getAttribute('version');
var appid = updates[i].getAttribute('appid');
var is_webstore = xhttp._url == updateUrl;
if (updatever && installed_versions[appid].version != updatever) {
updateCount++;
let crx_url = updateCheck.getAttribute('codebase');
window.open(crx_url, '_blank');
}
}
}
chrome.browserAction.getBadgeText({}, function (currentText) {
if (currentText != '?') {
if (!currentText) {
if (updateCount)
chrome.browserAction.setBadgeText({
text: '' + updateCount
});
} else
chrome.browserAction.setBadgeText({
text: parseInt(updateCount) + parseInt(currentText) + ''
});
}
});
} else {
container.appendChild(updatefailure);
if (is_webstore)
chrome.browserAction.setBadgeText({
text: "?"
});
}
}
};
xhttp.overrideMimeType('application/xml');
return xhttp;
};
chrome.browserAction.setBadgeText({
text: ''
});
updateUrls.forEach(function (uurl) {
if ((updateUrl == uurl && settings.check_store_apps) || (updateUrl != uurl && settings.check_external_apps)) {
xhr = getNewXhr();
xhr.open("GET", uurl, true);
xhr._url = uurl;
xhr.send();
}
});
});
});
}
};
chrome.runtime.onInstalled.addListener(function () {
chrome.contextMenus.create({
title: "Update All Extensions",
id: 'updateAll',
contexts: ["browser_action"]
});
});
chrome.contextMenus.onClicked.addListener(updateAll);
2 changes: 1 addition & 1 deletion updates.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='ocaahdebbfolfmndjeplogmgcagdmblk'>
<updatecheck codebase='https://github.com/NeverDecaf/chromium-web-store/releases/latest/download/Chromium.Web.Store.crx' version='0.6.0' />
<updatecheck codebase='https://github.com/NeverDecaf/chromium-web-store/releases/latest/download/Chromium.Web.Store.crx' version='0.7.0' />
</app>
</gupdate>

0 comments on commit 2f58fb0

Please sign in to comment.