Update badge (notification: update & custom permissions)

This commit is contained in:
magnolia1234 2021-05-02 07:51:25 +02:00
parent 5d3b2edf96
commit 4ee999472a
5 changed files with 37 additions and 4 deletions

View file

@ -723,6 +723,9 @@ ext_api.storage.onChanged.addListener(function (changes, namespace) {
} }
} }
} }
if (key === 'version_new') {
version_new = storageChange.newValue;
}
// reset disableJavascriptOnListedSites eventListener // reset disableJavascriptOnListedSites eventListener
ext_api.webRequest.onBeforeRequest.removeListener(disableJavascriptOnListedSites); ext_api.webRequest.onBeforeRequest.removeListener(disableJavascriptOnListedSites);
ext_api.webRequest.handlerBehaviorChanged(); ext_api.webRequest.handlerBehaviorChanged();
@ -1193,6 +1196,8 @@ function updateBadge(activeTab) {
badgeText = 'OFF'; badgeText = 'OFF';
color = 'blue'; color = 'blue';
} }
if (version_new)
badgeText = '^' + badgeText;
let isDefaultSite = matchUrlDomain(defaultSites_domains, currentUrl); let isDefaultSite = matchUrlDomain(defaultSites_domains, currentUrl);
let isCustomSite = matchUrlDomain(customSites_domains, currentUrl); let isCustomSite = matchUrlDomain(customSites_domains, currentUrl);
if (!isDefaultSite && isCustomSite) { if (!isDefaultSite && isCustomSite) {
@ -1200,7 +1205,7 @@ function updateBadge(activeTab) {
origins: ['*://*.' + isCustomSite + '/*'] origins: ['*://*.' + isCustomSite + '/*']
}, function (result) { }, function (result) {
if (!result) if (!result)
badgeText = ''; badgeText = enabledSites.includes(isCustomSite) ? 'C' : '';
if (color && badgeText) if (color && badgeText)
ext_api.browserAction.setBadgeBackgroundColor({color: color}); ext_api.browserAction.setBadgeBackgroundColor({color: color});
ext_api.browserAction.setBadgeText({text: badgeText}); ext_api.browserAction.setBadgeText({text: badgeText});
@ -1213,6 +1218,30 @@ function updateBadge(activeTab) {
} }
} }
var version_new;
check_update();
function check_update() {
var manifestData = ext_api.runtime.getManifest();
var manifest_new = 'https://bitbucket.org/magnolia1234/bypass-paywalls-firefox-clean/raw/master/manifest.json';
fetch(manifest_new)
.then(response => {
if (response.ok) {
response.json().then(json => {
ext_api.management.getSelf(function (result) {
var installType = result.installType;
var version_len = (installType === 'development') ? 7 : 5;
version_new = json['version'];
if (version_new.substring(0, version_len) <= manifestData.version.substring(0, version_len))
version_new = '';
ext_api.storage.local.set({
version_new: version_new
});
});
})
}
});
}
function site_switch() { function site_switch() {
ext_api.tabs.query({ ext_api.tabs.query({
active: true, active: true,

View file

@ -7,6 +7,7 @@ Add Levante-EMV (Spain)
Add L'Oeil de la Photographie (fr/en) Add L'Oeil de la Photographie (fr/en)
Add The New Atlantis Add The New Atlantis
Update custom sites (optional: only permissions for added sites) Update custom sites (optional: only permissions for added sites)
Update badge (notification: update & custom permissions)
* v2.1.8.0 (2021-04-25) * v2.1.8.0 (2021-04-25)
Add Il Giorno (Italy) Add Il Giorno (Italy)

View file

@ -508,5 +508,5 @@
"*://*.wallkit.net/*", "*://*.wallkit.net/*",
"*://*.wsj.net/*" "*://*.wsj.net/*"
], ],
"version": "2.1.8.5" "version": "2.1.8.6"
} }

View file

@ -203,7 +203,7 @@ function remove_permissions() {
var perm_custom = document.getElementById('perm-custom'); var perm_custom = document.getElementById('perm-custom');
var custom_enabled = document.getElementById('custom-enabled'); var custom_enabled = document.getElementById('custom-enabled');
ext_api.permissions.remove({ ext_api.permissions.remove({
origins: ["<all_urls>"] origins: perm_origins
}, function (removed) { }, function (removed) {
if (removed) { if (removed) {
perm_custom.innerText = 'NO'; perm_custom.innerText = 'NO';

View file

@ -20,6 +20,9 @@ fetch(manifest_new)
var version_len = (installType === 'development') ? 7 : 5; var version_len = (installType === 'development') ? 7 : 5;
var version_new = json['version']; var version_new = json['version'];
if (version_new.substring(0, version_len) > manifestData.version.substring(0, version_len)) { if (version_new.substring(0, version_len) > manifestData.version.substring(0, version_len)) {
ext_api.storage.local.set({
version_new: version_new
});
anchorEl = document.createElement('a'); anchorEl = document.createElement('a');
anchorEl.innerText = 'New release v' + version_new; anchorEl.innerText = 'New release v' + version_new;
if (manifestData.applications && manifestData.applications.gecko.id.includes('magnolia')) { if (manifestData.applications && manifestData.applications.gecko.id.includes('magnolia')) {
@ -51,4 +54,4 @@ fetch(manifest_new)
anchorEl.target = '_blank'; anchorEl.target = '_blank';
versionString_new.appendChild(anchorEl); versionString_new.appendChild(anchorEl);
} }
}); });