2020-03-08 12:30:03 +01:00
|
|
|
|
/**
|
|
|
|
|
* Main Updates Page
|
2020-06-30 18:41:58 +02:00
|
|
|
|
* Belongs to LocalCDN (since 2020-02-26)
|
|
|
|
|
* (Origin: Decentraleyes)
|
2020-03-08 12:30:03 +01:00
|
|
|
|
*
|
2020-06-30 18:41:58 +02:00
|
|
|
|
* @author nobody
|
2020-03-08 12:30:03 +01:00
|
|
|
|
* @since 2020-03-08
|
2020-06-30 18:41:58 +02:00
|
|
|
|
*
|
2020-03-08 12:30:03 +01:00
|
|
|
|
* @license MPL 2.0
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
var updates = {};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Private Methods
|
|
|
|
|
*/
|
2020-08-13 08:07:04 +02:00
|
|
|
|
updates._openRuleSet = function ({ target }) {
|
2020-07-09 20:55:05 +02:00
|
|
|
|
let urls = mappings;
|
|
|
|
|
let updateKey = target.getAttribute('data-option');
|
|
|
|
|
|
2020-08-13 08:07:04 +02:00
|
|
|
|
let textArea = document.getElementById('generated-rules');
|
|
|
|
|
let btnCopy = document.getElementById('button-copy-rule-set');
|
2020-07-09 20:55:05 +02:00
|
|
|
|
|
2020-08-13 08:07:04 +02:00
|
|
|
|
let content = '';
|
2020-07-09 20:55:05 +02:00
|
|
|
|
|
2020-08-13 08:07:04 +02:00
|
|
|
|
textArea.style.display = 'block';
|
|
|
|
|
btnCopy.style.display = 'block';
|
2020-07-09 20:55:05 +02:00
|
|
|
|
|
|
|
|
|
for (var domain in urls) {
|
2020-08-13 08:07:04 +02:00
|
|
|
|
if (updateKey === 'uMatrix') {
|
|
|
|
|
content += '* ' + domain + ' script allow' + '\n';
|
|
|
|
|
content += '* ' + domain + ' css allow' + '\n';
|
|
|
|
|
} else if (updateKey === 'uBlock') {
|
|
|
|
|
content += '* ' + domain + ' * noop' + '\n';
|
2020-07-09 20:55:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-13 08:07:04 +02:00
|
|
|
|
textArea.value = content.replace(/\n+$/, '');
|
2020-07-09 20:55:05 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-08-13 08:07:04 +02:00
|
|
|
|
updates._copyRuleSet = function () {
|
|
|
|
|
let textArea = document.getElementById('generated-rules');
|
|
|
|
|
navigator.clipboard.writeText(textArea.value).then(
|
|
|
|
|
function () {
|
|
|
|
|
textArea.select();
|
|
|
|
|
},
|
|
|
|
|
function () {
|
|
|
|
|
alert('Rule set cannot be copied!');
|
|
|
|
|
}
|
|
|
|
|
);
|
2020-07-09 20:55:05 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-08-13 08:07:04 +02:00
|
|
|
|
updates._openHistoryReleaseNotes = function () {
|
2020-07-09 20:55:05 +02:00
|
|
|
|
let container = document.getElementById('history-release-notes');
|
|
|
|
|
let toggle = document.getElementById('history-indicator');
|
|
|
|
|
|
|
|
|
|
if (container.style.display === 'none') {
|
|
|
|
|
container.style.display = 'block';
|
|
|
|
|
toggle.textContent = '–';
|
|
|
|
|
} else {
|
|
|
|
|
container.style.display = 'none';
|
|
|
|
|
toggle.textContent = '+';
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
updates._onDocumentLoaded = function () {
|
|
|
|
|
document.getElementById('generate-ublock-rules').checked = false;
|
|
|
|
|
document.getElementById('generate-umatrix-rules').checked = false;
|
|
|
|
|
|
|
|
|
|
let updateElements = {
|
2020-08-13 08:07:04 +02:00
|
|
|
|
['ruleSets']: document.getElementsByName('rule-sets'),
|
|
|
|
|
['copyRuleSet']: document.getElementById('button-copy-rule-set'),
|
2020-07-09 20:55:05 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-08-13 08:07:04 +02:00
|
|
|
|
for (let i = 0; i < updateElements.ruleSets.length; i++) {
|
2020-07-09 20:55:05 +02:00
|
|
|
|
updateElements.ruleSets[i].addEventListener('change', updates._openRuleSet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateElements.copyRuleSet.addEventListener('click', updates._copyRuleSet);
|
|
|
|
|
|
|
|
|
|
document.getElementById('history').addEventListener('click', updates._openHistoryReleaseNotes);
|
2020-07-24 08:16:25 +02:00
|
|
|
|
|
|
|
|
|
// GET parameter to display the rule set generator
|
|
|
|
|
let urlParams = new URLSearchParams(window.location.search);
|
|
|
|
|
if (urlParams.get('mappingupdate') === 'true') {
|
|
|
|
|
document.getElementById('generator-section').style.display = 'block';
|
|
|
|
|
}
|
2020-07-09 20:55:05 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-03-08 12:30:03 +01:00
|
|
|
|
document.addEventListener('DOMContentLoaded', updates._onDocumentLoaded);
|