|
|
@ -1,7 +1,7 @@
|
|
|
|
/*******************************************************************************
|
|
|
|
/*******************************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
µMatrix - a Chromium browser extension to black/white list requests.
|
|
|
|
uMatrix - a Chromium browser extension to black/white list requests.
|
|
|
|
Copyright (C) 2014-2015 Raymond Hill
|
|
|
|
Copyright (C) 2014-2017 Raymond Hill
|
|
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
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
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
@ -19,37 +19,34 @@
|
|
|
|
Home: https://github.com/gorhill/uMatrix
|
|
|
|
Home: https://github.com/gorhill/uMatrix
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* global vAPI, uDom */
|
|
|
|
/* global uDom */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
var listDetails = {};
|
|
|
|
var listDetails = {},
|
|
|
|
var externalHostsFiles = '';
|
|
|
|
lastUpdateTemplateString = vAPI.i18n('hostsFilesLastUpdate'),
|
|
|
|
var cacheWasPurged = false;
|
|
|
|
hostsFilesSettingsHash,
|
|
|
|
var needUpdate = false;
|
|
|
|
reValidExternalList = /[a-z-]+:\/\/\S*\/\S+/;
|
|
|
|
var hasCachedContent = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
var onMessage = function(msg) {
|
|
|
|
var onMessage = function(msg) {
|
|
|
|
switch ( msg.what ) {
|
|
|
|
switch ( msg.what ) {
|
|
|
|
|
|
|
|
case 'assetUpdated':
|
|
|
|
|
|
|
|
updateAssetStatus(msg);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'assetsUpdated':
|
|
|
|
|
|
|
|
document.body.classList.remove('updating');
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 'loadHostsFilesCompleted':
|
|
|
|
case 'loadHostsFilesCompleted':
|
|
|
|
renderHostsFiles();
|
|
|
|
renderHostsFiles();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 'forceUpdateAssetsProgress':
|
|
|
|
|
|
|
|
renderBusyOverlay(true, msg.progress);
|
|
|
|
|
|
|
|
if ( msg.done ) {
|
|
|
|
|
|
|
|
messager.send({ what: 'reloadHostsFiles' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -65,115 +62,120 @@ var renderNumber = function(value) {
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: get rid of background page dependencies
|
|
|
|
var renderHostsFiles = function(soft) {
|
|
|
|
|
|
|
|
var listEntryTemplate = uDom('#templates .listEntry'),
|
|
|
|
var renderHostsFiles = function() {
|
|
|
|
listStatsTemplate = vAPI.i18n('hostsFilesPerFileStats'),
|
|
|
|
var listEntryTemplate = uDom('#templates .listEntry');
|
|
|
|
renderElapsedTimeToString = vAPI.i18n.renderElapsedTimeToString,
|
|
|
|
var listStatsTemplate = vAPI.i18n('hostsFilesPerFileStats');
|
|
|
|
reExternalHostFile = /^https?:/;
|
|
|
|
var lastUpdateString = vAPI.i18n('hostsFilesLastUpdate');
|
|
|
|
|
|
|
|
var renderElapsedTimeToString = vAPI.i18n.renderElapsedTimeToString;
|
|
|
|
|
|
|
|
var reExternalHostFile = /^https?:/;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Assemble a pretty blacklist name if possible
|
|
|
|
// Assemble a pretty list name if possible
|
|
|
|
var listNameFromListKey = function(listKey) {
|
|
|
|
var listNameFromListKey = function(listKey) {
|
|
|
|
var list = listDetails.current[listKey] || listDetails.available[listKey];
|
|
|
|
var list = listDetails.current[listKey] || listDetails.available[listKey];
|
|
|
|
var listTitle = list ? list.title : '';
|
|
|
|
var listTitle = list ? list.title : '';
|
|
|
|
if ( listTitle === '' ) {
|
|
|
|
if ( listTitle === '' ) { return listKey; }
|
|
|
|
return listKey;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return listTitle;
|
|
|
|
return listTitle;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var liFromListEntry = function(listKey) {
|
|
|
|
var liFromListEntry = function(listKey, li) {
|
|
|
|
var elem, text;
|
|
|
|
var entry = listDetails.available[listKey],
|
|
|
|
var entry = listDetails.available[listKey];
|
|
|
|
elem;
|
|
|
|
var li = listEntryTemplate.clone();
|
|
|
|
if ( !li ) {
|
|
|
|
|
|
|
|
li = listEntryTemplate.clone().nodeAt(0);
|
|
|
|
if ( entry.off !== true ) {
|
|
|
|
|
|
|
|
li.descendants('input').attr('checked', '');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( li.getAttribute('data-listkey') !== listKey ) {
|
|
|
|
elem = li.descendants('a:nth-of-type(1)');
|
|
|
|
li.setAttribute('data-listkey', listKey);
|
|
|
|
elem.attr('href', encodeURI(listKey));
|
|
|
|
elem = li.querySelector('input[type="checkbox"]');
|
|
|
|
elem.text(listNameFromListKey(listKey) + '\u200E');
|
|
|
|
elem.checked = entry.off !== true;
|
|
|
|
|
|
|
|
elem = li.querySelector('a:nth-of-type(1)');
|
|
|
|
elem = li.descendants('a:nth-of-type(2)');
|
|
|
|
elem.setAttribute('href', 'asset-viewer.html?url=' + encodeURI(listKey));
|
|
|
|
if ( entry.homeDomain ) {
|
|
|
|
elem.setAttribute('type', 'text/html');
|
|
|
|
elem.attr('href', 'http://' + encodeURI(entry.homeHostname));
|
|
|
|
elem.textContent = listNameFromListKey(listKey);
|
|
|
|
elem.text('(' + entry.homeDomain + ')');
|
|
|
|
li.classList.remove('toRemove');
|
|
|
|
elem.css('display', '');
|
|
|
|
if ( entry.supportName ) {
|
|
|
|
|
|
|
|
li.classList.add('support');
|
|
|
|
|
|
|
|
elem = li.querySelector('a.support');
|
|
|
|
|
|
|
|
elem.setAttribute('href', entry.supportURL);
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
li.classList.remove('mustread');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://github.com/gorhill/uBlock/issues/1429
|
|
|
|
elem = li.descendants('span:nth-of-type(1)');
|
|
|
|
if ( !soft ) {
|
|
|
|
text = listStatsTemplate
|
|
|
|
elem = li.querySelector('input[type="checkbox"]');
|
|
|
|
.replace('{{used}}', renderNumber(!entry.off && !isNaN(+entry.entryUsedCount) ? entry.entryUsedCount : 0))
|
|
|
|
elem.checked = entry.off !== true;
|
|
|
|
.replace('{{total}}', !isNaN(+entry.entryCount) ? renderNumber(entry.entryCount) : '?');
|
|
|
|
|
|
|
|
elem.text(text);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://github.com/gorhill/uBlock/issues/78
|
|
|
|
|
|
|
|
// Badge for non-secure connection
|
|
|
|
|
|
|
|
var remoteURL = listKey;
|
|
|
|
|
|
|
|
if ( remoteURL.lastIndexOf('http:', 0) !== 0 ) {
|
|
|
|
|
|
|
|
remoteURL = entry.homeURL || '';
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( remoteURL.lastIndexOf('http:', 0) === 0 ) {
|
|
|
|
elem = li.querySelector('span.counts');
|
|
|
|
li.descendants('span.status.unsecure').css('display', '');
|
|
|
|
var text = '';
|
|
|
|
|
|
|
|
if ( !isNaN(+entry.entryUsedCount) && !isNaN(+entry.entryCount) ) {
|
|
|
|
|
|
|
|
text = listStatsTemplate
|
|
|
|
|
|
|
|
.replace('{{used}}', renderNumber(entry.off ? 0 : entry.entryUsedCount))
|
|
|
|
|
|
|
|
.replace('{{total}}', renderNumber(entry.entryCount));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
elem.textContent = text;
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/104
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/104
|
|
|
|
var asset = listDetails.cache[listKey] || {};
|
|
|
|
var asset = listDetails.cache[listKey] || {};
|
|
|
|
|
|
|
|
var remoteURL = asset.remoteURL;
|
|
|
|
// Badge for update status
|
|
|
|
li.classList.toggle(
|
|
|
|
if ( entry.off !== true ) {
|
|
|
|
'unsecure',
|
|
|
|
if ( asset.repoObsolete ) {
|
|
|
|
typeof remoteURL === 'string' && remoteURL.lastIndexOf('http:', 0) === 0
|
|
|
|
li.descendants('span.status.new').css('display', '');
|
|
|
|
);
|
|
|
|
needUpdate = true;
|
|
|
|
li.classList.toggle('failed', asset.error !== undefined);
|
|
|
|
} else if ( asset.cacheObsolete ) {
|
|
|
|
li.classList.toggle('obsolete', asset.obsolete === true);
|
|
|
|
li.descendants('span.status.obsolete').css('display', '');
|
|
|
|
li.classList.toggle('cached', asset.cached === true && asset.writeTime > 0);
|
|
|
|
needUpdate = true;
|
|
|
|
|
|
|
|
} else if ( entry.external && !asset.cached ) {
|
|
|
|
|
|
|
|
li.descendants('span.status.obsolete').css('display', '');
|
|
|
|
|
|
|
|
needUpdate = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// In cache
|
|
|
|
|
|
|
|
if ( asset.cached ) {
|
|
|
|
if ( asset.cached ) {
|
|
|
|
elem = li.descendants('span.status.purge');
|
|
|
|
li.querySelector('.status.cache').setAttribute(
|
|
|
|
elem.css('display', '');
|
|
|
|
'title',
|
|
|
|
elem.attr('title', lastUpdateString.replace('{{ago}}', renderElapsedTimeToString(asset.lastModified)));
|
|
|
|
lastUpdateTemplateString.replace('{{ago}}', renderElapsedTimeToString(asset.writeTime))
|
|
|
|
hasCachedContent = true;
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
li.classList.remove('discard');
|
|
|
|
return li;
|
|
|
|
return li;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var onListsReceived = function(details) {
|
|
|
|
var onListsReceived = function(details) {
|
|
|
|
// Before all, set context vars
|
|
|
|
// Before all, set context vars
|
|
|
|
listDetails = details;
|
|
|
|
listDetails = details;
|
|
|
|
needUpdate = false;
|
|
|
|
|
|
|
|
hasCachedContent = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var availableLists = details.available;
|
|
|
|
// Incremental rendering: this will allow us to easily discard unused
|
|
|
|
var listKeys = Object.keys(details.available);
|
|
|
|
// DOM list entries.
|
|
|
|
|
|
|
|
uDom('#lists .listEntry').addClass('discard');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var availableLists = details.available,
|
|
|
|
|
|
|
|
listKeys = Object.keys(details.available);
|
|
|
|
|
|
|
|
|
|
|
|
// Sort works this way:
|
|
|
|
// Sort works this way:
|
|
|
|
// - Send /^https?:/ items at the end (custom hosts file URL)
|
|
|
|
// - Send /^https?:/ items at the end (custom hosts file URL)
|
|
|
|
listKeys.sort(function(a, b) {
|
|
|
|
listKeys.sort(function(a, b) {
|
|
|
|
var ta = availableLists[a].title || a;
|
|
|
|
var ta = availableLists[a].title || a,
|
|
|
|
var tb = availableLists[b].title || b;
|
|
|
|
tb = availableLists[b].title || b;
|
|
|
|
if ( reExternalHostFile.test(ta) === reExternalHostFile.test(tb) ) {
|
|
|
|
if ( reExternalHostFile.test(ta) === reExternalHostFile.test(tb) ) {
|
|
|
|
return ta.localeCompare(tb);
|
|
|
|
return ta.localeCompare(tb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( reExternalHostFile.test(tb) ) {
|
|
|
|
return reExternalHostFile.test(tb) ? -1 : 1;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var ulList = uDom('#lists').empty();
|
|
|
|
|
|
|
|
|
|
|
|
var ulList = document.querySelector('#lists');
|
|
|
|
for ( var i = 0; i < listKeys.length; i++ ) {
|
|
|
|
for ( var i = 0; i < listKeys.length; i++ ) {
|
|
|
|
ulList.append(liFromListEntry(listKeys[i]));
|
|
|
|
var liEntry = liFromListEntry(listKeys[i], ulList.children[i]);
|
|
|
|
|
|
|
|
if ( liEntry.parentElement === null ) {
|
|
|
|
|
|
|
|
ulList.appendChild(liEntry);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uDom('#lists .listEntry.discard').remove();
|
|
|
|
uDom('#listsOfBlockedHostsPrompt').text(
|
|
|
|
uDom('#listsOfBlockedHostsPrompt').text(
|
|
|
|
vAPI.i18n('hostsFilesStats').replace(
|
|
|
|
vAPI.i18n('hostsFilesStats').replace(
|
|
|
|
'{{blockedHostnameCount}}',
|
|
|
|
'{{blockedHostnameCount}}',
|
|
|
@ -182,8 +184,10 @@ var renderHostsFiles = function() {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
uDom('#autoUpdate').prop('checked', listDetails.autoUpdate === true);
|
|
|
|
uDom('#autoUpdate').prop('checked', listDetails.autoUpdate === true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( !soft ) {
|
|
|
|
|
|
|
|
hostsFilesSettingsHash = hashFromCurrentFromSettings();
|
|
|
|
|
|
|
|
}
|
|
|
|
renderWidgets();
|
|
|
|
renderWidgets();
|
|
|
|
renderBusyOverlay(details.manualUpdate, details.manualUpdateProgress);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
messager.send({ what: 'getLists' }, onListsReceived);
|
|
|
|
messager.send({ what: 'getLists' }, onListsReceived);
|
|
|
@ -191,198 +195,163 @@ var renderHostsFiles = function() {
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
// Progress must be normalized to [0, 1], or can be undefined.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var renderBusyOverlay = function(state, progress) {
|
|
|
|
|
|
|
|
progress = progress || {};
|
|
|
|
|
|
|
|
var showProgress = typeof progress.value === 'number';
|
|
|
|
|
|
|
|
if ( showProgress ) {
|
|
|
|
|
|
|
|
uDom('#busyOverlay > div:nth-of-type(2) > div:first-child').css(
|
|
|
|
|
|
|
|
'width',
|
|
|
|
|
|
|
|
(progress.value * 100).toFixed(1) + '%'
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
var text = progress.text || '';
|
|
|
|
|
|
|
|
if ( text !== '' ) {
|
|
|
|
|
|
|
|
uDom('#busyOverlay > div:nth-of-type(2) > div:last-child').text(text);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
uDom('#busyOverlay > div:nth-of-type(2)').css('display', showProgress ? '' : 'none');
|
|
|
|
|
|
|
|
uDom('body').toggleClass('busy', !!state);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This is to give a visual hint that the selection of blacklists has changed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var renderWidgets = function() {
|
|
|
|
var renderWidgets = function() {
|
|
|
|
uDom('#buttonApply').toggleClass('disabled', !listsSelectionChanged());
|
|
|
|
uDom('#buttonUpdate').toggleClass('disabled', document.querySelector('body:not(.updating) #lists .listEntry.obsolete > input[type="checkbox"]:checked') === null);
|
|
|
|
uDom('#buttonUpdate').toggleClass('disabled', !listsContentChanged());
|
|
|
|
uDom('#buttonPurgeAll').toggleClass('disabled', document.querySelector('#lists .listEntry.cached') === null);
|
|
|
|
uDom('#buttonPurgeAll').toggleClass('disabled', !hasCachedContent);
|
|
|
|
uDom('#buttonApply').toggleClass('disabled', hostsFilesSettingsHash === hashFromCurrentFromSettings());
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
// Return whether selection of lists changed.
|
|
|
|
var updateAssetStatus = function(details) {
|
|
|
|
|
|
|
|
var li = document.querySelector('#lists .listEntry[data-listkey="' + details.key + '"]');
|
|
|
|
var listsSelectionChanged = function() {
|
|
|
|
if ( li === null ) { return; }
|
|
|
|
if ( cacheWasPurged ) {
|
|
|
|
li.classList.toggle('failed', !!details.failed);
|
|
|
|
return true;
|
|
|
|
li.classList.toggle('obsolete', !details.cached);
|
|
|
|
}
|
|
|
|
li.classList.toggle('cached', !!details.cached);
|
|
|
|
var availableLists = listDetails.available;
|
|
|
|
if ( details.cached ) {
|
|
|
|
var currentLists = listDetails.current;
|
|
|
|
li.querySelector('.status.cache').setAttribute(
|
|
|
|
var location, availableOff, currentOff;
|
|
|
|
'title',
|
|
|
|
// This check existing entries
|
|
|
|
lastUpdateTemplateString.replace(
|
|
|
|
for ( location in availableLists ) {
|
|
|
|
'{{ago}}',
|
|
|
|
if ( availableLists.hasOwnProperty(location) === false ) {
|
|
|
|
vAPI.i18n.renderElapsedTimeToString(Date.now())
|
|
|
|
continue;
|
|
|
|
)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
availableOff = availableLists[location].off === true;
|
|
|
|
|
|
|
|
currentOff = currentLists[location] === undefined || currentLists[location].off === true;
|
|
|
|
|
|
|
|
if ( availableOff !== currentOff ) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// This check removed entries
|
|
|
|
|
|
|
|
for ( location in currentLists ) {
|
|
|
|
|
|
|
|
if ( currentLists.hasOwnProperty(location) === false ) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
currentOff = currentLists[location].off === true;
|
|
|
|
|
|
|
|
availableOff = availableLists[location] === undefined || availableLists[location].off === true;
|
|
|
|
|
|
|
|
if ( availableOff !== currentOff ) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
renderWidgets();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/*******************************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
// Return whether content need update.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var listsContentChanged = function() {
|
|
|
|
Compute a hash from all the settings affecting how filter lists are loaded
|
|
|
|
return needUpdate;
|
|
|
|
in memory.
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
|
|
// This is to give a visual hint that the selection of blacklists has changed.
|
|
|
|
var hashFromCurrentFromSettings = function() {
|
|
|
|
|
|
|
|
var hash = [],
|
|
|
|
var updateWidgets = function() {
|
|
|
|
listHash = [],
|
|
|
|
uDom('#buttonApply').toggleClass('disabled', !listsSelectionChanged());
|
|
|
|
listEntries = document.querySelectorAll('#lists .listEntry[data-listkey]:not(.toRemove)'),
|
|
|
|
uDom('#buttonUpdate').toggleClass('disabled', !listsContentChanged());
|
|
|
|
liEntry,
|
|
|
|
uDom('#buttonPurgeAll').toggleClass('disabled', !hasCachedContent);
|
|
|
|
i = listEntries.length;
|
|
|
|
uDom('body').toggleClass('busy', false);
|
|
|
|
while ( i-- ) {
|
|
|
|
|
|
|
|
liEntry = listEntries[i];
|
|
|
|
|
|
|
|
if ( liEntry.querySelector('input[type="checkbox"]:checked') !== null ) {
|
|
|
|
|
|
|
|
listHash.push(liEntry.getAttribute('data-listkey'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
hash.push(
|
|
|
|
|
|
|
|
listHash.sort().join(),
|
|
|
|
|
|
|
|
reValidExternalList.test(document.getElementById('externalHostsFiles').value),
|
|
|
|
|
|
|
|
document.querySelector('#lists .listEntry.toRemove') !== null
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return hash.join();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
var onListCheckboxChanged = function() {
|
|
|
|
var onHostsFilesSettingsChanged = function() {
|
|
|
|
var href = uDom(this).parent().descendants('a').first().attr('href');
|
|
|
|
renderWidgets();
|
|
|
|
if ( typeof href !== 'string' ) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( listDetails.available[href] === undefined ) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
listDetails.available[href].off = !this.checked;
|
|
|
|
|
|
|
|
updateWidgets();
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
var onListLinkClicked = function(ev) {
|
|
|
|
var onRemoveExternalHostsFile = function(ev) {
|
|
|
|
messager.send({
|
|
|
|
var liEntry = uDom(this).ancestors('[data-listkey]'),
|
|
|
|
what: 'gotoExtensionURL',
|
|
|
|
listKey = liEntry.attr('data-listkey');
|
|
|
|
url: 'asset-viewer.html?url=' + uDom(this).attr('href')
|
|
|
|
if ( listKey ) {
|
|
|
|
});
|
|
|
|
liEntry.toggleClass('toRemove');
|
|
|
|
|
|
|
|
renderWidgets();
|
|
|
|
|
|
|
|
}
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.preventDefault();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
var onPurgeClicked = function() {
|
|
|
|
var onPurgeClicked = function() {
|
|
|
|
var button = uDom(this);
|
|
|
|
var button = uDom(this),
|
|
|
|
var li = button.parent();
|
|
|
|
liEntry = button.ancestors('[data-listkey]'),
|
|
|
|
var href = li.descendants('a').first().attr('href');
|
|
|
|
listKey = liEntry.attr('data-listkey');
|
|
|
|
if ( !href ) {
|
|
|
|
if ( !listKey ) { return; }
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
messager.send({ what: 'purgeCache', assetKey: listKey });
|
|
|
|
messager.send({ what: 'purgeCache', path: href });
|
|
|
|
liEntry.addClass('obsolete');
|
|
|
|
button.remove();
|
|
|
|
liEntry.removeClass('cached');
|
|
|
|
if ( li.descendants('input').first().prop('checked') ) {
|
|
|
|
|
|
|
|
cacheWasPurged = true;
|
|
|
|
if ( liEntry.descendants('input').first().prop('checked') ) {
|
|
|
|
updateWidgets();
|
|
|
|
renderWidgets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
var selectHostsFiles = function(callback) {
|
|
|
|
var selectHostsFiles = function(callback) {
|
|
|
|
var switches = [];
|
|
|
|
// Hosts files to select
|
|
|
|
var lis = uDom('#lists .listEntry'), li;
|
|
|
|
var toSelect = [],
|
|
|
|
var i = lis.length;
|
|
|
|
liEntries = document.querySelectorAll('#lists .listEntry[data-listkey]:not(.toRemove)'),
|
|
|
|
|
|
|
|
i = liEntries.length,
|
|
|
|
|
|
|
|
liEntry;
|
|
|
|
while ( i-- ) {
|
|
|
|
while ( i-- ) {
|
|
|
|
li = lis.at(i);
|
|
|
|
liEntry = liEntries[i];
|
|
|
|
switches.push({
|
|
|
|
if ( liEntry.querySelector('input[type="checkbox"]:checked') !== null ) {
|
|
|
|
location: li.descendants('a').attr('href'),
|
|
|
|
toSelect.push(liEntry.getAttribute('data-listkey'));
|
|
|
|
off: li.descendants('input').prop('checked') === false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// External hosts files 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 hosts files to import
|
|
|
|
|
|
|
|
var externalListsElem = document.getElementById('externalHostsFiles'),
|
|
|
|
|
|
|
|
toImport = externalListsElem.value.trim();
|
|
|
|
|
|
|
|
externalListsElem.value = '';
|
|
|
|
|
|
|
|
|
|
|
|
messager.send({
|
|
|
|
messager.send({
|
|
|
|
what: 'selectHostsFiles',
|
|
|
|
what: 'selectHostsFiles',
|
|
|
|
switches: switches
|
|
|
|
toSelect: toSelect,
|
|
|
|
}, callback);
|
|
|
|
toImport: toImport,
|
|
|
|
|
|
|
|
toRemove: toRemove
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
callback
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hostsFilesSettingsHash = hashFromCurrentFromSettings();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
var buttonApplyHandler = function() {
|
|
|
|
var buttonApplyHandler = function() {
|
|
|
|
uDom('#buttonApply').removeClass('enabled');
|
|
|
|
uDom('#buttonApply').removeClass('enabled');
|
|
|
|
|
|
|
|
selectHostsFiles(function() {
|
|
|
|
renderBusyOverlay(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var onSelectionDone = function() {
|
|
|
|
|
|
|
|
messager.send({ what: 'reloadHostsFiles' });
|
|
|
|
messager.send({ what: 'reloadHostsFiles' });
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
renderWidgets();
|
|
|
|
selectHostsFiles(onSelectionDone);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cacheWasPurged = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
var buttonUpdateHandler = function() {
|
|
|
|
var buttonUpdateHandler = function() {
|
|
|
|
uDom('#buttonUpdate').removeClass('enabled');
|
|
|
|
uDom('#buttonUpdate').removeClass('enabled');
|
|
|
|
|
|
|
|
selectHostsFiles(function() {
|
|
|
|
if ( needUpdate ) {
|
|
|
|
document.body.classList.add('updating');
|
|
|
|
renderBusyOverlay(true);
|
|
|
|
messager.send({ what: 'forceUpdateAssets' });
|
|
|
|
|
|
|
|
renderWidgets();
|
|
|
|
var onSelectionDone = function() {
|
|
|
|
});
|
|
|
|
messager.send({ what: 'forceUpdateAssets' });
|
|
|
|
renderWidgets();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
selectHostsFiles(onSelectionDone);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cacheWasPurged = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
var buttonPurgeAllHandler = function() {
|
|
|
|
var buttonPurgeAllHandler = function() {
|
|
|
|
uDom('#buttonPurgeAll').removeClass('enabled');
|
|
|
|
uDom('#buttonPurgeAll').removeClass('enabled');
|
|
|
|
|
|
|
|
messager.send({ what: 'purgeAllCaches' }, function() {
|
|
|
|
renderBusyOverlay(true);
|
|
|
|
renderHostsFiles(true);
|
|
|
|
|
|
|
|
});
|
|
|
|
var onCompleted = function() {
|
|
|
|
|
|
|
|
cacheWasPurged = true;
|
|
|
|
|
|
|
|
renderHostsFiles();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
messager.send({ what: 'purgeAllCaches' }, onCompleted);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
@ -397,52 +366,16 @@ var autoUpdateCheckboxChanged = function() {
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
var renderExternalLists = function() {
|
|
|
|
uDom('#autoUpdate').on('change', autoUpdateCheckboxChanged);
|
|
|
|
var onReceived = function(details) {
|
|
|
|
uDom('#buttonApply').on('click', buttonApplyHandler);
|
|
|
|
uDom('#externalHostsFiles').val(details);
|
|
|
|
uDom('#buttonUpdate').on('click', buttonUpdateHandler);
|
|
|
|
externalHostsFiles = details;
|
|
|
|
uDom('#buttonPurgeAll').on('click', buttonPurgeAllHandler);
|
|
|
|
};
|
|
|
|
uDom('#lists').on('change', '.listEntry > input', onHostsFilesSettingsChanged);
|
|
|
|
messager.send({ what: 'userSettings', name: 'externalHostsFiles' }, onReceived);
|
|
|
|
uDom('#lists').on('click', '.listEntry > a.remove', onRemoveExternalHostsFile);
|
|
|
|
};
|
|
|
|
uDom('#lists').on('click', 'span.cache', onPurgeClicked);
|
|
|
|
|
|
|
|
uDom('#externalHostsFiles').on('input', onHostsFilesSettingsChanged);
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var externalListsChangeHandler = function() {
|
|
|
|
|
|
|
|
uDom('#externalListsParse').prop(
|
|
|
|
|
|
|
|
'disabled',
|
|
|
|
|
|
|
|
this.value.trim() === externalHostsFiles
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var externalListsApplyHandler = function() {
|
|
|
|
|
|
|
|
externalHostsFiles = uDom('#externalHostsFiles').val();
|
|
|
|
|
|
|
|
messager.send({
|
|
|
|
|
|
|
|
what: 'userSettings',
|
|
|
|
|
|
|
|
name: 'externalHostsFiles',
|
|
|
|
|
|
|
|
value: externalHostsFiles
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
renderHostsFiles();
|
|
|
|
|
|
|
|
uDom('#externalListsParse').prop('disabled', true);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uDom.onLoad(function() {
|
|
|
|
renderHostsFiles();
|
|
|
|
uDom('#autoUpdate').on('change', autoUpdateCheckboxChanged);
|
|
|
|
|
|
|
|
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', '.listEntry > a:nth-of-type(1)', onListLinkClicked);
|
|
|
|
|
|
|
|
uDom('#lists').on('click', 'span.purge', onPurgeClicked);
|
|
|
|
|
|
|
|
uDom('#externalHostsFiles').on('input', externalListsChangeHandler);
|
|
|
|
|
|
|
|
uDom('#externalListsParse').on('click', externalListsApplyHandler);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderHostsFiles();
|
|
|
|
|
|
|
|
renderExternalLists();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|