mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2024-11-27 20:03:45 +03:00
Handle *. in UI for exceptions
This commit is contained in:
parent
df3ea9e6ad
commit
e95c186de1
|
@ -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: {}
|
ifHostHiddenMap: {}
|
||||||
};
|
};
|
||||||
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(
|
ifHostHiddenMap: this.state.sortedListOfOptions.reduce(
|
||||||
(isHostHidden, [excHost]) => {
|
(ifHostHiddenMap, [excHost]) => {
|
||||||
|
|
||||||
isHostHidden[excHost] = true;
|
ifHostHiddenMap[excHost] = true;
|
||||||
return isHostHidden;
|
return ifHostHiddenMap;
|
||||||
|
|
||||||
},
|
},
|
||||||
{}),
|
{}),
|
||||||
|
@ -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;
|
||||||
|
@ -121,7 +121,7 @@ export default function getExcEditor(theState) {
|
||||||
|
|
||||||
handleRadioClick(event) {
|
handleRadioClick(event) {
|
||||||
|
|
||||||
const host = this.state.trimmedInputValueOrSpace;
|
let host = this.state.trimmedInputValueOrSpace;
|
||||||
(() => { // `return` === `preventDefault`.
|
(() => { // `return` === `preventDefault`.
|
||||||
|
|
||||||
if(!this.isHostValid(host)) {
|
if(!this.isHostValid(host)) {
|
||||||
|
@ -147,7 +147,8 @@ export default function getExcEditor(theState) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pacMods.exceptions[host] = ifYesClicked;
|
const ifWild = host.startsWith('*.');
|
||||||
|
pacMods.exceptions[host.replace(/^\*\./g, '')] = { ifIncluded: ifYesClicked, ifWild };
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -279,7 +280,7 @@ export default function getExcEditor(theState) {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
isHostHidden: hidden,
|
ifHostHiddenMap: hidden,
|
||||||
sortedListOfOptions: options,
|
sortedListOfOptions: options,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -301,7 +302,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)}
|
||||||
|
@ -322,7 +323,7 @@ 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.
|
||||||
return <option
|
return <option
|
||||||
value={ this.state.isHostHidden[excHost] ? '\n' : excHost + ' ' }
|
value={ this.state.ifHostHiddenMap[excHost] ? '\n' : excHost + ' ' }
|
||||||
label={ excState === true ? labelIfProxied : (excState === false ? labelIfNotProxied : labelIfAuto) }/>
|
label={ excState === true ? labelIfProxied : (excState === false ? labelIfNotProxied : labelIfAuto) }/>
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user