2014-06-24 00:42:43 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
uBlock Origin - a browser extension to block requests.
|
2017-01-18 19:17:47 +01:00
|
|
|
Copyright (C) 2014-2017 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
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
'use strict';
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-07-25 22:12:20 +02:00
|
|
|
var listDetails = {};
|
2016-08-13 22:42:58 +02:00
|
|
|
var parseCosmeticFilters = true;
|
|
|
|
var ignoreGenericCosmeticFilters = false;
|
2017-01-18 19:17:47 +01:00
|
|
|
var selectedListsHashBefore = '';
|
2014-07-25 22:12:20 +02:00
|
|
|
var externalLists = '';
|
2014-09-09 01:45:22 +02:00
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onMessage = function(msg) {
|
|
|
|
switch ( msg.what ) {
|
2017-01-18 19:17:47 +01:00
|
|
|
case 'assetUpdated':
|
|
|
|
updateAssetStatus(msg);
|
|
|
|
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) {
|
2014-07-16 02:32:33 +02:00
|
|
|
return value.toLocaleString();
|
2014-07-09 22:03:25 +02:00
|
|
|
};
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-03-11 04:46:18 +01:00
|
|
|
var renderFilterLists = function() {
|
2017-01-18 19:17:47 +01:00
|
|
|
var listGroupTemplate = uDom('#templates .groupEntry'),
|
|
|
|
listEntryTemplate = uDom('#templates .listEntry'),
|
|
|
|
listStatsTemplate = vAPI.i18n('3pListsOfBlockedHostsPerListStats'),
|
|
|
|
renderElapsedTimeToString = vAPI.i18n.renderElapsedTimeToString,
|
|
|
|
lastUpdateString = vAPI.i18n('3pLastUpdate');
|
2015-03-08 22:54:08 +01:00
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
// Assemble a pretty list name if possible
|
2014-09-26 02:21:21 +02:00
|
|
|
var listNameFromListKey = function(listKey) {
|
|
|
|
var list = listDetails.current[listKey] || listDetails.available[listKey];
|
|
|
|
var listTitle = list ? list.title : '';
|
|
|
|
if ( listTitle === '' ) {
|
|
|
|
return listKey;
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
2014-09-26 02:21:21 +02:00
|
|
|
return listTitle;
|
2014-08-23 18:08:02 +02:00
|
|
|
};
|
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
var liFromListEntry = function(listKey, li) {
|
2015-03-08 22:54:08 +01:00
|
|
|
var entry = listDetails.available[listKey];
|
2017-01-18 19:17:47 +01:00
|
|
|
li = li ? li : listEntryTemplate.clone().nodeAt(0);
|
|
|
|
li.setAttribute('data-listkey', listKey);
|
|
|
|
var elem = li.querySelector('input[type="checkbox"]');
|
2015-03-08 22:54:08 +01:00
|
|
|
if ( entry.off !== true ) {
|
2017-01-18 19:17:47 +01:00
|
|
|
elem.setAttribute('checked', '');
|
|
|
|
} else {
|
|
|
|
elem.removeAttribute('checked');
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
2017-01-18 19:17:47 +01:00
|
|
|
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) + '\u200E';
|
|
|
|
elem = li.querySelector('a:nth-of-type(2)');
|
2015-06-10 17:30:57 +02:00
|
|
|
if ( entry.instructionURL ) {
|
2017-01-18 19:17:47 +01:00
|
|
|
elem.setAttribute('href', entry.instructionURL);
|
|
|
|
elem.style.setProperty('display', '');
|
|
|
|
} else {
|
|
|
|
elem.style.setProperty('display', 'none');
|
2015-06-10 17:30:57 +02:00
|
|
|
}
|
2017-01-18 19:17:47 +01:00
|
|
|
elem = li.querySelector('a:nth-of-type(3)');
|
2015-06-10 17:30:57 +02:00
|
|
|
if ( entry.supportName ) {
|
2017-01-18 19:17:47 +01:00
|
|
|
elem.setAttribute('href', entry.supportURL);
|
|
|
|
elem.textContent = '(' + entry.supportName + ')';
|
|
|
|
elem.style.setProperty('display', '');
|
|
|
|
} else {
|
|
|
|
elem.style.setProperty('display', 'none');
|
2014-09-09 16:53:47 +02:00
|
|
|
}
|
2017-01-18 19:17:47 +01:00
|
|
|
elem = li.querySelector('span.counts');
|
2015-06-08 02:27:19 +02:00
|
|
|
var text = listStatsTemplate
|
2015-03-08 22:54:08 +01:00
|
|
|
.replace('{{used}}', renderNumber(!entry.off && !isNaN(+entry.entryUsedCount) ? entry.entryUsedCount : 0))
|
|
|
|
.replace('{{total}}', !isNaN(+entry.entryCount) ? renderNumber(entry.entryCount) : '?');
|
2017-01-18 19:17:47 +01:00
|
|
|
elem.textContent = text;
|
2015-04-17 16:20:45 +02:00
|
|
|
|
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] || {};
|
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
// https://github.com/gorhill/uBlock/issues/78
|
|
|
|
// Badge for non-secure connection
|
|
|
|
var remoteURL = asset.remoteURL;
|
|
|
|
li.classList.toggle(
|
|
|
|
'unsecure',
|
|
|
|
typeof remoteURL === 'string' && remoteURL.lastIndexOf('http:', 0) === 0
|
|
|
|
);
|
2015-04-17 16:20:45 +02:00
|
|
|
// Badge for update status
|
2017-01-18 19:17:47 +01:00
|
|
|
li.classList.toggle(
|
|
|
|
'obsolete',
|
|
|
|
entry.off !== true && asset.obsolete === true
|
|
|
|
);
|
|
|
|
// Badge for cache status
|
|
|
|
li.classList.toggle(
|
|
|
|
'cached',
|
|
|
|
asset.cached === true && asset.writeTime > 0
|
|
|
|
);
|
2014-09-09 16:53:47 +02:00
|
|
|
if ( asset.cached ) {
|
2017-01-18 19:17:47 +01:00
|
|
|
li.querySelector('.status.purge').setAttribute(
|
|
|
|
'title',
|
|
|
|
lastUpdateString.replace('{{ago}}', renderElapsedTimeToString(asset.writeTime))
|
|
|
|
);
|
2014-09-09 16:53:47 +02:00
|
|
|
}
|
2017-01-19 20:03:08 +01:00
|
|
|
li.classList.remove('updating');
|
2017-01-18 19:17:47 +01:00
|
|
|
li.classList.remove('discard');
|
2015-03-08 22:54:08 +01:00
|
|
|
return li;
|
2014-09-09 16:53:47 +02:00
|
|
|
};
|
2014-07-16 02:32:33 +02:00
|
|
|
|
2015-03-23 15:19:43 +01:00
|
|
|
var listEntryCountFromGroup = function(listKeys) {
|
|
|
|
if ( Array.isArray(listKeys) === false ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
var count = 0;
|
|
|
|
var i = listKeys.length;
|
|
|
|
while ( i-- ) {
|
|
|
|
if ( listDetails.available[listKeys[i]].off !== true ) {
|
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count === 0 ? '' : '(' + count.toLocaleString() + ')';
|
|
|
|
};
|
|
|
|
|
2015-03-08 22:54:08 +01:00
|
|
|
var liFromListGroup = function(groupKey, listKeys) {
|
2017-01-18 19:17:47 +01:00
|
|
|
var liGroup = document.querySelector('#lists > .groupEntry[data-groupkey="' + groupKey + '"]');
|
|
|
|
if ( liGroup === null ) {
|
|
|
|
liGroup = listGroupTemplate.clone().nodeAt(0);
|
|
|
|
var groupName = vAPI.i18n('3pGroup' + groupKey.charAt(0).toUpperCase() + groupKey.slice(1));
|
|
|
|
if ( groupName !== '' ) {
|
|
|
|
liGroup.querySelector('.geName').textContent = groupName;
|
|
|
|
}
|
2015-03-23 15:19:43 +01:00
|
|
|
}
|
2017-01-18 19:17:47 +01:00
|
|
|
if ( liGroup.querySelector('.geName:empty') === null ) {
|
|
|
|
liGroup.querySelector('.geCount').textContent = listEntryCountFromGroup(listKeys);
|
2014-07-25 22:12:20 +02:00
|
|
|
}
|
2017-01-18 19:17:47 +01:00
|
|
|
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
|
|
|
});
|
2014-07-16 02:32:33 +02:00
|
|
|
for ( var i = 0; i < listKeys.length; i++ ) {
|
2017-01-18 19:17:47 +01:00
|
|
|
var liEntry = liFromListEntry(listKeys[i], ulGroup.children[i]);
|
|
|
|
if ( liEntry.parentElement === null ) {
|
|
|
|
ulGroup.appendChild(liEntry);
|
|
|
|
}
|
2014-07-16 02:32:33 +02:00
|
|
|
}
|
2015-03-08 22:54:08 +01:00
|
|
|
return liGroup;
|
2014-07-16 02:32:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2016-08-13 22:42:58 +02:00
|
|
|
parseCosmeticFilters = details.parseCosmeticFilters;
|
|
|
|
ignoreGenericCosmeticFilters = details.ignoreGenericCosmeticFilters;
|
2017-01-18 19:17:47 +01:00
|
|
|
|
|
|
|
// Incremental rendering: this will allow us to easily discard unused
|
|
|
|
// DOM list entries.
|
|
|
|
uDom('#lists .listEntries .listEntry').addClass('discard');
|
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
|
2017-01-18 19:17:47 +01:00
|
|
|
var ulLists = document.querySelector('#lists'),
|
|
|
|
groups = groupsFromLists(details.available),
|
|
|
|
liGroup, i, groupKey,
|
|
|
|
groupKeys = [
|
2014-07-25 22:12:20 +02:00
|
|
|
'default',
|
|
|
|
'ads',
|
|
|
|
'privacy',
|
|
|
|
'malware',
|
|
|
|
'social',
|
|
|
|
'multipurpose',
|
|
|
|
'regions',
|
|
|
|
'custom'
|
|
|
|
];
|
|
|
|
for ( i = 0; i < groupKeys.length; i++ ) {
|
|
|
|
groupKey = groupKeys[i];
|
2015-03-14 19:12:05 +01:00
|
|
|
liGroup = liFromListGroup(groupKey, groups[groupKey]);
|
2017-01-18 19:17:47 +01:00
|
|
|
liGroup.setAttribute('data-groupkey', groupKey);
|
|
|
|
liGroup.classList.toggle(
|
2015-03-14 19:12:05 +01:00
|
|
|
'collapsed',
|
|
|
|
vAPI.localStorage.getItem('collapseGroup' + (i + 1)) === 'y'
|
|
|
|
);
|
2017-01-18 19:17:47 +01:00
|
|
|
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];
|
2017-01-18 19:17:47 +01:00
|
|
|
ulLists.appendChild(liFromListGroup(groupKey, groups[groupKey]));
|
2014-07-25 22:12:20 +02:00
|
|
|
}
|
2014-07-16 02:32:33 +02:00
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
uDom('#lists .listEntries .listEntry.discard').remove();
|
|
|
|
uDom('#buttonUpdate').toggleClass('disabled', document.querySelector('#lists .listEntry.obsolete') === null);
|
|
|
|
uDom('#autoUpdate').prop('checked', listDetails.autoUpdate === true);
|
|
|
|
uDom('#parseCosmeticFilters').prop('checked', listDetails.parseCosmeticFilters === true);
|
|
|
|
uDom('#ignoreGenericCosmeticFilters').prop('checked', listDetails.ignoreGenericCosmeticFilters === true);
|
2014-08-20 16:26:57 +02:00
|
|
|
uDom('#listsOfBlockedHostsPrompt').text(
|
2014-10-17 21:44:19 +02:00
|
|
|
vAPI.i18n('3pListsOfBlockedHostsPrompt')
|
2014-08-20 16:26:57 +02:00
|
|
|
.replace('{{netFilterCount}}', renderNumber(details.netFilterCount))
|
|
|
|
.replace('{{cosmeticFilterCount}}', renderNumber(details.cosmeticFilterCount))
|
|
|
|
);
|
2017-01-18 19:17:47 +01:00
|
|
|
|
|
|
|
// Compute a hash of the lists currently enabled in memory.
|
|
|
|
var selectedListsBefore = [];
|
|
|
|
for ( var key in listDetails.current ) {
|
|
|
|
if ( listDetails.current[key].off !== true ) {
|
|
|
|
selectedListsBefore.push(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
selectedListsHashBefore = selectedListsBefore.sort().join();
|
2015-01-13 20:25:10 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
// This is to give a visual hint that the selection of blacklists has changed.
|
2015-03-11 04:46:18 +01:00
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
var renderWidgets = function() {
|
|
|
|
uDom('#buttonApply').toggleClass('disabled', !listsSelectionChanged());
|
|
|
|
uDom('#buttonPurgeAll').toggleClass('disabled', document.querySelector('#lists .listEntry.cached') === null);
|
|
|
|
uDom('#buttonUpdate').toggleClass('disabled', document.querySelector('#lists .listEntry.obsolete') === null);
|
2015-03-11 04:46:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
var updateAssetStatus = function(details) {
|
|
|
|
var li = uDom('#lists .listEntry[data-listkey="' + details.key + '"]');
|
|
|
|
li.toggleClass('obsolete', !details.cached);
|
|
|
|
li.toggleClass('cached', details.cached);
|
|
|
|
li.removeClass('updating');
|
|
|
|
renderWidgets();
|
2015-03-11 04:46:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-08-20 02:41:52 +02:00
|
|
|
// Return whether selection of lists changed.
|
2014-06-24 00:42:43 +02:00
|
|
|
|
2014-08-20 02:41:52 +02:00
|
|
|
var listsSelectionChanged = function() {
|
2016-08-13 22:42:58 +02:00
|
|
|
if (
|
|
|
|
listDetails.parseCosmeticFilters !== parseCosmeticFilters ||
|
2017-01-18 19:17:47 +01:00
|
|
|
listDetails.parseCosmeticFilters &&
|
|
|
|
listDetails.ignoreGenericCosmeticFilters !== ignoreGenericCosmeticFilters
|
2016-08-13 22:42:58 +02:00
|
|
|
) {
|
2014-07-25 22:12:20 +02:00
|
|
|
return true;
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
2017-01-18 19:17:47 +01:00
|
|
|
var selectedListsAfter = [],
|
|
|
|
listEntries = uDom('#lists .listEntry[data-listkey] > input[type="checkbox"]:checked');
|
|
|
|
for ( var i = 0, n = listEntries.length; i < n; i++ ) {
|
|
|
|
selectedListsAfter.push(listEntries.at(i).ancestors('.listEntry[data-listkey]').attr('data-listkey'));
|
2014-07-25 22:12:20 +02:00
|
|
|
}
|
2015-03-11 04:46:18 +01:00
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
return selectedListsHashBefore !== selectedListsAfter.sort().join();
|
2014-08-20 02:41:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-07-25 22:12:20 +02:00
|
|
|
var onListCheckboxChanged = 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
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-08-20 05:01:36 +02:00
|
|
|
var onPurgeClicked = function() {
|
2017-01-18 19:17:47 +01:00
|
|
|
var button = uDom(this),
|
|
|
|
liEntry = button.ancestors('[data-listkey]'),
|
|
|
|
listKey = liEntry.attr('data-listkey');
|
|
|
|
if ( !listKey ) { return; }
|
2015-10-14 20:16:43 +02:00
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
messaging.send('dashboard', { what: 'purgeCache', assetKey: listKey });
|
2015-10-14 20:16:43 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
|
// An external filter list must not be marked as obsolete, they will always
|
|
|
|
// be fetched anyways if there is no cached copy.
|
2017-01-18 19:17:47 +01:00
|
|
|
var entry = listDetails.current && listDetails.current[listKey];
|
|
|
|
if ( entry && entry.off !== true ) {
|
|
|
|
liEntry.addClass('obsolete');
|
|
|
|
uDom('#buttonUpdate').removeClass('disabled');
|
2015-10-14 20:16:43 +02:00
|
|
|
}
|
2017-01-18 19:17:47 +01:00
|
|
|
liEntry.removeClass('cached');
|
2015-10-14 20:16:43 +02:00
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
if ( liEntry.descendants('input').first().prop('checked') ) {
|
2015-03-11 04:46:18 +01:00
|
|
|
renderWidgets();
|
2014-08-20 02:41:52 +02:00
|
|
|
}
|
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: listDetails.parseCosmeticFilters
|
|
|
|
});
|
|
|
|
messaging.send('dashboard', {
|
|
|
|
what: 'userSettings',
|
|
|
|
name: 'ignoreGenericCosmeticFilters',
|
|
|
|
value: listDetails.ignoreGenericCosmeticFilters
|
|
|
|
});
|
2015-03-11 04:46:18 +01:00
|
|
|
|
|
|
|
// Filter lists
|
2017-01-18 19:17:47 +01:00
|
|
|
var listKeys = [],
|
|
|
|
liEntries = uDom('#lists .listEntry'), liEntry,
|
|
|
|
i = liEntries.length;
|
2014-06-24 00:42:43 +02:00
|
|
|
while ( i-- ) {
|
2017-01-18 19:17:47 +01:00
|
|
|
liEntry = liEntries.at(i);
|
|
|
|
if ( liEntry.descendants('input').first().prop('checked') ) {
|
|
|
|
listKeys.push(liEntry.attr('data-listkey'));
|
|
|
|
}
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
2015-03-11 04:46:18 +01:00
|
|
|
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'dashboard',
|
|
|
|
{
|
|
|
|
what: 'selectFilterLists',
|
2017-01-18 19:17:47 +01:00
|
|
|
keys: listKeys
|
2016-03-06 16:51:06 +01:00
|
|
|
},
|
|
|
|
callback
|
|
|
|
);
|
2014-08-20 02:41:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var buttonApplyHandler = function() {
|
2015-03-12 22:25:51 +01:00
|
|
|
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);
|
2014-08-20 02:41:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var buttonUpdateHandler = function() {
|
2017-01-18 19:17:47 +01:00
|
|
|
var onSelectionDone = function() {
|
|
|
|
uDom('#lists .listEntry.obsolete').addClass('updating');
|
|
|
|
messaging.send('dashboard', { what: 'forceUpdateAssets' });
|
|
|
|
};
|
|
|
|
selectFilterLists(onSelectionDone);
|
2014-08-20 02:41:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
var buttonPurgeAllHandler = function(ev) {
|
2015-03-12 22:25:51 +01:00
|
|
|
uDom('#buttonPurgeAll').removeClass('enabled');
|
2017-01-18 19:17:47 +01:00
|
|
|
messaging.send(
|
|
|
|
'dashboard',
|
|
|
|
{
|
|
|
|
what: 'purgeAllCaches',
|
|
|
|
hard: ev.ctrlKey && ev.shiftKey
|
|
|
|
},
|
|
|
|
renderFilterLists
|
|
|
|
);
|
2014-09-09 01:45:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-08-20 02:41:52 +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
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-08-20 16:26:57 +02:00
|
|
|
var cosmeticSwitchChanged = function() {
|
2016-08-13 22:42:58 +02:00
|
|
|
listDetails.parseCosmeticFilters = uDom.nodeFromId('parseCosmeticFilters').checked;
|
|
|
|
listDetails.ignoreGenericCosmeticFilters = uDom.nodeFromId('ignoreGenericCosmeticFilters').checked;
|
2015-03-11 04:46:18 +01:00
|
|
|
renderWidgets();
|
2014-07-25 22:12:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var renderExternalLists = function() {
|
|
|
|
var onReceived = function(details) {
|
|
|
|
uDom('#externalLists').val(details);
|
|
|
|
externalLists = details;
|
|
|
|
};
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'dashboard',
|
|
|
|
{ what: 'userSettings', name: 'externalLists' },
|
|
|
|
onReceived
|
|
|
|
);
|
2014-07-25 22:12:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var externalListsChangeHandler = function() {
|
2015-08-12 00:48:52 +02:00
|
|
|
uDom.nodeFromId('externalListsApply').disabled =
|
2016-01-08 17:08:53 +01:00
|
|
|
uDom.nodeFromId('externalLists').value.trim() === externalLists.trim();
|
2014-07-25 22:12:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var externalListsApplyHandler = function() {
|
2015-08-11 21:29:14 +02:00
|
|
|
externalLists = uDom.nodeFromId('externalLists').value;
|
2016-03-06 16:51:06 +01:00
|
|
|
messaging.send(
|
|
|
|
'dashboard',
|
|
|
|
{
|
|
|
|
what: 'userSettings',
|
|
|
|
name: 'externalLists',
|
|
|
|
value: externalLists
|
|
|
|
}
|
|
|
|
);
|
2015-03-11 04:46:18 +01:00
|
|
|
renderFilterLists();
|
2014-07-25 22:12:20 +02:00
|
|
|
uDom('#externalListsApply').prop('disabled', true);
|
2014-07-09 22:03:25 +02:00
|
|
|
};
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-03-14 19:12:05 +01:00
|
|
|
var groupEntryClickHandler = function() {
|
|
|
|
var li = uDom(this).ancestors('.groupEntry');
|
|
|
|
li.toggleClass('collapsed');
|
|
|
|
var key = 'collapseGroup' + li.nthOfType();
|
|
|
|
if ( li.hasClass('collapsed') ) {
|
|
|
|
vAPI.localStorage.setItem(key, 'y');
|
|
|
|
} else {
|
|
|
|
vAPI.localStorage.removeItem(key);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
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,
|
2015-08-11 21:29:14 +02:00
|
|
|
selectedLists: [],
|
|
|
|
externalLists: externalLists
|
|
|
|
};
|
2014-06-24 00:42:43 +02:00
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
var liEntries = uDom('#lists .listEntry'), liEntry;
|
|
|
|
var i = liEntries.length;
|
2015-08-11 21:29:14 +02:00
|
|
|
while ( i-- ) {
|
2017-01-18 19:17:47 +01:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
var fromCloudData = function(data, append) {
|
|
|
|
if ( typeof data !== 'object' || data === null ) { return; }
|
2015-08-11 21:29:14 +02:00
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
var elem, checked, i, n;
|
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
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
var listKey;
|
|
|
|
for ( i = 0, n = data.selectedLists.length; i < n; i++ ) {
|
|
|
|
listKey = data.selectedLists[i];
|
|
|
|
if ( listDetails.aliases[listKey] ) {
|
|
|
|
data.selectedLists[i] = listDetails.aliases[listKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var selectedSet = new Set(data.selectedLists),
|
|
|
|
listEntries = uDom('#lists .listEntry'),
|
|
|
|
listEntry, input;
|
|
|
|
for ( i = 0, n = listEntries.length; i < n; i++ ) {
|
|
|
|
listEntry = listEntries.at(i);
|
|
|
|
listKey = listEntry.attr('data-listkey');
|
|
|
|
input = listEntry.descendants('input').first();
|
|
|
|
if ( append && input.prop('checked') ) { continue; }
|
|
|
|
input.prop('checked', selectedSet.has(listKey) );
|
2015-08-11 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2016-01-08 17:08:53 +01:00
|
|
|
elem = uDom.nodeFromId('externalLists');
|
2017-01-18 19:17:47 +01:00
|
|
|
if ( !append ) { elem.value = ''; }
|
2016-01-08 17:08:53 +01:00
|
|
|
elem.value += data.externalLists || '';
|
2015-08-11 21:29:14 +02:00
|
|
|
|
|
|
|
renderWidgets();
|
|
|
|
externalListsChangeHandler();
|
|
|
|
};
|
|
|
|
|
2017-01-18 19:17:47 +01:00
|
|
|
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', cosmeticSwitchChanged);
|
2016-08-13 22:42:58 +02:00
|
|
|
uDom('#ignoreGenericCosmeticFilters').on('change', cosmeticSwitchChanged);
|
2015-08-11 21:29:14 +02:00
|
|
|
uDom('#buttonApply').on('click', buttonApplyHandler);
|
|
|
|
uDom('#buttonUpdate').on('click', buttonUpdateHandler);
|
|
|
|
uDom('#buttonPurgeAll').on('click', buttonPurgeAllHandler);
|
|
|
|
uDom('#lists').on('change', '.listEntry > input', onListCheckboxChanged);
|
|
|
|
uDom('#lists').on('click', 'span.purge', onPurgeClicked);
|
|
|
|
uDom('#externalLists').on('input', externalListsChangeHandler);
|
|
|
|
uDom('#externalListsApply').on('click', externalListsApplyHandler);
|
|
|
|
uDom('#lists').on('click', '.groupEntry > span', groupEntryClickHandler);
|
|
|
|
|
|
|
|
renderFilterLists();
|
|
|
|
renderExternalLists();
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|
|
|
|
|