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:
parent
f9ce06977d
commit
114acacd2e
@ -130,7 +130,9 @@ export function renderFilterLists(rulesetData) {
|
|||||||
|
|
||||||
const initializeListEntry = (ruleset, listEntry) => {
|
const initializeListEntry = (ruleset, listEntry) => {
|
||||||
const on = enabledRulesets.includes(ruleset.id);
|
const on = enabledRulesets.includes(ruleset.id);
|
||||||
dom.prop(qs$(listEntry, ':scope > .detailbar input'), 'checked', on);
|
if ( dom.cl.has(listEntry, 'toggled') === false ) {
|
||||||
|
dom.prop(qs$(listEntry, ':scope > .detailbar input'), 'checked', on);
|
||||||
|
}
|
||||||
if ( ruleset.homeURL ) {
|
if ( ruleset.homeURL ) {
|
||||||
dom.attr(qs$(listEntry, 'a.support'), 'href', ruleset.homeURL);
|
dom.attr(qs$(listEntry, 'a.support'), 'href', ruleset.homeURL);
|
||||||
}
|
}
|
||||||
@ -360,6 +362,7 @@ const searchFilterLists = ( ) => {
|
|||||||
haystack = [
|
haystack = [
|
||||||
rulesetDetails.name,
|
rulesetDetails.name,
|
||||||
listEntry.dataset.nodeid,
|
listEntry.dataset.nodeid,
|
||||||
|
rulesetDetails.group || '',
|
||||||
rulesetDetails.tags || '',
|
rulesetDetails.tags || '',
|
||||||
].join(' ').trim();
|
].join(' ').trim();
|
||||||
perListHaystack.set(rulesetDetails, haystack);
|
perListHaystack.set(rulesetDetails, haystack);
|
||||||
@ -379,34 +382,60 @@ dom.on('#findInLists', 'input', searchFilterLists);
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
async function applyEnabledRulesets() {
|
const applyEnabledRulesets = (( ) => {
|
||||||
const enabledRulesets = [];
|
const apply = async ( ) => {
|
||||||
for ( const liEntry of qsa$('#lists .listEntry[data-role="leaf"][data-rulesetid]') ) {
|
const enabledRulesets = [];
|
||||||
const checked = qs$(liEntry, 'input[type="checkbox"]:checked') !== null;
|
for ( const liEntry of qsa$('#lists .listEntry[data-role="leaf"][data-rulesetid]') ) {
|
||||||
if ( checked === false ) { continue; }
|
const checked = qs$(liEntry, 'input[type="checkbox"]:checked') !== null;
|
||||||
const { rulesetid } = liEntry.dataset;
|
if ( checked === false ) { continue; }
|
||||||
if ( dom.cl.has(liEntry, 'fromAdmin') ) { continue; }
|
const { rulesetid } = liEntry.dataset;
|
||||||
enabledRulesets.push(rulesetid);
|
if ( dom.cl.has(liEntry, 'fromAdmin') ) { continue; }
|
||||||
}
|
enabledRulesets.push(rulesetid);
|
||||||
|
}
|
||||||
|
|
||||||
if ( enabledRulesets.length === 0 ) { return; }
|
dom.cl.remove('#lists .listEntry.toggled', 'toggled');
|
||||||
|
|
||||||
await sendMessage({
|
if ( enabledRulesets.length === 0 ) { return; }
|
||||||
what: 'applyRulesets',
|
|
||||||
enabledRulesets,
|
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 => {
|
dom.on('#lists', 'change', '.listEntry input[type="checkbox"]', ev => {
|
||||||
const input = ev.target;
|
const input = ev.target;
|
||||||
const listEntry = input.closest('.listEntry');
|
const listEntry = input.closest('.listEntry');
|
||||||
if ( listEntry === null ) { return; }
|
if ( listEntry === null ) { return; }
|
||||||
if ( listEntry.dataset.nodeid !== undefined ) {
|
if ( listEntry.dataset.nodeid !== undefined ) {
|
||||||
let checkAll = input.checked ||
|
const checkAll = input.checked ||
|
||||||
dom.cl.has(qs$(listEntry, ':scope > .detailbar .checkbox'), 'partial');
|
dom.cl.has(qs$(listEntry, ':scope > .detailbar .checkbox'), 'partial');
|
||||||
for ( const input of qsa$(listEntry, '.listEntries input') ) {
|
for ( const subListEntry of qsa$(listEntry, ':scope > .listEntries .listEntry[data-rulesetid]') ) {
|
||||||
input.checked = checkAll;
|
dom.cl.add(subListEntry, 'toggled');
|
||||||
|
dom.prop(qsa$(subListEntry, ':scope > .detailbar input'), 'checked', checkAll);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
dom.cl.add(listEntry, 'toggled');
|
||||||
}
|
}
|
||||||
updateNodes();
|
updateNodes();
|
||||||
renderTotalRuleCounts();
|
renderTotalRuleCounts();
|
||||||
|
Loading…
Reference in New Issue
Block a user