mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2025-01-31 11:54:14 +03:00
Merge branch 'development' into production
This commit is contained in:
commit
422de472dd
|
@ -298,7 +298,8 @@
|
|||
self.included = [];
|
||||
self.excluded = [];
|
||||
for(const host of Object.keys(self.exceptions)) {
|
||||
if (self.exceptions[host]) {
|
||||
const ifProxy = self.exceptions[host] || false;
|
||||
if (ifProxy) {
|
||||
self.included.push(host);
|
||||
} else {
|
||||
self.excluded.push(host);
|
||||
|
@ -307,9 +308,9 @@
|
|||
['included', 'excluded'].forEach((who) => {
|
||||
|
||||
self[who] = self[who]
|
||||
.map( (s) => s.split('').reverse() )
|
||||
.map( (domain) => domain.split('').reverse() )
|
||||
.sort()
|
||||
.map( (a) => a.reverse().join('') );
|
||||
.map( (rDomain) => rDomain.reverse().join('') );
|
||||
|
||||
});
|
||||
if (self.included.length && !self.filteredCustomsString) {
|
||||
|
@ -386,11 +387,11 @@
|
|||
const ifIncluded = pacMods.included && pacMods.included.length;
|
||||
const ifExcluded = pacMods.excluded && pacMods.excluded.length;
|
||||
const ifManualExceptions = ifIncluded || ifExcluded;
|
||||
const finalExceptions = {};
|
||||
let finalExceptions = {};
|
||||
if (pacMods.ifProxyMoreDomains) {
|
||||
pacMods.moreDomains.reduce((acc, tld) => {
|
||||
finalExceptions = pacMods.moreDomains.reduce((acc, tld) => {
|
||||
|
||||
acc[tld] = true;
|
||||
acc['*.' + tld] = true;
|
||||
return acc;
|
||||
|
||||
}, finalExceptions);
|
||||
|
@ -405,17 +406,30 @@
|
|||
/******/
|
||||
/******/ /* EXCEPTIONS START */
|
||||
/******/ const dotHost = '.' + host;
|
||||
/******/ const isHostInDomain = (domain) => dotHost.endsWith('.' + domain);
|
||||
/******/ const domainReducer = (maxWeight, [domain, ifIncluded]) => {
|
||||
// TODO: handle wildcards.
|
||||
/******/ 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;
|
||||
/******/ }
|
||||
/******/ 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)) {
|
||||
/******/ return maxWeight;
|
||||
/******/ }
|
||||
/******/ return newWeightAbs*(ifIncluded ? 1 : -1);
|
||||
/******/ return newWeightAbs*(ifProxy ? 1 : -1);
|
||||
/******/
|
||||
/******/ };
|
||||
/******/
|
||||
|
|
|
@ -525,16 +525,41 @@
|
|||
|
||||
// ON EACH LAUNCH, STARTUP, RELOAD, UPDATE, ENABLE
|
||||
(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);
|
||||
if (storage.version && window.apis.version.isLeq(storage.version, '0.0.1.48')) {
|
||||
const ffxPacData = storage['firefox-only-pac-data'];
|
||||
delete storage['firefox-only-pac-data'];
|
||||
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 });
|
||||
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...');
|
||||
await new Promise((resolve) => window.apis.pacKitchen.keepCookedNowAsync(resolve));
|
||||
|
||||
//console.log('Storage on init:', oldStorage);
|
||||
antiCensorRu.ifFirstInstall = Object.keys(oldStorage).length === 0;
|
||||
//console.log('Storage on init:', oldAntiCensorRu);
|
||||
antiCensorRu.ifFirstInstall = Object.keys(oldAntiCensorRu).length === 0;
|
||||
|
||||
if (antiCensorRu.ifFirstInstall) {
|
||||
// INSTALL
|
||||
|
@ -585,11 +610,11 @@
|
|||
// LAUNCH, RELOAD, UPDATE
|
||||
// Use old or migrate to default.
|
||||
antiCensorRu._currentPacProviderKey =
|
||||
oldStorage._currentPacProviderKey || null;
|
||||
oldAntiCensorRu._currentPacProviderKey || null;
|
||||
antiCensorRu.lastPacUpdateStamp =
|
||||
oldStorage.lastPacUpdateStamp || antiCensorRu.lastPacUpdateStamp;
|
||||
oldAntiCensorRu.lastPacUpdateStamp || antiCensorRu.lastPacUpdateStamp;
|
||||
antiCensorRu._currentPacProviderLastModified =
|
||||
oldStorage._currentPacProviderLastModified
|
||||
oldAntiCensorRu._currentPacProviderLastModified
|
||||
|| antiCensorRu._currentPacProviderLastModified;
|
||||
console.log(
|
||||
'Last PAC update was on',
|
||||
|
@ -607,11 +632,11 @@
|
|||
|
||||
await new Promise(async (resolve) => {
|
||||
|
||||
const ifUpdating = antiCensorRu.version !== oldStorage.version;
|
||||
const ifUpdating = antiCensorRu.version !== oldAntiCensorRu.version;
|
||||
if (!ifUpdating) {
|
||||
|
||||
// LAUNCH, RELOAD, ENABLE
|
||||
antiCensorRu.pacProviders = oldStorage.pacProviders;
|
||||
antiCensorRu.pacProviders = oldAntiCensorRu.pacProviders;
|
||||
console.log('Extension launched, reloaded or enabled.');
|
||||
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 {
|
||||
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).
|
||||
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.');
|
||||
const provKey = antiCensorRu.getCurrentPacProviderKey();
|
||||
|
|
|
@ -79,14 +79,14 @@ export default function getExcEditor(theState) {
|
|||
props.currentTab &&
|
||||
props.currentTab.url &&
|
||||
!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();
|
||||
this.state = {
|
||||
trimmedInputValueOrSpace,
|
||||
sortedListOfOptions: this.modsToOpts(pacMods),
|
||||
isHostHidden: {}
|
||||
hostToIfHidden: {},
|
||||
};
|
||||
this.handleRadioClick = this.handleRadioClick.bind(this);
|
||||
this.handleInputOrClick = this.handleInputOrClick.bind(this);
|
||||
|
@ -96,11 +96,11 @@ export default function getExcEditor(theState) {
|
|||
hideAllOptions() {
|
||||
|
||||
this.setState({
|
||||
isHostHidden: this.state.sortedListOfOptions.reduce(
|
||||
(isHostHidden, [excHost]) => {
|
||||
hostToIfHidden: this.state.sortedListOfOptions.reduce(
|
||||
(hostToIfHidden, [excHost]) => {
|
||||
|
||||
isHostHidden[excHost] = true;
|
||||
return isHostHidden;
|
||||
hostToIfHidden[excHost] = true;
|
||||
return hostToIfHidden;
|
||||
|
||||
},
|
||||
{}),
|
||||
|
@ -110,7 +110,7 @@ export default function getExcEditor(theState) {
|
|||
|
||||
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)) {
|
||||
this.props.funs.showErrors(new TypeError('Должно быть только доменное имя, без протокола, порта и пути. Попробуйте ещё раз.'));
|
||||
return false;
|
||||
|
@ -210,7 +210,9 @@ export default function getExcEditor(theState) {
|
|||
const ifInit = !event;
|
||||
const currentHost = ifTriangleClicked ? '' : (trimmedInput || (ifInit ? '' : ' '));
|
||||
setInputValue(currentHost);
|
||||
this.setState({trimmedInputValueOrSpace: currentHost});
|
||||
this.setState({
|
||||
trimmedInputValueOrSpace: currentHost,
|
||||
});
|
||||
|
||||
// Episode 2.
|
||||
|
||||
|
@ -279,7 +281,7 @@ export default function getExcEditor(theState) {
|
|||
})();
|
||||
|
||||
this.setState({
|
||||
isHostHidden: hidden,
|
||||
hostToIfHidden: hidden,
|
||||
sortedListOfOptions: options,
|
||||
});
|
||||
|
||||
|
@ -301,7 +303,7 @@ export default function getExcEditor(theState) {
|
|||
<div>{chrome.i18n.getMessage('ProxyTheDomainNameBelowQ')}</div>
|
||||
<div id="exc-address-container">
|
||||
<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}
|
||||
ref={(inputNode) => { this.rawInput = inputNode; }}
|
||||
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.
|
||||
// 2. Space is used in matching so even an empty input (replaced with space) has tooltip with prompts.
|
||||
const ifProxy = excState;
|
||||
return <option
|
||||
value={ this.state.isHostHidden[excHost] ? '\n' : excHost + ' ' }
|
||||
label={ excState === true ? labelIfProxied : (excState === false ? labelIfNotProxied : labelIfAuto) }/>
|
||||
value={ this.state.hostToIfHidden[excHost] ? '\n' : excHost + ' ' }
|
||||
label={ ifProxy === true ? labelIfProxied : (ifProxy === false ? labelIfNotProxied : labelIfAuto) }/>
|
||||
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user