Skip to content

Commit

Permalink
First lookup matching stock lists when importing URLs
Browse files Browse the repository at this point in the history
Related discussion:
MasterKia/PersianBlocker#224
  • Loading branch information
gorhill committed Feb 29, 2024
1 parent b0067b7 commit 2b16a10
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/js/3p-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,35 @@ dom.on('#lists', 'click', 'span.cache', onPurgeClicked);
/******************************************************************************/

const selectFilterLists = async ( ) => {
// External filter lists to import
// Find stock list matching entries in lists to import
const toImport = (( ) => {
const textarea = qs$('#lists .listEntry[data-role="import"].expanded textarea');
if ( textarea === null ) { return ''; }
const lists = listsetDetails.available;
const lines = textarea.value.split(/\s+\n|\s+/);
const after = [];
for ( const line of lines ) {
if ( /^https?:\/\//.test(line) === false ) { continue; }
for ( const [ listkey, list ] of Object.entries(lists) ) {
if ( list.content !== 'filters' ) { continue; }
if ( list.contentURL === undefined ) { continue; }
if ( list.contentURL.includes(line) === false ) {
after.push(line);
continue;
}
const input = qs$(`[data-key="${list.group}"] [data-key="${listkey}"] > .detailbar input`);
if ( input === null ) { break; }
input.checked = true;
toggleFilterList(input, true, true);
break;
}
}
dom.cl.remove(textarea.closest('.expandable'), 'expanded');
textarea.value = '';
return after.join('\n');
})();

// Cosmetic filtering switch
let checked = qs$('#parseCosmeticFilters').checked;
vAPI.messaging.send('dashboard', {
Expand Down Expand Up @@ -569,14 +598,6 @@ const selectFilterLists = async ( ) => {
}
}

// External filter lists to import
const textarea = qs$('#lists .listEntry[data-role="import"].expanded textarea');
const toImport = textarea !== null && textarea.value.trim() || '';
if ( textarea !== null ) {
dom.cl.remove(textarea.closest('.expandable'), 'expanded');
textarea.value = '';
}

hashFromListsetDetails();

await vAPI.messaging.send('dashboard', {
Expand Down

0 comments on commit 2b16a10

Please sign in to comment.