|
|
@ -145,22 +145,23 @@ var renderHostsFiles = function(soft) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let ulList = document.querySelector(listSelector),
|
|
|
|
let ulList = document.querySelector(listSelector),
|
|
|
|
liImport = ulList.querySelector('.importURL');
|
|
|
|
liLast = ulList.querySelector('.notAnAsset');
|
|
|
|
if ( liImport.parentNode !== null ) {
|
|
|
|
|
|
|
|
liImport.parentNode.removeChild(liImport);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( let i = 0; i < assetKeys.length; i++ ) {
|
|
|
|
for ( let i = 0; i < assetKeys.length; i++ ) {
|
|
|
|
let liEntry = liFromListEntry(
|
|
|
|
let liReuse = i < ulList.childElementCount ?
|
|
|
|
collection,
|
|
|
|
ulList.children[i] :
|
|
|
|
assetKeys[i],
|
|
|
|
null;
|
|
|
|
ulList.children[i]
|
|
|
|
if (
|
|
|
|
);
|
|
|
|
liReuse !== null &&
|
|
|
|
|
|
|
|
liReuse.classList.contains('notAnAsset')
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
liReuse = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let liEntry = liFromListEntry(collection, assetKeys[i], liReuse);
|
|
|
|
if ( liEntry.parentElement === null ) {
|
|
|
|
if ( liEntry.parentElement === null ) {
|
|
|
|
ulList.appendChild(liEntry);
|
|
|
|
ulList.insertBefore(liEntry, liLast);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ulList.appendChild(liImport);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var onAssetDataReceived = function(details) {
|
|
|
|
var onAssetDataReceived = function(details) {
|
|
|
@ -171,9 +172,14 @@ var renderHostsFiles = function(soft) {
|
|
|
|
// Before all, set context vars
|
|
|
|
// Before all, set context vars
|
|
|
|
listDetails = details;
|
|
|
|
listDetails = details;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.body.classList.toggle(
|
|
|
|
|
|
|
|
'contributor',
|
|
|
|
|
|
|
|
listDetails.contributor === true
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// Incremental rendering: this will allow us to easily discard unused
|
|
|
|
// Incremental rendering: this will allow us to easily discard unused
|
|
|
|
// DOM list entries.
|
|
|
|
// DOM list entries.
|
|
|
|
uDom('#hosts .listEntry:not(.importURL)').addClass('discard');
|
|
|
|
uDom('#hosts .listEntry:not(.notAnAsset)').addClass('discard');
|
|
|
|
|
|
|
|
|
|
|
|
onRenderAssetFiles(details.hosts, '#hosts');
|
|
|
|
onRenderAssetFiles(details.hosts, '#hosts');
|
|
|
|
onRenderAssetFiles(details.recipes, '#recipes');
|
|
|
|
onRenderAssetFiles(details.recipes, '#recipes');
|
|
|
@ -188,6 +194,12 @@ var renderHostsFiles = function(soft) {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
uDom('#autoUpdate').prop('checked', listDetails.autoUpdate === true);
|
|
|
|
uDom('#autoUpdate').prop('checked', listDetails.autoUpdate === true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uDom.nodeFromSelector('#recipes .toInline > input[type="checkbox"]').checked =
|
|
|
|
|
|
|
|
listDetails.userRecipes.enabled === true;
|
|
|
|
|
|
|
|
uDom.nodeFromSelector('#recipes .toInline > textarea').value =
|
|
|
|
|
|
|
|
listDetails.userRecipes.content;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( !soft ) {
|
|
|
|
if ( !soft ) {
|
|
|
|
hostsFilesSettingsHash = hashFromCurrentFromSettings();
|
|
|
|
hostsFilesSettingsHash = hashFromCurrentFromSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -231,31 +243,50 @@ var updateAssetStatus = function(details) {
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
/*******************************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
Compute a hash from all the settings affecting how filter lists are loaded
|
|
|
|
Compute a hash from all the settings affecting how assets are loaded
|
|
|
|
in memory.
|
|
|
|
in memory.
|
|
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
|
|
var hashFromCurrentFromSettings = function() {
|
|
|
|
var hashFromCurrentFromSettings = function() {
|
|
|
|
var hash = [],
|
|
|
|
let listHash = [],
|
|
|
|
listHash = [],
|
|
|
|
listEntries = document.querySelectorAll(
|
|
|
|
listEntries = document.querySelectorAll('.assets .listEntry[data-listkey]:not(.toRemove)'),
|
|
|
|
'.assets .listEntry[data-listkey]:not(.toRemove)'
|
|
|
|
i = listEntries.length;
|
|
|
|
);
|
|
|
|
while ( i-- ) {
|
|
|
|
for ( let liEntry of listEntries ) {
|
|
|
|
let liEntry = listEntries[i];
|
|
|
|
|
|
|
|
if ( liEntry.querySelector('input[type="checkbox"]:checked') !== null ) {
|
|
|
|
if ( liEntry.querySelector('input[type="checkbox"]:checked') !== null ) {
|
|
|
|
listHash.push(liEntry.getAttribute('data-listkey'));
|
|
|
|
listHash.push(liEntry.getAttribute('data-listkey'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let textarea1 = document.querySelector('.assets .importURL > input[type="checkbox"]:checked ~ textarea');
|
|
|
|
return [
|
|
|
|
let textarea2 = document.querySelector('#recipes .importURL > input[type="checkbox"]:checked ~ textarea');
|
|
|
|
listHash.join(),
|
|
|
|
hash.push(
|
|
|
|
document.querySelector('.listEntry.toRemove') !== null,
|
|
|
|
listHash.sort().join(),
|
|
|
|
reValidExternalList.test(
|
|
|
|
textarea1 !== null && reValidExternalList.test(textarea1.value),
|
|
|
|
textFromTextarea(
|
|
|
|
textarea2 !== null && reValidExternalList.test(textarea2.value),
|
|
|
|
'#hosts .toImport > input[type="checkbox"]:checked ~ textarea'
|
|
|
|
document.querySelector('.listEntry.toRemove') !== null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
),
|
|
|
|
return hash.join();
|
|
|
|
textFromTextarea(
|
|
|
|
|
|
|
|
'#hosts .toInline > input[type="checkbox"]:checked ~ textarea'
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
reValidExternalList.test(
|
|
|
|
|
|
|
|
textFromTextarea(
|
|
|
|
|
|
|
|
'#recipes .toImport > input[type="checkbox"]:checked ~ textarea'
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
textFromTextarea(
|
|
|
|
|
|
|
|
'#recipes .toInline > input[type="checkbox"]:checked ~ textarea'
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var textFromTextarea = function(textarea) {
|
|
|
|
|
|
|
|
if ( typeof textarea === 'string' ) {
|
|
|
|
|
|
|
|
textarea = document.querySelector(textarea);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return textarea !== null ? textarea.value.trim() : '';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
@ -300,36 +331,44 @@ var selectAssets = function(callback) {
|
|
|
|
var out = {
|
|
|
|
var out = {
|
|
|
|
toSelect: [],
|
|
|
|
toSelect: [],
|
|
|
|
toImport: '',
|
|
|
|
toImport: '',
|
|
|
|
toRemove: []
|
|
|
|
toRemove: [],
|
|
|
|
|
|
|
|
toInline: {
|
|
|
|
|
|
|
|
enabled: false,
|
|
|
|
|
|
|
|
content: ''
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let root = document.querySelector(listSelector);
|
|
|
|
let root = document.querySelector(listSelector);
|
|
|
|
|
|
|
|
|
|
|
|
let liEntries = root.querySelectorAll('.listEntry[data-listkey]:not(.toRemove)'),
|
|
|
|
// Lists to select or remove
|
|
|
|
i = liEntries.length;
|
|
|
|
let liEntries = root.querySelectorAll(
|
|
|
|
while ( i-- ) {
|
|
|
|
'.listEntry[data-listkey]:not(.notAnAsset)'
|
|
|
|
let liEntry = liEntries[i];
|
|
|
|
);
|
|
|
|
if ( liEntry.querySelector('input[type="checkbox"]:checked') !== null ) {
|
|
|
|
for ( let liEntry of liEntries ) {
|
|
|
|
|
|
|
|
if ( liEntry.classList.contains('toRemove') ) {
|
|
|
|
|
|
|
|
out.toRemove.push(liEntry.getAttribute('data-listkey'));
|
|
|
|
|
|
|
|
} else if ( liEntry.querySelector('input[type="checkbox"]:checked') ) {
|
|
|
|
out.toSelect.push(liEntry.getAttribute('data-listkey'));
|
|
|
|
out.toSelect.push(liEntry.getAttribute('data-listkey'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// External hosts files to remove
|
|
|
|
|
|
|
|
liEntries = root.querySelectorAll('.listEntry.toRemove[data-listkey]');
|
|
|
|
|
|
|
|
i = liEntries.length;
|
|
|
|
|
|
|
|
while ( i-- ) {
|
|
|
|
|
|
|
|
out.toRemove.push(liEntries[i].getAttribute('data-listkey'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// External hosts files to import
|
|
|
|
// External hosts files to import
|
|
|
|
let input = root.querySelector('.importURL > input[type="checkbox"]:checked');
|
|
|
|
let input = root.querySelector(
|
|
|
|
|
|
|
|
'.toImport > input[type="checkbox"]:checked'
|
|
|
|
|
|
|
|
);
|
|
|
|
if ( input !== null ) {
|
|
|
|
if ( input !== null ) {
|
|
|
|
let textarea = root.querySelector('.importURL textarea');
|
|
|
|
let textarea = root.querySelector('.toImport textarea');
|
|
|
|
out.toImport = textarea.value.trim();
|
|
|
|
out.toImport = textarea.value.trim();
|
|
|
|
textarea.value = '';
|
|
|
|
textarea.value = '';
|
|
|
|
input.checked = false;
|
|
|
|
input.checked = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Inline data
|
|
|
|
|
|
|
|
out.toInline.enabled = root.querySelector(
|
|
|
|
|
|
|
|
'.toInline > input[type="checkbox"]:checked'
|
|
|
|
|
|
|
|
) !== null;
|
|
|
|
|
|
|
|
out.toInline.content = textFromTextarea('.toInline > textarea');
|
|
|
|
|
|
|
|
|
|
|
|
return out;
|
|
|
|
return out;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -406,7 +445,7 @@ uDom('#buttonApply').on('click', buttonApplyHandler);
|
|
|
|
uDom('#buttonUpdate').on('click', buttonUpdateHandler);
|
|
|
|
uDom('#buttonUpdate').on('click', buttonUpdateHandler);
|
|
|
|
uDom('#buttonPurgeAll').on('click', buttonPurgeAllHandler);
|
|
|
|
uDom('#buttonPurgeAll').on('click', buttonPurgeAllHandler);
|
|
|
|
uDom('.assets').on('change', '.listEntry > input', onHostsFilesSettingsChanged);
|
|
|
|
uDom('.assets').on('change', '.listEntry > input', onHostsFilesSettingsChanged);
|
|
|
|
uDom('.assets').on('input', '.listEntry.importURL textarea', onHostsFilesSettingsChanged);
|
|
|
|
uDom('.assets').on('input', '.listEntry > textarea', onHostsFilesSettingsChanged);
|
|
|
|
uDom('.assets').on('click', '.listEntry > a.remove', onRemoveExternalAsset);
|
|
|
|
uDom('.assets').on('click', '.listEntry > a.remove', onRemoveExternalAsset);
|
|
|
|
uDom('.assets').on('click', 'span.cache', onPurgeClicked);
|
|
|
|
uDom('.assets').on('click', 'span.cache', onPurgeClicked);
|
|
|
|
|
|
|
|
|
|
|
|