Skip to content

Commit

Permalink
[mv3] Prevent enabling more filter lists than allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jul 9, 2023
1 parent 3f7b7fe commit 634fdde
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions platform/mv3/extension/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ p {
display: none;
}

body.noMoreRuleset .listEntry:not(.checked) {
opacity: 0.5;
pointer-events: none;
}

/* touch-screen devices */
:root.mobile .listEntry .fa-icon {
font-size: 120%;
Expand Down
1 change: 1 addition & 0 deletions platform/mv3/extension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ function onMessage(request, sender, callback) {
callback({
defaultFilteringMode,
enabledRulesets,
maxNumberOfEnabledRulesets: dnr.MAX_NUMBER_OF_ENABLED_STATIC_RULESETS,
rulesetDetails: Array.from(rulesetDetails.values()),
autoReload: rulesetConfig.autoReload === 1,
firstRun,
Expand Down
12 changes: 10 additions & 2 deletions platform/mv3/extension/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,12 @@ const renderWidgets = function() {
qs$('#autoReload input[type="checkbox"').checked = cachedRulesetData.autoReload;

// Compute total counts
let rulesetCount = 0;
let filterCount = 0;
let ruleCount = 0;
for ( const liEntry of qsa$('#lists .listEntry[data-listkey]') ) {
if ( qs$(liEntry, 'input[type="checkbox"]:checked') === null ) { continue; }
if ( qs$(liEntry, 'input[type="checkbox"]:checked') === null ) { continue; }
rulesetCount += 1;
const stats = rulesetStats(liEntry.dataset.listkey);
if ( stats === undefined ) { continue; }
ruleCount += stats.ruleCount;
Expand All @@ -234,6 +236,10 @@ const renderWidgets = function() {
.replace('{{ruleCount}}', ruleCount.toLocaleString())
.replace('{{filterCount}}', filterCount.toLocaleString())
);

dom.cl.toggle(dom.body, 'noMoreRuleset',
rulesetCount === cachedRulesetData.maxNumberOfEnabledRulesets
);
};

/******************************************************************************/
Expand Down Expand Up @@ -292,7 +298,9 @@ dom.on('#autoReload input[type="checkbox"', 'change', ev => {
async function applyEnabledRulesets() {
const enabledRulesets = [];
for ( const liEntry of qsa$('#lists .listEntry[data-listkey]') ) {
if ( qs$(liEntry, 'input[type="checkbox"]:checked') === null ) { continue; }
const checked = qs$(liEntry, 'input[type="checkbox"]:checked') !== null;
dom.cl.toggle(liEntry, 'checked', checked);
if ( checked === false ) { continue; }
enabledRulesets.push(liEntry.dataset.listkey);
}

Expand Down

0 comments on commit 634fdde

Please sign in to comment.