1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-21 18:02:34 +01:00

[mv3] Batch changes thru dashboard UI to reduce worker's workload

This commit is contained in:
Raymond Hill 2024-11-18 14:08:30 -05:00
parent f9ce06977d
commit 114acacd2e
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -130,7 +130,9 @@ export function renderFilterLists(rulesetData) {
const initializeListEntry = (ruleset, listEntry) => {
const on = enabledRulesets.includes(ruleset.id);
if ( dom.cl.has(listEntry, 'toggled') === false ) {
dom.prop(qs$(listEntry, ':scope > .detailbar input'), 'checked', on);
}
if ( ruleset.homeURL ) {
dom.attr(qs$(listEntry, 'a.support'), 'href', ruleset.homeURL);
}
@ -360,6 +362,7 @@ const searchFilterLists = ( ) => {
haystack = [
rulesetDetails.name,
listEntry.dataset.nodeid,
rulesetDetails.group || '',
rulesetDetails.tags || '',
].join(' ').trim();
perListHaystack.set(rulesetDetails, haystack);
@ -379,7 +382,8 @@ dom.on('#findInLists', 'input', searchFilterLists);
/******************************************************************************/
async function applyEnabledRulesets() {
const applyEnabledRulesets = (( ) => {
const apply = async ( ) => {
const enabledRulesets = [];
for ( const liEntry of qsa$('#lists .listEntry[data-role="leaf"][data-rulesetid]') ) {
const checked = qs$(liEntry, 'input[type="checkbox"]:checked') !== null;
@ -389,24 +393,49 @@ async function applyEnabledRulesets() {
enabledRulesets.push(rulesetid);
}
dom.cl.remove('#lists .listEntry.toggled', 'toggled');
if ( enabledRulesets.length === 0 ) { return; }
await sendMessage({
what: 'applyRulesets',
enabledRulesets,
});
}
};
let timer;
self.addEventListener('beforeunload', ( ) => {
if ( timer !== undefined ) { return; }
self.clearTimeout(timer);
timer = undefined;
apply();
});
return function() {
if ( timer !== undefined ) {
self.clearTimeout(timer);
}
timer = self.setTimeout(( ) => {
timer = undefined;
apply();
}, 997);
}
})();
dom.on('#lists', 'change', '.listEntry input[type="checkbox"]', ev => {
const input = ev.target;
const listEntry = input.closest('.listEntry');
if ( listEntry === null ) { return; }
if ( listEntry.dataset.nodeid !== undefined ) {
let checkAll = input.checked ||
const checkAll = input.checked ||
dom.cl.has(qs$(listEntry, ':scope > .detailbar .checkbox'), 'partial');
for ( const input of qsa$(listEntry, '.listEntries input') ) {
input.checked = checkAll;
for ( const subListEntry of qsa$(listEntry, ':scope > .listEntries .listEntry[data-rulesetid]') ) {
dom.cl.add(subListEntry, 'toggled');
dom.prop(qsa$(subListEntry, ':scope > .detailbar input'), 'checked', checkAll);
}
} else {
dom.cl.add(listEntry, 'toggled');
}
updateNodes();
renderTotalRuleCounts();