8.0.0 #3

Merged
wanhose merged 30 commits from v8.0.0 into main 2024-10-15 15:01:19 +00:00
Showing only changes of commit 0cb264d796 - Show all commits

View File

@ -8,9 +8,9 @@ if (typeof browser === 'undefined') {
const dispatch = browser.runtime.sendMessage;
/**
* @description Domain RegExp
* @description RegExp for matching domains
*/
const domainRx = /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/g;
const domainRegExp = /^(?!-)[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z]{2,})+$/;
/**
* @description Exclusion list, URLs where the user prefers to disable the extension
@ -58,14 +58,15 @@ function createList() {
* @returns {Promise<void>}
*/
async function handleAddClick() {
const exclusionValue = window.prompt(browser.i18n.getMessage('options_addPrompt'));
const message = browser.i18n.getMessage('options_addPrompt');
const value = window.prompt(message)?.trim().replace('www.', '');
if (exclusionValue?.trim() && (domainRx.test(exclusionValue) || exclusionValue === 'localhost')) {
if (value && (domainRegExp.test(value) || value === 'localhost')) {
const filterInputElement = document.getElementById('filter-input');
const state = { on: false };
await dispatch({ hostname: exclusionValue, state, type: 'UPDATE_STORE' });
await dispatch({ hostname: value, state, type: 'UPDATE_STORE' });
exclusionList = [...new Set([...exclusionList, exclusionValue])].sort();
exclusionList = [...new Set([...exclusionList, value])].sort();
createList();
updateList(filterInputElement.value.trim());
}
@ -169,18 +170,23 @@ function handleFileChange(event) {
const reader = new FileReader();
reader.addEventListener('load', async (event) => {
const newExclusionList = event.currentTarget.result.split('\n').filter((x) => x.trim());
const input = event.currentTarget.result.split('\n');
const exclusions = [];
for (const exclusionValue of newExclusionList) {
for (let value of input) {
value = value.replace('www.', '');
if (value && (domainRegExp.test(value) || value === 'localhost')) {
const state = { on: false };
await dispatch({ hostname: exclusionValue, state, type: 'UPDATE_STORE' });
await dispatch({ hostname: value, state, type: 'UPDATE_STORE' });
exclusions.push(value);
}
}
if (newExclusionList.length) {
exclusionList = [...new Set([...exclusionList, ...newExclusionList])].sort();
exclusionList = [...new Set([...exclusionList, ...exclusions])].sort();
createList();
updateList(filterInputElement.value.trim());
}
});
event.currentTarget.value = '';