mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2024-11-27 20:03:45 +03:00
Keep objects in mods.in/ex(cluded). Refactor
This commit is contained in:
parent
e95c186de1
commit
ccda45a57c
|
@ -298,18 +298,20 @@
|
||||||
self.included = [];
|
self.included = [];
|
||||||
self.excluded = [];
|
self.excluded = [];
|
||||||
for(const host of Object.keys(self.exceptions)) {
|
for(const host of Object.keys(self.exceptions)) {
|
||||||
if (self.exceptions[host]?.ifIncluded) {
|
const ifProxy = self.exceptions[host]?.ifProxy || false;
|
||||||
self.included.push(host);
|
const ifWild = self.exceptions[host]?.ifWild || false;
|
||||||
|
if (ifProxy) {
|
||||||
|
self.included.push([host, ifWild]);
|
||||||
} else {
|
} else {
|
||||||
self.excluded.push(host);
|
self.excluded.push([host, ifWild]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
['included', 'excluded'].forEach((who) => {
|
['included', 'excluded'].forEach((who) => {
|
||||||
|
|
||||||
self[who] = self[who]
|
self[who] = self[who]
|
||||||
.map( (s) => s.split('').reverse() )
|
.map( ([domain, ifWild]) => [domain.split('').reverse(), ifWild] )
|
||||||
.sort()
|
.sort()
|
||||||
.map( (a) => a.reverse().join('') );
|
.map( ([rDomain, ifWild]) => [rDomain.reverse().join(''), ifWild] );
|
||||||
|
|
||||||
});
|
});
|
||||||
if (self.included.length && !self.filteredCustomsString) {
|
if (self.included.length && !self.filteredCustomsString) {
|
||||||
|
@ -390,7 +392,7 @@
|
||||||
if (pacMods.ifProxyMoreDomains) {
|
if (pacMods.ifProxyMoreDomains) {
|
||||||
finalExceptions = pacMods.moreDomains.reduce((acc, tld) => {
|
finalExceptions = pacMods.moreDomains.reduce((acc, tld) => {
|
||||||
|
|
||||||
acc[tld] = { ifIncluded: true, ifWild: true };
|
acc[tld] = { ifProxy: true, ifWild: true };
|
||||||
return acc;
|
return acc;
|
||||||
|
|
||||||
}, finalExceptions);
|
}, finalExceptions);
|
||||||
|
@ -406,7 +408,7 @@
|
||||||
/******/ /* EXCEPTIONS START */
|
/******/ /* EXCEPTIONS START */
|
||||||
/******/ const dotHost = '.' + host;
|
/******/ const dotHost = '.' + host;
|
||||||
/******/ const isHostInDomain = (domain) => dotHost.endsWith('.' + domain);
|
/******/ const isHostInDomain = (domain) => dotHost.endsWith('.' + domain);
|
||||||
/******/ const domainReducer = (maxWeight, [domain, { ifIncluded, ifWild }]) => {
|
/******/ const domainReducer = (maxWeight, [domain, { ifProxy, ifWild }]) => {
|
||||||
/******/
|
/******/
|
||||||
/******/ if (!isHostInDomain(domain)) {
|
/******/ if (!isHostInDomain(domain)) {
|
||||||
/******/ return maxWeight;
|
/******/ return maxWeight;
|
||||||
|
@ -415,7 +417,7 @@
|
||||||
/******/ if (newWeightAbs < Math.abs(maxWeight)) {
|
/******/ if (newWeightAbs < Math.abs(maxWeight)) {
|
||||||
/******/ return maxWeight;
|
/******/ return maxWeight;
|
||||||
/******/ }
|
/******/ }
|
||||||
/******/ return newWeightAbs*(ifIncluded ? 1 : -1);
|
/******/ return newWeightAbs*(ifProxy ? 1 : -1);
|
||||||
/******/
|
/******/
|
||||||
/******/ };
|
/******/ };
|
||||||
/******/
|
/******/
|
||||||
|
|
|
@ -110,7 +110,7 @@ export default function getExcEditor(theState) {
|
||||||
|
|
||||||
isHostValid(host) {
|
isHostValid(host) {
|
||||||
|
|
||||||
const ValidHostnameRegex = /^(?:\*\.)?(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/;
|
const ValidHostnameRegex = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/;
|
||||||
if(!ValidHostnameRegex.test(host)) {
|
if(!ValidHostnameRegex.test(host)) {
|
||||||
this.props.funs.showErrors(new TypeError('Должно быть только доменное имя, без протокола, порта и пути. Попробуйте ещё раз.'));
|
this.props.funs.showErrors(new TypeError('Должно быть только доменное имя, без протокола, порта и пути. Попробуйте ещё раз.'));
|
||||||
return false;
|
return false;
|
||||||
|
@ -122,6 +122,8 @@ export default function getExcEditor(theState) {
|
||||||
handleRadioClick(event) {
|
handleRadioClick(event) {
|
||||||
|
|
||||||
let host = this.state.trimmedInputValueOrSpace;
|
let host = this.state.trimmedInputValueOrSpace;
|
||||||
|
const ifWild = host.startsWith('*.');
|
||||||
|
host = host.replace(/^\*\./g, '');
|
||||||
(() => { // `return` === `preventDefault`.
|
(() => { // `return` === `preventDefault`.
|
||||||
|
|
||||||
if(!this.isHostValid(host)) {
|
if(!this.isHostValid(host)) {
|
||||||
|
@ -147,8 +149,7 @@ export default function getExcEditor(theState) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ifWild = host.startsWith('*.');
|
pacMods.exceptions[host] = { ifProxy: ifYesClicked, ifWild };
|
||||||
pacMods.exceptions[host.replace(/^\*\./g, '')] = { ifIncluded: ifYesClicked, ifWild };
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -293,7 +294,7 @@ export default function getExcEditor(theState) {
|
||||||
if ( acc !== undefined ) {
|
if ( acc !== undefined ) {
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
return this.state.trimmedInputValueOrSpace === excHost ? excState : undefined;
|
return this.state.trimmedInputValueOrSpace === excHost ? (excState || {}).ifProxy : undefined;
|
||||||
|
|
||||||
}, undefined);
|
}, undefined);
|
||||||
|
|
||||||
|
@ -322,9 +323,10 @@ export default function getExcEditor(theState) {
|
||||||
|
|
||||||
// 1. Option's value may be changed to hide it from the tooltip.
|
// 1. Option's value may be changed to hide it from the tooltip.
|
||||||
// 2. Space is used in matching so even an empty input (replaced with space) has tooltip with prompts.
|
// 2. Space is used in matching so even an empty input (replaced with space) has tooltip with prompts.
|
||||||
|
const ifProxy = (excState || {}).ifProxy;
|
||||||
return <option
|
return <option
|
||||||
value={ this.state.ifHostHiddenMap[excHost] ? '\n' : excHost + ' ' }
|
value={ this.state.ifHostHiddenMap[excHost] ? '\n' : excHost + ' ' }
|
||||||
label={ excState === true ? labelIfProxied : (excState === false ? labelIfNotProxied : labelIfAuto) }/>
|
label={ ifProxy === true ? labelIfProxied : (ifProxy === false ? labelIfNotProxied : labelIfAuto) }/>
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user