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