Add concept of "preferred" lists

Preferred lists will be visually listed above other lists.
This commit is contained in:
Raymond Hill 2024-03-19 11:51:03 -04:00
parent 7e48a03927
commit 61e916901b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 23 additions and 5 deletions

View File

@ -155,6 +155,7 @@
"group": "ads",
"title": "EasyList",
"tags": "ads",
"preferred": true,
"contentURL": [
"https://ublockorigin.github.io/uAssets/thirdparties/easylist.txt",
"assets/thirdparties/easylist/easylist.txt"
@ -205,6 +206,7 @@
"group": "privacy",
"title": "EasyPrivacy",
"tags": "privacy",
"preferred": true,
"contentURL": [
"https://ublockorigin.github.io/uAssets/thirdparties/easyprivacy.txt",
"assets/thirdparties/easylist/easyprivacy.txt"
@ -281,6 +283,7 @@
"off": true,
"title": "EasyList Cookie Notices",
"tags": "annoyances cookies",
"preferred": true,
"contentURL": [
"https://ublockorigin.github.io/uAssets/thirdparties/easylist-cookies.txt",
"https://secure.fanboy.co.nz/fanboy-cookiemonster_ubo.txt"
@ -302,6 +305,7 @@
"off": true,
"title": "uBlock filters Cookie Notices",
"tags": "annoyances cookies",
"preferred": true,
"contentURL": "https://ublockorigin.github.io/uAssets/filters/annoyances-cookies.txt",
"cdnURLs": [
"https://ublockorigin.github.io/uAssetsCDN/filters/annoyances-cookies.txt",
@ -331,6 +335,7 @@
"off": true,
"title": "EasyList Social Widgets",
"tags": "annoyances social",
"preferred": true,
"contentURL": [
"https://ublockorigin.github.io/uAssets/thirdparties/easylist-social.txt",
"https://secure.fanboy.co.nz/fanboy-social_ubo.txt"
@ -405,6 +410,7 @@
"off": true,
"title": "EasyList Other Annoyances",
"tags": "annoyances",
"preferred": true,
"contentURL": "https://ublockorigin.github.io/uAssets/thirdparties/easylist-annoyances.txt",
"cdnURLs": [
"https://ublockorigin.github.io/uAssetsCDN/thirdparties/easylist-annoyances.txt",
@ -421,6 +427,7 @@
"off": true,
"title": "EasyList Chat Widgets",
"tags": "annoyances",
"preferred": true,
"contentURL": "https://ublockorigin.github.io/uAssets/thirdparties/easylist-chat.txt",
"cdnURLs": [
"https://ublockorigin.github.io/uAssetsCDN/thirdparties/easylist-chat.txt",
@ -437,6 +444,7 @@
"off": true,
"title": "EasyList Newsletter Notices",
"tags": "annoyances",
"preferred": true,
"contentURL": [
"https://ublockorigin.github.io/uAssets/thirdparties/easylist-newsletters.txt"
],
@ -455,6 +463,7 @@
"off": true,
"title": "EasyList Notifications",
"tags": "annoyances",
"preferred": true,
"contentURL": [
"https://ublockorigin.github.io/uAssets/thirdparties/easylist-notifications.txt"
],
@ -497,6 +506,7 @@
"updateAfter": 13,
"title": "Peter Lowes Ad and tracking server list",
"tags": "ads privacy security",
"preferred": true,
"contentURL": [
"https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=1&mimetype=plaintext",
"assets/thirdparties/pgl.yoyo.org/as/serverlist.txt",

View File

@ -19,11 +19,9 @@
Home: https://github.com/gorhill/uBlock
*/
'use strict';
import { onBroadcast } from './broadcast.js';
import { dom, qs$, qsa$ } from './dom.js';
import { i18n, i18n$ } from './i18n.js';
import { onBroadcast } from './broadcast.js';
/******************************************************************************/
@ -32,6 +30,10 @@ const obsoleteTemplateString = i18n$('3pExternalListObsolete');
const reValidExternalList = /^[a-z-]+:\/\/(?:\S+\/\S*|\/\S+)/m;
const recentlyUpdated = 1 * 60 * 60 * 1000; // 1 hour
// https://eslint.org/docs/latest/rules/no-prototype-builtins
const hasOwnProperty = (o, p) =>
Object.prototype.hasOwnProperty.call(o, p);
let listsetDetails = {};
/******************************************************************************/
@ -182,6 +184,9 @@ const renderFilterLists = ( ) => {
if ( depth !== 0 ) {
const reEmojis = /\p{Emoji}+/gu;
treeEntries.sort((a ,b) => {
const ap = a[1].preferred === true;
const bp = b[1].preferred === true;
if ( ap !== bp ) { return ap ? -1 : 1; }
const as = (a[1].title || a[0]).replace(reEmojis, '');
const bs = (b[1].title || b[0]).replace(reEmojis, '');
return as.localeCompare(bs);
@ -241,7 +246,7 @@ const renderFilterLists = ( ) => {
}
for ( const [ listkey, listDetails ] of Object.entries(response.available) ) {
let groupkey = listDetails.group2 || listDetails.group;
if ( listTree.hasOwnProperty(groupkey) === false ) {
if ( hasOwnProperty(listTree, groupkey) === false ) {
groupkey = 'unknown';
}
const groupDetails = listTree[groupkey];
@ -251,6 +256,9 @@ const renderFilterLists = ( ) => {
if ( lists[parent] === undefined ) {
lists[parent] = { title: parent, lists: {} };
}
if ( listDetails.preferred === true ) {
lists[parent].preferred = true;
}
lists = lists[parent].lists;
}
lists[listkey] = listDetails;
@ -596,7 +604,7 @@ const selectFilterLists = async ( ) => {
const toRemove = [];
for ( const liEntry of qsa$('#lists .listEntry[data-role="leaf"]') ) {
const listkey = liEntry.dataset.key;
if ( listsetDetails.available.hasOwnProperty(listkey) === false ) {
if ( hasOwnProperty(listsetDetails.available, listkey) === false ) {
continue;
}
const listDetails = listsetDetails.available[listkey];