Fixed bug in lastMappingUpdate and added hideReleaseNotes in settings

This commit is contained in:
nobody42 2020-04-06 18:04:53 +02:00
parent 27eb0d8c17
commit e9057f7918
No known key found for this signature in database
GPG Key ID: AB5145CF05BFE119
6 changed files with 86 additions and 28 deletions

View File

@ -70,5 +70,21 @@
"generateRuleSetTitle": {
"message": "Generiere Regelsätze für uBlock oder uMatrix",
"description": "Generate rule set title."
},
"loggingTitle": {
"message": "Aktiviere das loggen in die Browser-Konsole",
"description": "Aktiviere das loggen in die Browser-Konsole."
},
"loggingDescription": {
"message": "Öffne die \"Browser-Konsole\" ( STRG + UMSCHALT + J ) um fehlende Resourcen anzuzeigen.",
"description": "Öffne die \"Browser-Konsole\" ( STRG + UMSCHALT + J ) um fehlende Resourcen anzuzeigen."
},
"hideReleaseNotesTitle": {
"message": "Versionshinweise deaktivieren",
"description": "Versionshinweise deaktivieren"
},
"hideReleaseNotesDescription": {
"message": "Falls aktivert, erhälst du keine Hinweise über Neuerungen in LocalCDN. Dazu gehören auch Informationen über neue uBlock/uMatrix-Regeln.",
"description": "Falls aktivert, erhälst du keine Hinweise über Neuerungen in LocalCDN. Dazu gehören auch Informationen über neue uBlock/uMatrix-Regeln."
}
}

View File

@ -77,6 +77,14 @@
},
"loggingDescription": {
"message": "Open \"Browser Console\" ( CTRL + SHIFT + J ) to show missing resources",
"description": "Generate rule set title."
"description": "Open \"Browser Console\" ( CTRL + SHIFT + J ) to show missing resources."
},
"hideReleaseNotesTitle": {
"message": "Disable release notes",
"description": "Disable release notes"
},
"hideReleaseNotesDescription": {
"message": "If enabled, you wont receive any information about new features in LocalCDN. This includes information about new uBlock/uMatrix rules.",
"description": "If enabled, you wont receive any information about new features in LocalCDN. This includes information about new uBlock/uMatrix rules."
}
}

View File

@ -60,7 +60,7 @@ const Setting = {
'DISABLE_PREFETCH': 'disablePrefetch',
'ENFORCE_STAGING': 'enforceStaging',
'SHOW_ICON_BADGE': 'showIconBadge',
'SHOW_RELEASE_NOTES': 'showReleaseNotes',
'HIDE_RELEASE_NOTES': 'hideReleaseNotes',
'STRIP_METADATA': 'stripMetadata',
'LAST_MAPPING_UPDATE': 'lastMappingUpdate',
'WHITELISTED_DOMAINS': 'whitelistedDomains',

View File

@ -31,8 +31,8 @@ main._initializeSettings = function () {
[Setting.BLOCK_MISSING]: false,
[Setting.DISABLE_PREFETCH]: true,
[Setting.ENFORCE_STAGING]: false,
[Setting.HIDE_RELEASE_NOTES]: false,
[Setting.STRIP_METADATA]: true,
[Setting.LAST_MAPPING_UPDATE]: "2020-01-01",
[Setting.WHITELISTED_DOMAINS]: {},
[Setting.LOGGING]: false
};
@ -69,41 +69,55 @@ main._showReleaseNotes = function (details) {
if (details.reason === chrome.runtime.OnInstalledReason.INSTALL) {
previousVersion = details.previousVersion;
chrome.storage.local.set({
[Setting.LAST_MAPPING_UPDATE]: lastMappingUpdate
}, function() {
if (previousVersion && previousVersion.charAt(0) === '2') {
return; // Do not show release notes after minor updates.
}
previousVersion = details.previousVersion;
if (details.temporary !== true) {
if (previousVersion && previousVersion.charAt(0) === '2') {
return; // Do not show release notes after minor updates.
}
chrome.storage.local.get({
[Setting.SHOW_RELEASE_NOTES]: true
}, function (items) {
if (details.temporary !== true) {
if (items.showReleaseNotes === true) {
chrome.storage.local.get([Setting.HIDE_RELEASE_NOTES], function (items) {
chrome.tabs.create({
'url': location,
'active': false
});
}
});
}
} else if (details.reason === chrome.runtime.OnInstalledReason.UPDATE) {
// If add-on update true, check last update of mappings.js
chrome.storage.local.get({[Setting.LAST_MAPPING_UPDATE]: lastMappingUpdate}, function (items) {
if (items.lastMappingUpdate !== lastMappingUpdate) {
// Updated mappings.js
chrome.tabs.create({
'url': updateAdBlockerRules,
'active': true
if (items.hideReleaseNotes !== true) {
chrome.tabs.create({
'url': location,
'active': false
});
}
});
}
});
} else if (details.reason === chrome.runtime.OnInstalledReason.UPDATE) {
let newValue = lastMappingUpdate;
let oldValue = "";
// If add-on update true, check last update of mappings.js
chrome.storage.local.get([Setting.LAST_MAPPING_UPDATE, Setting.HIDE_RELEASE_NOTES], function (items) {
oldValue = items.lastMappingUpdate;
if (oldValue !== newValue) {
// Updated mappings.js
chrome.storage.local.set({
[Setting.LAST_MAPPING_UPDATE]: lastMappingUpdate
[Setting.LAST_MAPPING_UPDATE]: newValue
}, function() {
if (!items.hideReleaseNotes) {
chrome.tabs.create({
'url': updateAdBlockerRules,
'active': true
});
}
});
} else {
// No mappings.js update
return;
}
});
}

View File

@ -138,6 +138,23 @@
</section>
<section class="option">
<div class="title-option">
<label class="label-checkbox">
<input class="input-checkbox" data-option="hideReleaseNotes" type="checkbox">
<span data-i18n-content="hideReleaseNotesTitle"></span>
</label>
</div>
<div class="description-option" data-i18n-content="hideReleaseNotesDescription"></div>
</section>
<section class="option">
<div class="title-option" data-i18n-content="whitelistedDomainsTitle"></div>

View File

@ -45,6 +45,7 @@ options._renderOptionsPanel = function () {
elements.blockMissing.checked = options._optionValues.blockMissing;
elements.disablePrefetch.checked = options._optionValues.disablePrefetch;
elements.stripMetadata.checked = options._optionValues.stripMetadata;
elements.hideReleaseNotes.checked = options._optionValues.hideReleaseNotes;
elements.enableLogging.checked = options._optionValues.enableLogging;
elements.whitelistedDomains.value = domainWhitelist;
@ -87,6 +88,7 @@ options._registerOptionChangedEventListeners = function (elements) {
elements.disablePrefetch.addEventListener('change', options._onOptionChanged);
elements.stripMetadata.addEventListener('change', options._onOptionChanged);
elements.enableLogging.addEventListener('change', options._onOptionChanged);
elements.hideReleaseNotes.addEventListener('change', options._onOptionChanged);
elements.whitelistedDomains.addEventListener('keyup', options._onOptionChanged);
let type = elements.ruleSets;
for(let i = 0; i < type.length; i++) {
@ -134,6 +136,7 @@ options._getOptionElements = function () {
[Setting.DISABLE_PREFETCH]: options._getOptionElement(Setting.DISABLE_PREFETCH),
[Setting.STRIP_METADATA]: options._getOptionElement(Setting.STRIP_METADATA),
[Setting.WHITELISTED_DOMAINS]: options._getOptionElement(Setting.WHITELISTED_DOMAINS),
[Setting.HIDE_RELEASE_NOTES]: options._getOptionElement(Setting.HIDE_RELEASE_NOTES),
[Setting.LOGGING]: options._getOptionElement(Setting.LOGGING),
['ruleSets']: document.getElementsByName("rule-sets"),
['copyRuleSet']: document.getElementById("button-copy-rule-set")