LocalCDN-Firefox-Chrome-Brave/modules/internal/rule-generator.js

72 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-08-29 09:56:11 +02:00
/**
* Rule Generator
* Belongs to LocalCDN (since 2020-02-26)
*
* @author nobody
* @since 2020-03-08
*
* @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';
2021-02-17 07:01:08 +01:00
2020-08-29 09:56:11 +02:00
/**
* Updates
*/
var ruleGenerator = {};
2021-02-17 07:01:08 +01:00
2020-08-29 09:56:11 +02:00
/**
* Public Methods
*/
2021-02-17 07:01:08 +01:00
ruleGenerator.openRuleSet = function ({target}) {
2020-11-08 21:21:53 +01:00
let urls, key, textArea, btnCopy, content;
2020-08-29 09:56:11 +02:00
2020-11-08 21:55:40 +01:00
urls = mappings.cdn;
2021-02-21 19:28:18 +01:00
key = target.getAttribute('data-ruleset');
2020-11-08 21:21:53 +01:00
textArea = document.getElementById('generated-rules');
btnCopy = document.getElementById('button-copy-rule-set');
content = '';
2020-08-29 09:56:11 +02:00
textArea.style.display = 'block';
btnCopy.style.display = 'block';
if (!BrowserType.FIREFOX) {
delete urls['fonts.googleapis.com'];
delete urls['fonts.gstatic.com'];
}
2021-02-17 07:01:08 +01:00
for (const domain in urls) {
2020-08-29 09:56:11 +02:00
if (key === 'uMatrix') {
2021-02-17 07:01:08 +01:00
content += `* ${domain} script allow\n`;
content += `* ${domain} css allow\n`;
2020-08-29 09:56:11 +02:00
} else if (key === 'uBlock') {
2021-02-17 07:01:08 +01:00
content += `* ${domain} * noop\n`;
2020-09-13 07:42:28 +02:00
} else if (key === 'AdGuard') {
2021-02-17 07:01:08 +01:00
content += `@@||${domain}^\n`;
2021-06-07 06:39:55 +02:00
} else if (key === 'NoScript') {
2022-04-04 06:17:40 +02:00
content += `"§:${domain}",\n`;
2020-08-29 09:56:11 +02:00
}
}
textArea.value = content.replace(/\n+$/, '');
};
ruleGenerator.copyRuleSet = function () {
let textArea = document.getElementById('generated-rules');
navigator.clipboard.writeText(textArea.value).then(
function () {
textArea.select();
},
function () {
alert('Rule set cannot be copied!');
}
);
};