uBlock/src/js/3p-filters.js

694 lines
24 KiB
JavaScript
Raw Normal View History

2014-06-24 00:42:43 +02:00
/*******************************************************************************
2016-03-06 16:51:06 +01:00
uBlock Origin - a browser extension to block requests.
Copyright (C) 2014-2018 Raymond Hill
2014-06-24 00:42:43 +02:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
Home: https://github.com/gorhill/uBlock
*/
2016-03-06 16:51:06 +01:00
/* global uDom */
2014-06-24 00:42:43 +02:00
'use strict';
2014-06-24 00:42:43 +02:00
/******************************************************************************/
(function() {
/******************************************************************************/
var listDetails = {},
filteringSettingsHash = '',
2017-01-23 23:16:37 +01:00
lastUpdateTemplateString = vAPI.i18n('3pLastUpdate'),
reValidExternalList = /[a-z-]+:\/\/\S*\/\S+/,
hideUnusedSet = new Set();
2014-09-09 01:45:22 +02:00
2014-06-24 00:42:43 +02:00
/******************************************************************************/
var onMessage = function(msg) {
switch ( msg.what ) {
case 'assetUpdated':
updateAssetStatus(msg);
break;
case 'assetsUpdated':
document.body.classList.remove('updating');
renderWidgets();
break;
2016-09-24 20:36:08 +02:00
case 'staticFilteringDataChanged':
2015-04-17 16:20:45 +02:00
renderFilterLists();
break;
default:
break;
2014-06-24 00:42:43 +02:00
}
};
2016-03-06 16:51:06 +01:00
var messaging = vAPI.messaging;
messaging.addChannelListener('dashboard', onMessage);
2014-06-24 00:42:43 +02:00
/******************************************************************************/
2014-07-09 22:03:25 +02:00
var renderNumber = function(value) {
return value.toLocaleString();
2014-07-09 22:03:25 +02:00
};
2014-06-24 00:42:43 +02:00
/******************************************************************************/
2017-01-22 22:05:16 +01:00
var renderFilterLists = function(soft) {
var listGroupTemplate = uDom('#templates .groupEntry'),
listEntryTemplate = uDom('#templates .listEntry'),
listStatsTemplate = vAPI.i18n('3pListsOfBlockedHostsPerListStats'),
renderElapsedTimeToString = vAPI.i18n.renderElapsedTimeToString,
groupNames = new Map();
2015-03-08 22:54:08 +01:00
// Assemble a pretty list name if possible
var listNameFromListKey = function(listKey) {
var list = listDetails.current[listKey] || listDetails.available[listKey];
var listTitle = list ? list.title : '';
if ( listTitle === '' ) { return listKey; }
return listTitle;
2014-08-23 18:08:02 +02:00
};
var liFromListEntry = function(listKey, li, hideUnused) {
var entry = listDetails.available[listKey],
elem;
if ( !li ) {
li = listEntryTemplate.clone().nodeAt(0);
2015-06-10 17:30:57 +02:00
}
var on = entry.off !== true;
if ( li.getAttribute('data-listkey') !== listKey ) {
li.setAttribute('data-listkey', listKey);
elem = li.querySelector('input[type="checkbox"]');
elem.checked = on;
elem = li.querySelector('a:nth-of-type(1)');
elem.setAttribute('href', 'asset-viewer.html?url=' + encodeURI(listKey));
elem.setAttribute('type', 'text/html');
elem.textContent = listNameFromListKey(listKey);
2017-01-24 14:23:52 +01:00
li.classList.remove('toRemove');
if ( entry.supportName ) {
2017-01-22 22:05:16 +01:00
li.classList.add('support');
elem = li.querySelector('a.support');
elem.setAttribute('href', entry.supportURL);
2017-01-22 22:05:16 +01:00
elem.setAttribute('title', entry.supportName);
} else {
li.classList.remove('support');
}
if ( entry.external ) {
li.classList.add('external');
} else {
li.classList.remove('external');
}
if ( entry.instructionURL ) {
li.classList.add('mustread');
elem = li.querySelector('a.mustread');
elem.setAttribute('href', entry.instructionURL);
} else {
2017-01-22 22:05:16 +01:00
li.classList.remove('mustread');
}
li.classList.toggle('unused', hideUnused && !on);
2014-09-09 16:53:47 +02:00
}
2017-01-22 22:05:16 +01:00
// https://github.com/gorhill/uBlock/issues/1429
if ( !soft ) {
li.querySelector('input[type="checkbox"]').checked = on;
2017-01-22 22:05:16 +01:00
}
elem = li.querySelector('span.counts');
2017-01-22 22:05:16 +01:00
var text = '';
if ( !isNaN(+entry.entryUsedCount) && !isNaN(+entry.entryCount) ) {
text = listStatsTemplate
.replace('{{used}}', renderNumber(on ? entry.entryUsedCount : 0))
2017-01-22 22:05:16 +01:00
.replace('{{total}}', renderNumber(entry.entryCount));
}
elem.textContent = text;
2015-04-07 03:26:05 +02:00
// https://github.com/chrisaljoudi/uBlock/issues/104
2015-03-08 22:54:08 +01:00
var asset = listDetails.cache[listKey] || {};
var remoteURL = asset.remoteURL;
li.classList.toggle(
'unsecure',
typeof remoteURL === 'string' && remoteURL.lastIndexOf('http:', 0) === 0
);
2017-01-22 22:05:16 +01:00
li.classList.toggle('failed', asset.error !== undefined);
li.classList.toggle('obsolete', asset.obsolete === true);
if ( asset.cached === true ) {
li.classList.add('cached');
2017-01-22 22:05:16 +01:00
li.querySelector('.status.cache').setAttribute(
'title',
lastUpdateTemplateString.replace(
'{{ago}}',
renderElapsedTimeToString(asset.writeTime)
)
);
} else {
li.classList.remove('cached');
2014-09-09 16:53:47 +02:00
}
li.classList.remove('discard');
2015-03-08 22:54:08 +01:00
return li;
2014-09-09 16:53:47 +02:00
};
2015-03-23 15:19:43 +01:00
var listEntryCountFromGroup = function(listKeys) {
if ( Array.isArray(listKeys) === false ) { return ''; }
var count = 0,
total = 0;
2015-03-23 15:19:43 +01:00
var i = listKeys.length;
while ( i-- ) {
if ( listDetails.available[listKeys[i]].off !== true ) {
count += 1;
}
total += 1;
2015-03-23 15:19:43 +01:00
}
return total !== 0 ?
'(' + count.toLocaleString() + '/' + total.toLocaleString() + ')' :
'';
2015-03-23 15:19:43 +01:00
};
2015-03-08 22:54:08 +01:00
var liFromListGroup = function(groupKey, listKeys) {
var liGroup = document.querySelector('#lists > .groupEntry[data-groupkey="' + groupKey + '"]');
if ( liGroup === null ) {
liGroup = listGroupTemplate.clone().nodeAt(0);
var groupName = groupNames.get(groupKey);
if ( groupName === undefined ) {
groupName = vAPI.i18n('3pGroup' + groupKey.charAt(0).toUpperCase() + groupKey.slice(1));
// Category "Social" is being renamed "Annoyances": ensure
// smooth transition.
// TODO: remove when majority of users are post-1.14.8 uBO.
if ( groupName === '' && groupKey === 'social' ) {
groupName = vAPI.i18n('3pGroupAnnoyances');
}
groupNames.set(groupKey, groupName);
}
if ( groupName !== '' ) {
liGroup.querySelector('.geName').textContent = groupName;
}
2015-03-23 15:19:43 +01:00
}
if ( liGroup.querySelector('.geName:empty') === null ) {
liGroup.querySelector('.geCount').textContent = listEntryCountFromGroup(listKeys);
2014-07-25 22:12:20 +02:00
}
var hideUnused = mustHideUnusedLists(groupKey);
liGroup.classList.toggle('hideUnused', hideUnused);
var ulGroup = liGroup.querySelector('.listEntries');
if ( !listKeys ) { return liGroup; }
2014-07-25 22:12:20 +02:00
listKeys.sort(function(a, b) {
2015-03-23 15:19:43 +01:00
return (listDetails.available[a].title || '').localeCompare(listDetails.available[b].title || '');
2014-07-25 22:12:20 +02:00
});
for ( var i = 0; i < listKeys.length; i++ ) {
var liEntry = liFromListEntry(
listKeys[i],
ulGroup.children[i],
hideUnused
);
if ( liEntry.parentElement === null ) {
ulGroup.appendChild(liEntry);
}
}
2015-03-08 22:54:08 +01:00
return liGroup;
};
var groupsFromLists = function(lists) {
var groups = {};
var listKeys = Object.keys(lists);
var i = listKeys.length;
var listKey, list, groupKey;
while ( i-- ) {
listKey = listKeys[i];
list = lists[listKey];
groupKey = list.group || 'nogroup';
if ( groups[groupKey] === undefined ) {
groups[groupKey] = [];
}
groups[groupKey].push(listKey);
}
return groups;
};
2014-07-25 22:12:20 +02:00
var onListsReceived = function(details) {
2014-09-09 16:53:47 +02:00
// Before all, set context vars
2014-07-25 22:12:20 +02:00
listDetails = details;
// Incremental rendering: this will allow us to easily discard unused
// DOM list entries.
uDom('#lists .listEntries .listEntry[data-listkey]').addClass('discard');
// Remove import widget while we recreate list of lists.
var importWidget = uDom('.listEntry.toImport').detach();
2014-07-25 22:12:20 +02:00
2014-09-09 16:53:47 +02:00
// Visually split the filter lists in purpose-based groups
var ulLists = document.querySelector('#lists'),
groups = groupsFromLists(details.available),
liGroup, i, groupKey,
groupKeys = [
2017-05-19 00:55:03 +02:00
'default',
'ads',
'privacy',
'malware',
'social',
'multipurpose',
'regions',
'custom'
];
document.body.classList.toggle('hideUnused', mustHideUnusedLists('*'));
2014-07-25 22:12:20 +02:00
for ( i = 0; i < groupKeys.length; i++ ) {
groupKey = groupKeys[i];
2015-03-14 19:12:05 +01:00
liGroup = liFromListGroup(groupKey, groups[groupKey]);
liGroup.setAttribute('data-groupkey', groupKey);
liGroup.classList.toggle(
2015-03-14 19:12:05 +01:00
'collapsed',
vAPI.localStorage.getItem('collapseGroup' + (i + 1)) === 'y'
);
if ( liGroup.parentElement === null ) {
ulLists.appendChild(liGroup);
}
2014-07-25 22:12:20 +02:00
delete groups[groupKey];
}
// For all groups not covered above (if any left)
groupKeys = Object.keys(groups);
for ( i = 0; i < groupKeys.length; i++ ) {
groupKey = groupKeys[i];
ulLists.appendChild(liFromListGroup(groupKey, groups[groupKey]));
2014-07-25 22:12:20 +02:00
}
uDom('#lists .listEntries .listEntry.discard').remove();
// Re-insert import widget.
uDom('[data-groupkey="custom"] .listEntries').append(importWidget);
uDom.nodeFromId('autoUpdate').checked = listDetails.autoUpdate === true;
uDom.nodeFromId('listsOfBlockedHostsPrompt').textContent =
vAPI.i18n('3pListsOfBlockedHostsPrompt')
.replace(
'{{netFilterCount}}',
renderNumber(details.netFilterCount)
)
.replace(
'{{cosmeticFilterCount}}',
renderNumber(details.cosmeticFilterCount)
);
uDom.nodeFromId('parseCosmeticFilters').checked =
listDetails.parseCosmeticFilters === true;
uDom.nodeFromId('ignoreGenericCosmeticFilters').checked =
listDetails.ignoreGenericCosmeticFilters === true;
// Compute a hash of the settings so that we can keep track of changes
// affecting the loading of filter lists.
2017-01-22 22:05:16 +01:00
if ( !soft ) {
filteringSettingsHash = hashFromCurrentFromSettings();
}
2015-03-11 04:46:18 +01:00
renderWidgets();
2014-07-25 22:12:20 +02:00
};
2014-06-24 00:42:43 +02:00
2016-03-06 16:51:06 +01:00
messaging.send('dashboard', { what: 'getLists' }, onListsReceived);
2014-07-09 22:03:25 +02:00
};
2014-06-24 00:42:43 +02:00
/******************************************************************************/
var renderWidgets = function() {
uDom('#buttonApply').toggleClass(
'disabled',
filteringSettingsHash === hashFromCurrentFromSettings()
);
uDom('#buttonPurgeAll').toggleClass(
'disabled',
document.querySelector('#lists .listEntry.cached:not(.obsolete)') === null
);
uDom('#buttonUpdate').toggleClass(
'disabled',
document.querySelector('body:not(.updating) #lists .listEntry.obsolete > input[type="checkbox"]:checked') === null
);
2015-03-11 04:46:18 +01:00
};
/******************************************************************************/
var updateAssetStatus = function(details) {
2017-01-22 22:05:16 +01:00
var li = document.querySelector('#lists .listEntry[data-listkey="' + details.key + '"]');
if ( li === null ) { return; }
li.classList.toggle('failed', !!details.failed);
li.classList.toggle('obsolete', !details.cached);
li.classList.toggle('cached', !!details.cached);
if ( details.cached ) {
li.querySelector('.status.cache').setAttribute(
'title',
lastUpdateTemplateString.replace(
'{{ago}}',
vAPI.i18n.renderElapsedTimeToString(Date.now())
)
);
}
renderWidgets();
2015-03-11 04:46:18 +01:00
};
/*******************************************************************************
2015-03-11 04:46:18 +01:00
Compute a hash from all the settings affecting how filter lists are loaded
in memory.
2014-06-24 00:42:43 +02:00
**/
2015-03-11 04:46:18 +01:00
var hashFromCurrentFromSettings = function() {
var hash = [
uDom.nodeFromId('parseCosmeticFilters').checked,
uDom.nodeFromId('ignoreGenericCosmeticFilters').checked
];
var listHash = [],
2017-01-22 22:05:16 +01:00
listEntries = document.querySelectorAll('#lists .listEntry[data-listkey]:not(.toRemove)'),
liEntry,
i = listEntries.length;
while ( i-- ) {
liEntry = listEntries[i];
if ( liEntry.querySelector('input[type="checkbox"]:checked') !== null ) {
listHash.push(liEntry.getAttribute('data-listkey'));
}
}
2017-01-23 23:16:37 +01:00
hash.push(
listHash.sort().join(),
uDom.nodeFromId('importLists').checked &&
reValidExternalList.test(uDom.nodeFromId('externalLists').value),
2017-01-23 23:16:37 +01:00
document.querySelector('#lists .listEntry.toRemove') !== null
);
2017-01-22 22:05:16 +01:00
return hash.join();
};
/******************************************************************************/
var onFilteringSettingsChanged = function() {
2015-03-11 04:46:18 +01:00
renderWidgets();
2014-07-09 22:03:25 +02:00
};
2014-06-24 00:42:43 +02:00
/******************************************************************************/
2017-01-22 22:05:16 +01:00
var onRemoveExternalList = function(ev) {
var liEntry = uDom(this).ancestors('[data-listkey]'),
listKey = liEntry.attr('data-listkey');
if ( listKey ) {
liEntry.toggleClass('toRemove');
renderWidgets();
}
ev.preventDefault();
};
/******************************************************************************/
2014-08-20 05:01:36 +02:00
var onPurgeClicked = function() {
var button = uDom(this),
liEntry = button.ancestors('[data-listkey]'),
listKey = liEntry.attr('data-listkey');
if ( !listKey ) { return; }
messaging.send('dashboard', { what: 'purgeCache', assetKey: listKey });
// If the cached version is purged, the installed version must be assumed
// to be obsolete.
2016-06-19 19:26:02 +02:00
// https://github.com/gorhill/uBlock/issues/1733
2017-01-22 22:05:16 +01:00
// An external filter list must not be marked as obsolete, they will
// always be fetched anyways if there is no cached copy.
liEntry.addClass('obsolete');
liEntry.removeClass('cached');
if ( liEntry.descendants('input').first().prop('checked') ) {
2015-03-11 04:46:18 +01:00
renderWidgets();
}
2014-07-26 22:10:20 +02:00
};
/******************************************************************************/
2015-03-11 04:46:18 +01:00
var selectFilterLists = function(callback) {
// Cosmetic filtering switch
2016-08-13 22:42:58 +02:00
messaging.send('dashboard', {
what: 'userSettings',
name: 'parseAllABPHideFilters',
value: document.getElementById('parseCosmeticFilters').checked
2016-08-13 22:42:58 +02:00
});
messaging.send('dashboard', {
what: 'userSettings',
name: 'ignoreGenericCosmeticFilters',
value: document.getElementById('ignoreGenericCosmeticFilters').checked
2016-08-13 22:42:58 +02:00
});
2015-03-11 04:46:18 +01:00
2017-01-22 22:05:16 +01:00
// Filter lists to select
var toSelect = [],
liEntries = document.querySelectorAll('#lists .listEntry[data-listkey]:not(.toRemove)'),
i = liEntries.length,
liEntry;
2014-06-24 00:42:43 +02:00
while ( i-- ) {
liEntry = liEntries[i];
if ( liEntry.querySelector('input[type="checkbox"]:checked') !== null ) {
2017-01-22 22:05:16 +01:00
toSelect.push(liEntry.getAttribute('data-listkey'));
}
2014-06-24 00:42:43 +02:00
}
2015-03-11 04:46:18 +01:00
2017-01-22 22:05:16 +01:00
// External filter lists to remove
var toRemove = [];
liEntries = document.querySelectorAll('#lists .listEntry.toRemove[data-listkey]');
i = liEntries.length;
while ( i-- ) {
toRemove.push(liEntries[i].getAttribute('data-listkey'));
}
// External filter lists to import
var externalListsElem = document.getElementById('externalLists'),
toImport = externalListsElem.value.trim();
externalListsElem.value = '';
uDom.nodeFromId('importLists').checked = false;
2017-01-22 22:05:16 +01:00
2016-03-06 16:51:06 +01:00
messaging.send(
'dashboard',
2017-01-22 22:05:16 +01:00
{
what: 'applyFilterListSelection',
toSelect: toSelect,
toImport: toImport,
toRemove: toRemove
},
2016-03-06 16:51:06 +01:00
callback
);
filteringSettingsHash = hashFromCurrentFromSettings();
};
/******************************************************************************/
var buttonApplyHandler = function() {
uDom('#buttonApply').removeClass('enabled');
2015-03-11 04:46:18 +01:00
var onSelectionDone = function() {
2016-03-06 16:51:06 +01:00
messaging.send('dashboard', { what: 'reloadAllFilters' });
2015-03-11 04:46:18 +01:00
};
selectFilterLists(onSelectionDone);
renderWidgets();
};
/******************************************************************************/
var buttonUpdateHandler = function() {
var onSelectionDone = function() {
document.body.classList.add('updating');
messaging.send('dashboard', { what: 'forceUpdateAssets' });
2017-01-22 22:05:16 +01:00
renderWidgets();
};
selectFilterLists(onSelectionDone);
renderWidgets();
};
/******************************************************************************/
var buttonPurgeAllHandler = function(ev) {
uDom('#buttonPurgeAll').removeClass('enabled');
messaging.send(
'dashboard',
{
what: 'purgeAllCaches',
hard: ev.ctrlKey && ev.shiftKey
},
2017-01-22 22:05:16 +01:00
function() { renderFilterLists(true); }
);
2014-09-09 01:45:22 +02:00
};
/******************************************************************************/
var autoUpdateCheckboxChanged = function() {
2016-03-06 16:51:06 +01:00
messaging.send(
'dashboard',
{
what: 'userSettings',
name: 'autoUpdate',
value: this.checked
}
);
2014-07-09 22:03:25 +02:00
};
2014-06-24 00:42:43 +02:00
/******************************************************************************/
// Collapsing of unused lists.
2014-06-24 00:42:43 +02:00
var mustHideUnusedLists = function(which) {
var hideAll = hideUnusedSet.has('*');
if ( which === '*' ) { return hideAll; }
return hideUnusedSet.has(which) !== hideAll;
};
2014-06-24 00:42:43 +02:00
var toggleHideUnusedLists = function(which) {
var groupSelector,
doesHideAll = hideUnusedSet.has('*'),
mustHide;
if ( which === '*' ) {
mustHide = doesHideAll === false;
groupSelector = '';
hideUnusedSet.clear();
if ( mustHide ) {
hideUnusedSet.add(which);
}
document.body.classList.toggle('hideUnused', mustHide);
uDom('.groupEntry[data-groupkey]').toggleClass('hideUnused', mustHide);
2015-03-14 19:12:05 +01:00
} else {
var doesHide = hideUnusedSet.has(which);
if ( doesHide ) {
hideUnusedSet.delete(which);
} else {
hideUnusedSet.add(which);
}
mustHide = doesHide === doesHideAll;
groupSelector = '.groupEntry[data-groupkey="' + which + '"] ';
uDom(groupSelector).toggleClass('hideUnused', mustHide);
2015-03-14 19:12:05 +01:00
}
uDom(groupSelector + '.listEntry > input[type="checkbox"]:not(:checked)')
.ancestors('.listEntry[data-listkey]')
.toggleClass('unused', mustHide);
vAPI.localStorage.setItem(
'hideUnusedFilterLists',
JSON.stringify(Array.from(hideUnusedSet))
);
};
var revealHiddenUsedLists = function() {
uDom('#lists .listEntry.unused > input[type="checkbox"]:checked')
.ancestors('.listEntry[data-listkey]')
.removeClass('unused');
2015-03-14 19:12:05 +01:00
};
uDom('#listsOfBlockedHostsPrompt').on('click', function() {
toggleHideUnusedLists('*');
});
uDom('#lists').on('click', '.groupEntry[data-groupkey] > .geDetails', function(ev) {
toggleHideUnusedLists(
uDom(ev.target)
.ancestors('.groupEntry[data-groupkey]')
.attr('data-groupkey')
);
});
(function() {
var aa;
try {
var json = vAPI.localStorage.getItem('hideUnusedFilterLists');
if ( json !== null ) {
aa = JSON.parse(json);
}
} catch (ex) {
}
if ( Array.isArray(aa) === false ) {
aa = [ '*' ];
}
hideUnusedSet = new Set(aa);
})();
2015-03-14 19:12:05 +01:00
/******************************************************************************/
// Cloud-related.
var toCloudData = function() {
2015-08-11 21:29:14 +02:00
var bin = {
parseCosmeticFilters: uDom.nodeFromId('parseCosmeticFilters').checked,
2016-08-13 22:42:58 +02:00
ignoreGenericCosmeticFilters: uDom.nodeFromId('ignoreGenericCosmeticFilters').checked,
selectedLists: []
2015-08-11 21:29:14 +02:00
};
2014-06-24 00:42:43 +02:00
var liEntries = uDom('#lists .listEntry'), liEntry;
var i = liEntries.length;
2015-08-11 21:29:14 +02:00
while ( i-- ) {
liEntry = liEntries.at(i);
if ( liEntry.descendants('input').prop('checked') ) {
bin.selectedLists.push(liEntry.attr('data-listkey'));
2015-08-11 21:29:14 +02:00
}
}
return bin;
};
var fromCloudData = function(data, append) {
if ( typeof data !== 'object' || data === null ) { return; }
2015-08-11 21:29:14 +02:00
var elem, checked;
2015-08-11 21:29:14 +02:00
2016-01-08 17:08:53 +01:00
elem = uDom.nodeFromId('parseCosmeticFilters');
2016-08-13 22:42:58 +02:00
checked = data.parseCosmeticFilters === true || append && elem.checked;
elem.checked = listDetails.parseCosmeticFilters = checked;
elem = uDom.nodeFromId('ignoreGenericCosmeticFilters');
checked = data.ignoreGenericCosmeticFilters === true || append && elem.checked;
elem.checked = listDetails.ignoreGenericCosmeticFilters = checked;
2016-01-08 17:08:53 +01:00
var selectedSet = new Set(data.selectedLists),
listEntries = uDom('#lists .listEntry'),
listEntry, listKey;
for ( var i = 0, n = listEntries.length; i < n; i++ ) {
listEntry = listEntries.at(i);
listKey = listEntry.attr('data-listkey');
var hasListKey = selectedSet.has(listKey);
selectedSet.delete(listKey);
var input = listEntry.descendants('input').first();
if ( append && input.prop('checked') ) { continue; }
input.prop('checked', hasListKey);
2015-08-11 21:29:14 +02:00
}
// If there are URL-like list keys left in the selected set, import them.
for ( listKey of selectedSet ) {
if ( reValidExternalList.test(listKey) === false ) {
selectedSet.delete(listKey);
}
}
if ( selectedSet.size !== 0 ) {
elem = uDom.nodeFromId('externalLists');
if ( append ) {
if ( elem.value.trim() !== '' ) { elem.value += '\n'; }
} else {
elem.value = '';
}
elem.value += Array.from(selectedSet).join('\n');
uDom.nodeFromId('importLists').checked = true;
}
2015-08-11 21:29:14 +02:00
revealHiddenUsedLists();
2015-08-11 21:29:14 +02:00
renderWidgets();
};
self.cloud.onPush = toCloudData;
self.cloud.onPull = fromCloudData;
2015-08-11 21:29:14 +02:00
/******************************************************************************/
uDom('#autoUpdate').on('change', autoUpdateCheckboxChanged);
uDom('#parseCosmeticFilters').on('change', onFilteringSettingsChanged);
uDom('#ignoreGenericCosmeticFilters').on('change', onFilteringSettingsChanged);
2015-08-11 21:29:14 +02:00
uDom('#buttonApply').on('click', buttonApplyHandler);
uDom('#buttonUpdate').on('click', buttonUpdateHandler);
uDom('#buttonPurgeAll').on('click', buttonPurgeAllHandler);
2017-01-22 22:05:16 +01:00
uDom('#lists').on('change', '.listEntry > input', onFilteringSettingsChanged);
uDom('#lists').on('click', '.listEntry > a.remove', onRemoveExternalList);
uDom('#lists').on('click', 'span.cache', onPurgeClicked);
uDom('#externalLists').on('input', onFilteringSettingsChanged);
2015-08-11 21:29:14 +02:00
/******************************************************************************/
2017-01-22 22:05:16 +01:00
renderFilterLists();
2014-06-24 00:42:43 +02:00
/******************************************************************************/
})();