Skip to content

Commit

Permalink
Apply substitution groups according to their mode: automatic for on-l…
Browse files Browse the repository at this point in the history
…oad and periodic and manual for the user-requested. #206
  • Loading branch information
Woundorf committed Nov 21, 2017
1 parent abed0e1 commit 565b977
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Added 3 modes for substitution groups (issue 206):
- auto: used in auto-replace on load and auto-replace every n seconds
- manual: used when manually applying the substitution list
- auto&manual (default): used in both cases, equivalent to previous versions
* New list format 2.1 to include the mode.
* Dropped support for substitution lists in the 0.13 format.

v2.0.0 (2017-10-13)
Expand Down
14 changes: 1 addition & 13 deletions scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,7 @@ browser.storage.onChanged.addListener(changes => {
// Listen for periodic replace alarm
browser.alarms.onAlarm.addListener(alarm => {
if (alarm.name == periodicReplace.alarmName) {
Promise.all([storage.getEnabledGroups(), storage.getPrefs()])
.then(([list, prefs]) => {
if (list.length > 0) {
replaceCurrentTab({
key: "replace",
list: substitutionListToJSON(list),
prefs: {
replaceUrls: prefs.replaceUrls,
replaceScripts: prefs.replaceScripts
}
});
}
});
replaceCurrentTab({ key: "replaceWithListPeriod"});
}
});

Expand Down
11 changes: 9 additions & 2 deletions scripts/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The content has just loaded. Apply the substitution list if auto-replace on load is on.
storage.getPrefs().then(prefs => {
if (prefs.autoReplaceOnLoad) {
storage.getEnabledGroups().then(list => {
storage.getAutomaticGroups().then(list => {
replaceWindow(window, list, prefs);
});
}
Expand All @@ -34,7 +34,14 @@ browser.runtime.onMessage.addListener(message => {
break;
case "replaceWithList":
storage.getPrefs().then(prefs => {
storage.getEnabledGroups().then(list => {
storage.getManualGroups().then(list => {
replaceWindow(window, list, prefs);
});
});
break;
case "replaceWithListPeriod":
storage.getPrefs().then(prefs => {
storage.getAutomaticGroups().then(list => {
replaceWindow(window, list, prefs);
});
});
Expand Down
8 changes: 6 additions & 2 deletions scripts/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ var storage = {
return browser.storage.local.set(sanitizedPrefs);
},

getEnabledGroups() {
return this.getList().then(list => list.filter(group => group.enabled));
getAutomaticGroups() {
return this.getList().then(list => list.filter(group => group.enabled && (group.mode == group.MODE_AUTO_AND_MANUAL || group.mode == group.MODE_AUTO)));
},

getManualGroups() {
return this.getList().then(list => list.filter(group => group.enabled && (group.mode == group.MODE_AUTO_AND_MANUAL || group.mode == group.MODE_MANUAL)));
}

};

0 comments on commit 565b977

Please sign in to comment.