mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2025-01-31 20:04:11 +03:00
Merge branch 'development' into production
This commit is contained in:
commit
422de472dd
|
@ -298,7 +298,8 @@
|
||||||
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]) {
|
const ifProxy = self.exceptions[host] || false;
|
||||||
|
if (ifProxy) {
|
||||||
self.included.push(host);
|
self.included.push(host);
|
||||||
} else {
|
} else {
|
||||||
self.excluded.push(host);
|
self.excluded.push(host);
|
||||||
|
@ -307,9 +308,9 @@
|
||||||
['included', 'excluded'].forEach((who) => {
|
['included', 'excluded'].forEach((who) => {
|
||||||
|
|
||||||
self[who] = self[who]
|
self[who] = self[who]
|
||||||
.map( (s) => s.split('').reverse() )
|
.map( (domain) => domain.split('').reverse() )
|
||||||
.sort()
|
.sort()
|
||||||
.map( (a) => a.reverse().join('') );
|
.map( (rDomain) => rDomain.reverse().join('') );
|
||||||
|
|
||||||
});
|
});
|
||||||
if (self.included.length && !self.filteredCustomsString) {
|
if (self.included.length && !self.filteredCustomsString) {
|
||||||
|
@ -386,11 +387,11 @@
|
||||||
const ifIncluded = pacMods.included && pacMods.included.length;
|
const ifIncluded = pacMods.included && pacMods.included.length;
|
||||||
const ifExcluded = pacMods.excluded && pacMods.excluded.length;
|
const ifExcluded = pacMods.excluded && pacMods.excluded.length;
|
||||||
const ifManualExceptions = ifIncluded || ifExcluded;
|
const ifManualExceptions = ifIncluded || ifExcluded;
|
||||||
const finalExceptions = {};
|
let finalExceptions = {};
|
||||||
if (pacMods.ifProxyMoreDomains) {
|
if (pacMods.ifProxyMoreDomains) {
|
||||||
pacMods.moreDomains.reduce((acc, tld) => {
|
finalExceptions = pacMods.moreDomains.reduce((acc, tld) => {
|
||||||
|
|
||||||
acc[tld] = true;
|
acc['*.' + tld] = true;
|
||||||
return acc;
|
return acc;
|
||||||
|
|
||||||
}, finalExceptions);
|
}, finalExceptions);
|
||||||
|
@ -405,17 +406,30 @@
|
||||||
/******/
|
/******/
|
||||||
/******/ /* EXCEPTIONS START */
|
/******/ /* EXCEPTIONS START */
|
||||||
/******/ const dotHost = '.' + host;
|
/******/ const dotHost = '.' + host;
|
||||||
/******/ const isHostInDomain = (domain) => dotHost.endsWith('.' + domain);
|
// TODO: handle wildcards.
|
||||||
/******/ const domainReducer = (maxWeight, [domain, ifIncluded]) => {
|
/******/ const isHostInDomain = (domain, ifWild) => {
|
||||||
|
if (ifWild) {
|
||||||
|
return dotHost.endsWith(domain.substr(1));
|
||||||
|
}
|
||||||
|
return domain === host;
|
||||||
|
}
|
||||||
|
/******/ const domainReducer = (maxWeight, [domain, ifProxy]) => {
|
||||||
/******/
|
/******/
|
||||||
/******/ if (!isHostInDomain(domain)) {
|
const ifWild = domain.startsWith('*.');
|
||||||
|
/******/ if (!isHostInDomain(domain, ifWild)) {
|
||||||
/******/ return maxWeight;
|
/******/ return maxWeight;
|
||||||
/******/ }
|
/******/ }
|
||||||
/******/ const newWeightAbs = domain.length;
|
let len = domain.length;
|
||||||
|
if (ifWild) {
|
||||||
|
len = len === 0 ? len : (len - 2)*2 - 1;
|
||||||
|
} else {
|
||||||
|
len = len*2;
|
||||||
|
}
|
||||||
|
/******/ const newWeightAbs = len;
|
||||||
/******/ if (newWeightAbs < Math.abs(maxWeight)) {
|
/******/ if (newWeightAbs < Math.abs(maxWeight)) {
|
||||||
/******/ return maxWeight;
|
/******/ return maxWeight;
|
||||||
/******/ }
|
/******/ }
|
||||||
/******/ return newWeightAbs*(ifIncluded ? 1 : -1);
|
/******/ return newWeightAbs*(ifProxy ? 1 : -1);
|
||||||
/******/
|
/******/
|
||||||
/******/ };
|
/******/ };
|
||||||
/******/
|
/******/
|
||||||
|
|
|
@ -525,16 +525,41 @@
|
||||||
|
|
||||||
// ON EACH LAUNCH, STARTUP, RELOAD, UPDATE, ENABLE
|
// ON EACH LAUNCH, STARTUP, RELOAD, UPDATE, ENABLE
|
||||||
(async () => {
|
(async () => {
|
||||||
let oldStorage = await window.utils.promisedLocalStorage.get('antiCensorRu') || {};
|
let oldAntiCensorRu = await window.utils.promisedLocalStorage.get('antiCensorRu') || {};
|
||||||
|
|
||||||
if (!Object.keys(oldStorage).length) {
|
const otherKeys = [
|
||||||
|
'pac-kitchen-if-incontinence',
|
||||||
|
'pac-kitchen-mods',
|
||||||
|
'ip-to-host',
|
||||||
|
'handlers-pac-error',
|
||||||
|
'handlers-ext-error',
|
||||||
|
'handlers-no-control',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!Object.keys(oldAntiCensorRu).length) {
|
||||||
const storage = await window.utils.promisedLocalStorage.get(null);
|
const storage = await window.utils.promisedLocalStorage.get(null);
|
||||||
if (storage.version && window.apis.version.isLeq(storage.version, '0.0.1.48')) {
|
if (storage.version && window.apis.version.isLeq(storage.version, '0.0.1.48')) {
|
||||||
const ffxPacData = storage['firefox-only-pac-data'];
|
const ffxPacData = storage['firefox-only-pac-data'];
|
||||||
delete storage['firefox-only-pac-data'];
|
delete storage['firefox-only-pac-data'];
|
||||||
await window.utils.promisedLocalStorage.clear();
|
await window.utils.promisedLocalStorage.clear();
|
||||||
|
for(const key of otherKeys) {
|
||||||
|
await window.utils.promisedLocalStorage.set({ [key]: storage[key] });
|
||||||
|
delete storage[key];
|
||||||
|
}
|
||||||
await window.utils.promisedLocalStorage.set({ antiCensorRu: storage });
|
await window.utils.promisedLocalStorage.set({ antiCensorRu: storage });
|
||||||
oldStorage = storage;
|
oldAntiCensorRu = storage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (oldAntiCensorRu.version && window.apis.version.isLeq(oldAntiCensorRu.version, '0.0.1.49')) {
|
||||||
|
const modsMutated = window.apis.pacKitchen.getPacModsRaw();
|
||||||
|
if (modsMutated) {
|
||||||
|
modsMutated.exceptions = Object.entries(modsMutated.exceptions).reduce((acc, [host, ifProxy]) => {
|
||||||
|
acc[\`*.\${host}\`] = ifProxy;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
await new Promise(
|
||||||
|
(resolve) => window.apis.pacKitchen.keepCookedNowAsync(modsMutated, resolve),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,8 +596,8 @@
|
||||||
console.log('Keep cooked...');
|
console.log('Keep cooked...');
|
||||||
await new Promise((resolve) => window.apis.pacKitchen.keepCookedNowAsync(resolve));
|
await new Promise((resolve) => window.apis.pacKitchen.keepCookedNowAsync(resolve));
|
||||||
|
|
||||||
//console.log('Storage on init:', oldStorage);
|
//console.log('Storage on init:', oldAntiCensorRu);
|
||||||
antiCensorRu.ifFirstInstall = Object.keys(oldStorage).length === 0;
|
antiCensorRu.ifFirstInstall = Object.keys(oldAntiCensorRu).length === 0;
|
||||||
|
|
||||||
if (antiCensorRu.ifFirstInstall) {
|
if (antiCensorRu.ifFirstInstall) {
|
||||||
// INSTALL
|
// INSTALL
|
||||||
|
@ -585,11 +610,11 @@
|
||||||
// LAUNCH, RELOAD, UPDATE
|
// LAUNCH, RELOAD, UPDATE
|
||||||
// Use old or migrate to default.
|
// Use old or migrate to default.
|
||||||
antiCensorRu._currentPacProviderKey =
|
antiCensorRu._currentPacProviderKey =
|
||||||
oldStorage._currentPacProviderKey || null;
|
oldAntiCensorRu._currentPacProviderKey || null;
|
||||||
antiCensorRu.lastPacUpdateStamp =
|
antiCensorRu.lastPacUpdateStamp =
|
||||||
oldStorage.lastPacUpdateStamp || antiCensorRu.lastPacUpdateStamp;
|
oldAntiCensorRu.lastPacUpdateStamp || antiCensorRu.lastPacUpdateStamp;
|
||||||
antiCensorRu._currentPacProviderLastModified =
|
antiCensorRu._currentPacProviderLastModified =
|
||||||
oldStorage._currentPacProviderLastModified
|
oldAntiCensorRu._currentPacProviderLastModified
|
||||||
|| antiCensorRu._currentPacProviderLastModified;
|
|| antiCensorRu._currentPacProviderLastModified;
|
||||||
console.log(
|
console.log(
|
||||||
'Last PAC update was on',
|
'Last PAC update was on',
|
||||||
|
@ -607,11 +632,11 @@
|
||||||
|
|
||||||
await new Promise(async (resolve) => {
|
await new Promise(async (resolve) => {
|
||||||
|
|
||||||
const ifUpdating = antiCensorRu.version !== oldStorage.version;
|
const ifUpdating = antiCensorRu.version !== oldAntiCensorRu.version;
|
||||||
if (!ifUpdating) {
|
if (!ifUpdating) {
|
||||||
|
|
||||||
// LAUNCH, RELOAD, ENABLE
|
// LAUNCH, RELOAD, ENABLE
|
||||||
antiCensorRu.pacProviders = oldStorage.pacProviders;
|
antiCensorRu.pacProviders = oldAntiCensorRu.pacProviders;
|
||||||
console.log('Extension launched, reloaded or enabled.');
|
console.log('Extension launched, reloaded or enabled.');
|
||||||
return resolve();
|
return resolve();
|
||||||
|
|
||||||
|
@ -626,9 +651,9 @@
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Updating from', oldStorage.version, 'to', antiCensorRu.version);
|
console.log('Updating from', oldAntiCensorRu.version, 'to', antiCensorRu.version);
|
||||||
try {
|
try {
|
||||||
if (window.apis.version.isLeq(oldStorage.version, '0.0.1.5')) {
|
if (window.apis.version.isLeq(oldAntiCensorRu.version, '0.0.1.5')) {
|
||||||
|
|
||||||
// Change semicolons to semicolons followed by newlines in proxy string (raw).
|
// Change semicolons to semicolons followed by newlines in proxy string (raw).
|
||||||
const migrateProxies = (oldStr) => oldStr.replace(/;\\r?\\n?/g, ';\\n');
|
const migrateProxies = (oldStr) => oldStr.replace(/;\\r?\\n?/g, ';\\n');
|
||||||
|
@ -641,7 +666,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (window.apis.version.isLeq(oldStorage.version, '0.0.1.25')) {
|
if (window.apis.version.isLeq(oldAntiCensorRu.version, '0.0.1.25')) {
|
||||||
|
|
||||||
console.log('Switch to Antizapret automatically, only from Anitcensority without own proxies.');
|
console.log('Switch to Antizapret automatically, only from Anitcensority without own proxies.');
|
||||||
const provKey = antiCensorRu.getCurrentPacProviderKey();
|
const provKey = antiCensorRu.getCurrentPacProviderKey();
|
||||||
|
|
|
@ -79,14 +79,14 @@ export default function getExcEditor(theState) {
|
||||||
props.currentTab &&
|
props.currentTab &&
|
||||||
props.currentTab.url &&
|
props.currentTab.url &&
|
||||||
!props.currentTab.url.startsWith('chrome')
|
!props.currentTab.url.startsWith('chrome')
|
||||||
? new URL(props.currentTab.url).hostname.replace(/^www\./g, '')
|
? '*.' + (new URL(props.currentTab.url).hostname.replace(/^www\./g, ''))
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
const pacMods = props.apis.pacKitchen.getPacMods();
|
const pacMods = props.apis.pacKitchen.getPacMods();
|
||||||
this.state = {
|
this.state = {
|
||||||
trimmedInputValueOrSpace,
|
trimmedInputValueOrSpace,
|
||||||
sortedListOfOptions: this.modsToOpts(pacMods),
|
sortedListOfOptions: this.modsToOpts(pacMods),
|
||||||
isHostHidden: {}
|
hostToIfHidden: {},
|
||||||
};
|
};
|
||||||
this.handleRadioClick = this.handleRadioClick.bind(this);
|
this.handleRadioClick = this.handleRadioClick.bind(this);
|
||||||
this.handleInputOrClick = this.handleInputOrClick.bind(this);
|
this.handleInputOrClick = this.handleInputOrClick.bind(this);
|
||||||
|
@ -96,11 +96,11 @@ export default function getExcEditor(theState) {
|
||||||
hideAllOptions() {
|
hideAllOptions() {
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
isHostHidden: this.state.sortedListOfOptions.reduce(
|
hostToIfHidden: this.state.sortedListOfOptions.reduce(
|
||||||
(isHostHidden, [excHost]) => {
|
(hostToIfHidden, [excHost]) => {
|
||||||
|
|
||||||
isHostHidden[excHost] = true;
|
hostToIfHidden[excHost] = true;
|
||||||
return isHostHidden;
|
return hostToIfHidden;
|
||||||
|
|
||||||
},
|
},
|
||||||
{}),
|
{}),
|
||||||
|
@ -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;
|
||||||
|
@ -210,7 +210,9 @@ export default function getExcEditor(theState) {
|
||||||
const ifInit = !event;
|
const ifInit = !event;
|
||||||
const currentHost = ifTriangleClicked ? '' : (trimmedInput || (ifInit ? '' : ' '));
|
const currentHost = ifTriangleClicked ? '' : (trimmedInput || (ifInit ? '' : ' '));
|
||||||
setInputValue(currentHost);
|
setInputValue(currentHost);
|
||||||
this.setState({trimmedInputValueOrSpace: currentHost});
|
this.setState({
|
||||||
|
trimmedInputValueOrSpace: currentHost,
|
||||||
|
});
|
||||||
|
|
||||||
// Episode 2.
|
// Episode 2.
|
||||||
|
|
||||||
|
@ -279,7 +281,7 @@ export default function getExcEditor(theState) {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
isHostHidden: hidden,
|
hostToIfHidden: hidden,
|
||||||
sortedListOfOptions: options,
|
sortedListOfOptions: options,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -301,7 +303,7 @@ export default function getExcEditor(theState) {
|
||||||
<div>{chrome.i18n.getMessage('ProxyTheDomainNameBelowQ')}</div>
|
<div>{chrome.i18n.getMessage('ProxyTheDomainNameBelowQ')}</div>
|
||||||
<div id="exc-address-container">
|
<div id="exc-address-container">
|
||||||
<div id="exc-address" class={inputProxyingState !== undefined ? ( inputProxyingState === true ? scopedCss.ifYes : scopedCss.ifNo ) : ''}>
|
<div id="exc-address" class={inputProxyingState !== undefined ? ( inputProxyingState === true ? scopedCss.ifYes : scopedCss.ifNo ) : ''}>
|
||||||
<span>*.</span><input placeholder="navalny.com" list="exc-list" id="exc-editor"
|
<input placeholder="*.navalny.com" list="exc-list" id="exc-editor"
|
||||||
value={this.state.trimmedInputValueOrSpace}
|
value={this.state.trimmedInputValueOrSpace}
|
||||||
ref={(inputNode) => { this.rawInput = inputNode; }}
|
ref={(inputNode) => { this.rawInput = inputNode; }}
|
||||||
onKeyDown={this.handleKeyDown.bind(this)}
|
onKeyDown={this.handleKeyDown.bind(this)}
|
||||||
|
@ -321,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;
|
||||||
return <option
|
return <option
|
||||||
value={ this.state.isHostHidden[excHost] ? '\n' : excHost + ' ' }
|
value={ this.state.hostToIfHidden[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