mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2024-11-24 02:13:43 +03:00
Refactor exception editor behavior, change mods desc
This commit is contained in:
parent
5644fcfbd8
commit
5af9458eae
|
@ -1,8 +1,5 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"extends": ["google"],
|
"extends": ["airbnb"],
|
||||||
"plugins": [
|
|
||||||
//"hapi"
|
|
||||||
],
|
|
||||||
"env": {
|
"env": {
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"webextensions": true,
|
"webextensions": true,
|
||||||
|
@ -23,6 +20,5 @@ module.exports = {
|
||||||
"no-console": "off",
|
"no-console": "off",
|
||||||
"padded-blocks": "off",
|
"padded-blocks": "off",
|
||||||
"require-jsdoc": "off"
|
"require-jsdoc": "off"
|
||||||
//"hapi/hapi-scope-start": ["warn"]
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,12 +10,10 @@
|
||||||
"author": "Ilya Ig. Petrov",
|
"author": "Ilya Ig. Petrov",
|
||||||
"license": "GPLv3",
|
"license": "GPLv3",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^3.11.1",
|
"eslint": "^3.15.0",
|
||||||
"eslint-config-airbnb": "^13.0.0",
|
"eslint-config-airbnb": "^14.0.0",
|
||||||
"eslint-config-google": "^0.7.1",
|
|
||||||
"eslint-plugin-hapi": "^4.0.0",
|
|
||||||
"eslint-plugin-import": "^2.2.0",
|
"eslint-plugin-import": "^2.2.0",
|
||||||
"eslint-plugin-jsx-a11y": "^2.2.3",
|
"eslint-plugin-jsx-a11y": "^3.0.2",
|
||||||
"eslint-plugin-react": "^6.7.1"
|
"eslint-plugin-react": "^6.9.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,18 @@
|
||||||
(res) => {
|
(res) => {
|
||||||
|
|
||||||
const textCb =
|
const textCb =
|
||||||
(err) => res.text().then( (text) => cb(err, text), cb );
|
(err) => {
|
||||||
|
|
||||||
|
console.log('Reading response as text...');
|
||||||
|
res.text().then(
|
||||||
|
(text) => {
|
||||||
|
console.log('Calling CB...');
|
||||||
|
cb(err, text);
|
||||||
|
},
|
||||||
|
cb
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
const status = res.status;
|
const status = res.status;
|
||||||
if ( !( status >= 200 && status < 300 || status === 304 ) ) {
|
if ( !( status >= 200 && status < 300 || status === 304 ) ) {
|
||||||
|
|
|
@ -116,10 +116,12 @@
|
||||||
'https://dns.google.com/resolve?type=' + type + '&name=' + host,
|
'https://dns.google.com/resolve?type=' + type + '&name=' + host,
|
||||||
(err, res) => {
|
(err, res) => {
|
||||||
|
|
||||||
|
console.log('After GET...');
|
||||||
if (res) {
|
if (res) {
|
||||||
try {
|
try {
|
||||||
|
console.log('Parsing JSON...');
|
||||||
res = JSON.parse(res);
|
res = JSON.parse(res);
|
||||||
console.log('Json parsed.');
|
console.log('JSON parsed.');
|
||||||
if (err || res.Status) {
|
if (err || res.Status) {
|
||||||
const msg = ['Answer', 'Comment', 'Status']
|
const msg = ['Answer', 'Comment', 'Status']
|
||||||
.filter( (prop) => res[prop] )
|
.filter( (prop) => res[prop] )
|
||||||
|
@ -222,7 +224,7 @@
|
||||||
|
|
||||||
getIpsFor(hostStr, (err, ips, ...warns) => {
|
getIpsFor(hostStr, (err, ips, ...warns) => {
|
||||||
|
|
||||||
console.log('IPS', ips, err);
|
console.log('Got IPs + err?:', ips, err);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
this._purgeOldIpsForSync(hostStr);
|
this._purgeOldIpsForSync(hostStr);
|
||||||
// Object may be shared, string can't.
|
// Object may be shared, string can't.
|
||||||
|
@ -233,7 +235,6 @@
|
||||||
console.log(privates._ipToHostObj[ip], privates._ipToHostObj);
|
console.log(privates._ipToHostObj[ip], privates._ipToHostObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('PP', privates._ipToHostObj);
|
|
||||||
return cb(err, null, ...warns);
|
return cb(err, null, ...warns);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
ifProxyHttpsUrlsOnly: {
|
ifProxyHttpsUrlsOnly: {
|
||||||
dflt: false,
|
dflt: false,
|
||||||
label: 'проксировать только HTTP<em>S</em>-сайты',
|
label: 'проксировать только HTTP<em>S</em>-сайты',
|
||||||
desc: 'Проксировать только сайты, доступные по шифрованному протоколу httpS. Прокси и провайдер смогут видеть только адреса проксируемых HTTP<em>S</em>-сайтов, но не их содержимое. Используйте, если вы не доверяете прокси-серверам ваш HTTP-трафик. Разумеется, что с этой опцией разблокировка HTTP-сайтов работать не будет.',
|
desc: 'Проксировать только сайты, доступные по шифрованному протоколу HTTP<em>S</em>. Прокси и провайдер смогут видеть только адреса проксируемых HTTP<em>S</em>-сайтов, но не их содержимое. Используйте, если вы не доверяете прокси-серверам ваш HTTP-трафик. Разумеется, что с этой опцией разблокировка HTTP-сайтов работать не будет.',
|
||||||
index: 0,
|
index: 0,
|
||||||
},
|
},
|
||||||
ifUseSecureProxiesOnly: {
|
ifUseSecureProxiesOnly: {
|
||||||
|
@ -140,7 +140,6 @@
|
||||||
|
|
||||||
this.included = this.excluded = undefined;
|
this.included = this.excluded = undefined;
|
||||||
if (this.ifMindExceptions && this.exceptions) {
|
if (this.ifMindExceptions && this.exceptions) {
|
||||||
console.log('Exceptions:', this.exceptions);
|
|
||||||
this.included = [];
|
this.included = [];
|
||||||
this.excluded = [];
|
this.excluded = [];
|
||||||
for(const host of Object.keys(this.exceptions)) {
|
for(const host of Object.keys(this.exceptions)) {
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
}
|
}
|
||||||
em {
|
em {
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
border-bottom: 1px solid black;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* COMMON 1 */
|
/* COMMON 1 */
|
||||||
|
@ -227,7 +227,8 @@
|
||||||
.desc:hover .tooltip {
|
.desc:hover .tooltip {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
.tooltip a {
|
.tooltip a,
|
||||||
|
.tooltip em {
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
.desc .tooltip:after {
|
.desc .tooltip:after {
|
||||||
|
@ -377,7 +378,6 @@
|
||||||
</section>
|
</section>
|
||||||
<section data-for="acc-exc" class="hidden-for-options-page">
|
<section data-for="acc-exc" class="hidden-for-options-page">
|
||||||
|
|
||||||
|
|
||||||
<div>Проксировать указанный сайт?</div>
|
<div>Проксировать указанный сайт?</div>
|
||||||
<div id="exc-address">
|
<div id="exc-address">
|
||||||
<span>*.</span><input placeholder="navalny.com" list="exc-list" name="browser" id="exc-editor" style=""/>
|
<span>*.</span><input placeholder="navalny.com" list="exc-list" name="browser" id="exc-editor" style=""/>
|
||||||
|
|
|
@ -258,24 +258,25 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const ifProxyHtml = '✔';
|
const ifProxyLabel = '✔';
|
||||||
const ifNotProxyHtml = '✘';
|
const ifNotProxyLabel = '✘';
|
||||||
const ifAutoHtml = '🔄';
|
const ifAutoLabel = '🔄';
|
||||||
|
|
||||||
const addOption = function addOption(host, yesNoUndefined) {
|
const addOption = function addOption(host, yesNoUndefined) {
|
||||||
|
|
||||||
const opt = document.createElement('option');
|
const opt = document.createElement('option');
|
||||||
|
// `value` may be changed for hiding line in the tooltip.
|
||||||
opt.value = host;
|
opt.value = host;
|
||||||
opt.dataset.host = host;
|
opt.dataset.host = host;
|
||||||
switch(yesNoUndefined) {
|
switch(yesNoUndefined) {
|
||||||
case true:
|
case true:
|
||||||
opt.innerHTML = ifProxyHtml;
|
opt.label = ifProxyLabel;
|
||||||
break;
|
break;
|
||||||
case false:
|
case false:
|
||||||
opt.innerHTML = ifNotProxyHtml;
|
opt.label = ifNotProxyLabel;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
opt.innerHTML = ifAutoHtml;
|
opt.label = ifAutoLabel;
|
||||||
}
|
}
|
||||||
const editorHost = excEditor.value.trim();
|
const editorHost = excEditor.value.trim();
|
||||||
if (host === editorHost) {
|
if (host === editorHost) {
|
||||||
|
@ -283,6 +284,7 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
|
||||||
} else {
|
} else {
|
||||||
excList.appendChild(opt);
|
excList.appendChild(opt);
|
||||||
}
|
}
|
||||||
|
return opt;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -318,7 +320,7 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
excEditor.onclick = excEditor.oninput = function(event) {
|
const renderExceptions = function renderExceptions(event) {
|
||||||
|
|
||||||
// If triangle button on right of datalist input clicked.
|
// If triangle button on right of datalist input clicked.
|
||||||
|
|
||||||
|
@ -326,13 +328,10 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
|
||||||
const ifClick = event && event.type === 'click';
|
const ifClick = event && event.type === 'click';
|
||||||
|
|
||||||
{
|
{
|
||||||
const minIndentFromRightInPx = 15;
|
const maxIndentFromRightInPx = 15;
|
||||||
if( ifClick
|
ifTriangleClicked = ifClick
|
||||||
&& !this.selectionStart && !this.selectionStart
|
&& !excEditor.selectionStart && !excEditor.selectionStart
|
||||||
&& event.x > this.getBoundingClientRect().right - minIndentFromRightInPx
|
&& event.x > excEditor.getBoundingClientRect().right - maxIndentFromRightInPx;
|
||||||
) {
|
|
||||||
ifTriangleClicked = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const setInputValue = (newValue) => {
|
const setInputValue = (newValue) => {
|
||||||
|
@ -343,55 +342,86 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
|
||||||
}
|
}
|
||||||
// See bug in my comment to http://stackoverflow.com/a/32394157/521957
|
// See bug in my comment to http://stackoverflow.com/a/32394157/521957
|
||||||
// First click on empty input may be still ignored.
|
// First click on empty input may be still ignored.
|
||||||
const nu = this.selectionStart + newValue.length - this.value.length;
|
const nu = excEditor.selectionStart + newValue.length - excEditor.value.length;
|
||||||
this.value = newValue;
|
excEditor.value = newValue;
|
||||||
excEditor.dataset.moveCursorTo = nu;
|
excEditor.dataset.moveCursorTo = nu;
|
||||||
window.setTimeout(moveCursorIfNeeded, 0);
|
window.setTimeout(moveCursorIfNeeded, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const host = this.value.trim();
|
const originalHost = excEditor.value.trim();
|
||||||
const ifInit = !event;
|
const ifInit = !event;
|
||||||
setInputValue(ifTriangleClicked ? '' : (host || (ifInit ? '' : ' ')));
|
const currentHost = ifTriangleClicked ? '' : (originalHost || (ifInit ? '' : ' '));
|
||||||
thisAuto.checked = true;
|
setInputValue(currentHost);
|
||||||
|
|
||||||
let exactOpt = false;
|
let exactOpt = false;
|
||||||
|
let editedOpt = false;
|
||||||
excList.childNodes.forEach(
|
excList.childNodes.forEach(
|
||||||
(opt) => {
|
(opt) => {
|
||||||
|
|
||||||
if(opt.innerHTML === ifAutoHtml) {
|
unhideOpt(opt);
|
||||||
return opt.remove();
|
|
||||||
|
if(opt.label === ifAutoLabel) {
|
||||||
|
editedOpt = opt;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const ifExactMatch = opt.dataset.host === host;
|
if (opt.dataset.host === originalHost) {
|
||||||
if (!ifExactMatch) {
|
exactOpt = opt;
|
||||||
return unhideOpt(opt);
|
|
||||||
}
|
}
|
||||||
exactOpt = opt;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
this.parentNode.classList.remove(noClass, yesClass);
|
thisAuto.checked = true;
|
||||||
if(exactOpt) {
|
excEditor.parentNode.classList.remove(noClass, yesClass);
|
||||||
if(ifTriangleClicked) {
|
|
||||||
unhideOpt(exactOpt);
|
if (ifTriangleClicked || !originalHost) {
|
||||||
} else {
|
// Show all opts.
|
||||||
hideOpt(exactOpt);
|
if (editedOpt) {
|
||||||
if(exactOpt.innerHTML === ifProxyHtml) {
|
const ifBackspaced = !originalHost && editedOpt.value.length < 3;
|
||||||
thisYes.checked = true;
|
if (ifBackspaced) {
|
||||||
this.parentNode.classList.add(yesClass);
|
editedOpt.remove();
|
||||||
} else {
|
|
||||||
thisNo.checked = true;
|
|
||||||
this.parentNode.classList.add(noClass);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ifTriangleClicked && host) {
|
return true;
|
||||||
addOption(host, undefined);
|
}
|
||||||
|
|
||||||
|
if (editedOpt) {
|
||||||
|
hideOpt(editedOpt);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!exactOpt) {
|
||||||
|
if(editedOpt) {
|
||||||
|
const ifExact = editedOpt.dataset.host === originalHost;
|
||||||
|
if(ifExact) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Not exact! Update!
|
||||||
|
editedOpt.remove();
|
||||||
|
}
|
||||||
|
editedOpt = addOption(originalHost, undefined);
|
||||||
|
if (!ifClick) {
|
||||||
|
// New value was typed -- don't show tooltip.
|
||||||
|
hideOpt(editedOpt);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exact found!
|
||||||
|
hideOpt(exactOpt);
|
||||||
|
if(exactOpt.label === ifProxyLabel) {
|
||||||
|
thisYes.checked = true;
|
||||||
|
excEditor.parentNode.classList.add(yesClass);
|
||||||
|
} else {
|
||||||
|
thisNo.checked = true;
|
||||||
|
excEditor.parentNode.classList.add(noClass);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
excEditor.onclick = excEditor.oninput = renderExceptions;
|
||||||
|
|
||||||
if (currentTab && !currentTab.url.startsWith('chrome')) {
|
if (currentTab && !currentTab.url.startsWith('chrome')) {
|
||||||
excEditor.value = new URL(currentTab.url).hostname;
|
excEditor.value = new URL(currentTab.url).hostname;
|
||||||
} else {
|
} else {
|
||||||
|
@ -405,7 +435,7 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
|
||||||
for(const host of Object.keys(pacMods.exceptions || {}).sort()) {
|
for(const host of Object.keys(pacMods.exceptions || {}).sort()) {
|
||||||
addOption(host, pacMods.exceptions[host]);
|
addOption(host, pacMods.exceptions[host]);
|
||||||
}
|
}
|
||||||
excEditor.oninput(); // Colorize input.
|
renderExceptions(); // Colorize input.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,8 +482,9 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
|
||||||
(opt) => opt.dataset.host === host && opt.remove()
|
(opt) => opt.dataset.host === host && opt.remove()
|
||||||
);
|
);
|
||||||
fixUi();
|
fixUi();
|
||||||
|
// Window may be closed before this line executes.
|
||||||
console.log(excEditor, excEditor.oninput);
|
console.log(excEditor, excEditor.oninput);
|
||||||
excEditor.oninput();
|
renderExceptions();
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Before Width: | Height: | Size: 434 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user