[mv3] Fix "Proceed" button not working in strict-block page

Related issue:
https://github.com/uBlockOrigin/uBOL-home/issues/576
This commit is contained in:
Raymond Hill 2025-12-30 15:36:42 -05:00
parent 3c7eb3497d
commit 9b45333e0d
No known key found for this signature in database
GPG key ID: F5630CAE62A14316

View file

@ -48,9 +48,6 @@ const TRUSTED_DIRECTIVE_BASE_RULE_ID = 8000000;
const TRUSTED_DIRECTIVE_PRIORITY = USER_RULES_PRIORITY + 1000000;
const STRICTBLOCK_PRIORITY = 29;
let dynamicRegexCount = 0;
let sessionRegexCount = 0;
/******************************************************************************/
const isStrictBlockRule = rule => {
@ -128,6 +125,14 @@ pruneInvalidRegexRules.validated = new Map();
/******************************************************************************/
async function getDynamicRegexRuleCount() {
const rules = await dnr.getDynamicRules();
const regexRules = rules.filter(a => Boolean(a.condition?.regexFilter));
return regexRules.length;
}
/******************************************************************************/
async function updateRegexRules(currentRules, addRules, removeRuleIds) {
// Remove existing regex-related block rules
for ( const rule of currentRules ) {
@ -181,19 +186,19 @@ async function updateDynamicRules() {
await updateRegexRules(currentRules, addRules, removeRuleIds);
if ( addRules.length === 0 && removeRuleIds.length === 0 ) { return; }
const dynamicRegexCountBefore = dynamicRegexCount;
dynamicRegexCount = 0;
const dynamicRegexCountBefore = await getDynamicRegexRuleCount();
let dynamicRegexCountAfter = 0;
let ruleId = 1;
for ( const rule of addRules ) {
if ( rule?.condition.regexFilter ) { dynamicRegexCount += 1; }
if ( rule?.condition.regexFilter ) { dynamicRegexCountAfter += 1; }
rule.id = ruleId++;
}
if ( dynamicRegexCount !== 0 ) {
ubolLog(`Using ${dynamicRegexCount}/${dnr.MAX_NUMBER_OF_REGEX_RULES} dynamic regex-based DNR rules`);
if ( dynamicRegexCountAfter !== 0 ) {
ubolLog(`Using ${dynamicRegexCountAfter}/${dnr.MAX_NUMBER_OF_REGEX_RULES} dynamic regex-based DNR rules`);
}
// If we increase the number of dynamic regex rules, reset session rules to
// reduce risk of hitting maximum regex count
if ( dynamicRegexCount > dynamicRegexCountBefore ) {
if ( dynamicRegexCountAfter > dynamicRegexCountBefore ) {
await clearSessionRules();
}
@ -341,7 +346,8 @@ async function updateSessionRules() {
const currentRules = await dnr.getSessionRules();
await updateStrictBlockRules(currentRules, addRulesUnfiltered, removeRuleIds);
if ( addRulesUnfiltered.length === 0 && removeRuleIds.length === 0 ) { return; }
const maxRegexCount = dnr.MAX_NUMBER_OF_REGEX_RULES * 0.80;
const maxRegexCount = dnr.MAX_NUMBER_OF_REGEX_RULES * 0.95;
const dynamicRegexCount = await getDynamicRegexRuleCount();
let regexCount = dynamicRegexCount;
let ruleId = 1;
for ( const rule of addRulesUnfiltered ) {
@ -351,7 +357,7 @@ async function updateSessionRules() {
if ( regexCount < maxRegexCount ) { continue; }
rule.id = 0;
}
sessionRegexCount = regexCount - dynamicRegexCount;
const sessionRegexCount = regexCount - dynamicRegexCount;
const addRules = addRulesUnfiltered.filter(a => a.id !== 0);
const rejectedRuleCount = addRulesUnfiltered.length - addRules.length;
if ( rejectedRuleCount !== 0 ) {