Add troubleshoot, no debug, lint, visual changes

This commit is contained in:
Ilya Ig. Petrov 2017-01-11 15:48:08 +00:00
parent c6d0de4798
commit bcf647d684
9 changed files with 144 additions and 116 deletions

View File

@ -1,5 +1,5 @@
module.exports = {
"extends": ["eslint:recommended", "google"],
"extends": ["google"],
"plugins": [
//"hapi"
],

View File

@ -1,6 +1,6 @@
'use strict';
const IF_DEBUG = true;
const IF_DEBUG = false;
if (!IF_DEBUG) {
// I believe logging objects precludes them from being GCed.
@ -8,13 +8,24 @@ if (!IF_DEBUG) {
// (though no one sent me logs so far).
['log', 'warn', 'error'].forEach( (meth) => {
const _meth = window.console[meth].bind(console);
window.console[meth] = function(...args) { _meth(...args.map((a) => '' + a)) }
window.console[meth] = function(...args) {
_meth(...args.map((a) => '' + a));
};
});
}
window.utils = {
mandatory() {
throw new TypeError('Missing required argument. ' +
'Be explicit if you swallow errors.');
},
areSettingsNotControlledFor(details) {
return ['controlled_by_other', 'not_controllable']

View File

@ -78,13 +78,18 @@
window.apis.errorHandlers = {
viewErrorVoid(errId) {
viewErrorVoid(type = window.utils.mandatory(), err) {
const errors = this.idToError;
let errors = {};
if (err) {
errors[type] = err;
} else {
errors = this.idToError;
}
const json = JSON.stringify(errors, errorJsonReplacer, 0);
openAndFocus(
'http://rebrand.ly/ac-error/?json=' + encodeURIComponent(json) +
'&type=' + encodeURIComponent(errId) +
(type ? '&type=' + encodeURIComponent(type) : '') +
'&version=' + chrome.runtime.getManifest().version
);
@ -142,7 +147,7 @@
{
icon = 'default-128.png',
context = extName,
ifSticky = true
ifSticky = true,
}
) {
@ -248,7 +253,7 @@
noCon,
chrome.i18n.getMessage('noControl'),
chrome.i18n.getMessage('which'),
{icon:'no-control-128.png', ifSticky: false}
{icon: 'no-control-128.png', ifSticky: false}
);
} else {
chrome.notifications.clear( noCon );

View File

@ -21,12 +21,7 @@
{ // Private namespace starts.
const mandatory = function mandatory() {
throw new TypeError('Missing required argument. ' +
'Be explicit if you swallow errors.');
};
const mandatory = window.utils.mandatory;
const throwIfError = function throwIfError(err) {
@ -99,7 +94,10 @@
};
const clarify = function clarify(err = mandatory(), message = mandatory(), {data} = {}) {
const clarify = function clarify(
err = mandatory(),
message = mandatory(),
{data} = {}) {
err.clarification = new Clarification(message, err.clarification);
if (data) {
@ -144,8 +142,7 @@
console.warn('Failed, other extension is in control.');
return cb(
null, null,
[new Warning( window.utils.messages.whichExtensionHtml() )]
new Warning( window.utils.messages.whichExtensionHtml() )
);
}
@ -163,17 +160,22 @@
};
const clarifyFetchErrorThen = (cb) => clarifyErrorThen('Что-то не так с сетью, проверьте соединение.', cb);
const clarifyFetchErrorThen = (cb) =>
clarifyErrorThen('Что-то не так с сетью, проверьте соединение.', cb);
const ifModifiedSince = function ifModifiedSince(url = mandatory(), lastModified = mandatory(), cb = mandatory()) {
const ifModifiedSince = function ifModifiedSince(
url = mandatory(),
lastModified = mandatory(),
cb = mandatory()
) {
const wasModified = new Date(0).toUTCString();
const notModifiedCode = 304;
fetch(url, {
method: 'HEAD',
headers: new Headers({
'If-Modified-Since': lastModified
})
'If-Modified-Since': lastModified,
}),
}).then(
(res) => {
cb(
@ -242,7 +244,10 @@
);
}
} catch(e) {
err = clarify(e, 'Сервер (текст): ' + res, err ? {data: err} : null)
err = clarify(
e,
'Сервер (текст): ' + res, err ? {data: err} : null
);
}
}
resolve([err, res]);
@ -271,7 +276,10 @@
};
const updatePacProxyIps = function updatePacProxyIps(provider, cb = throwIfError) {
const updatePacProxyIps = function updatePacProxyIps(
provider,
cb = throwIfError
) {
cb = asyncLogGroup(
'Getting IP for '+ provider.proxyHosts.join(', ') + '...',
@ -312,7 +320,7 @@
);
errorsCount === hostsProcessed
? cb(failure)
: cb(null, null, [failure])
: cb(null, null, [failure]);
}
)
);
@ -335,7 +343,10 @@
return cb(
null,
{lastModified},
[new Warning('Ваш PAC-скрипт не нуждается в обновлении. Его дата: ' + lastModified)]
[new Warning(
'Ваш PAC-скрипт не нуждается в обновлении. Его дата: ' +
lastModified
)]
);
}
@ -381,8 +392,6 @@
version: chrome.runtime.getManifest().version,
throwAsync() { throw new Error('ABC') }, // TODO: delete
pacProviders: {
Антизапрет: {
label: 'Антизапрет',
@ -404,8 +413,9 @@
Антицензорити: {
label: 'Антицензорити',
desc: 'Основной PAC-скрипт от автора расширения.' +
' Блокировка определятся по доменному имени или IP адресу. Работает на switch-ах.' +
' <br/><a href="https://rebrand.ly/ac-wiki">Страница проекта</a>.',
' Блокировка определятся по доменному имени или IP адресу.' +
' Работает на switch-ах. <br/>' +
' <a href="https://rebrand.ly/anticensority">Страница проекта</a>.',
/*
Don't use in system configs! Because Windows does poor caching.
@ -416,11 +426,11 @@
// Official, Cloud Flare with caching:
'https://anticensorship-russia.tk/generated-pac-scripts/anticensority.pac',
// GitHub.io:
'\x68\x74\x74\x70\x73\x3a\x2f\x2f\x61\x6e\x74\x69\x63\x65\x6e\x73\x6f\x72\x73\x68\x69\x70\x2d\x72\x75\x73\x73\x69\x61\x2e\x67\x69\x74\x68\x75\x62\x2e\x69\x6f\x2f\x67\x65\x6e\x65\x72\x61\x74\x65\x64\x2d\x70\x61\x63\x2d\x73\x63\x72\x69\x70\x74\x73\x2f\x61\x6e\x74\x69\x63\x65\x6e\x73\x6f\x72\x69\x74\x79\x2e\x70\x61\x63',
'\x68\x74\x74\x70\x73\x3a\x2f\x2f\x61\x6e\x74\x69\x63\x65\x6e\x73\x6f\x72\x73\x68\x69\x70\x2d\x72\x75\x73\x73\x69\x61\x2e\x67\x69\x74\x68\x75\x62\x2e\x69\x6f\x2f\x67\x65\x6e\x65\x72\x61\x74\x65\x64\x2d\x70\x61\x63\x2d\x73\x63\x72\x69\x70\x74\x73\x2f\x61\x6e\x74\x69\x63\x65\x6e\x73\x6f\x72\x69\x74\x79\x2e\x70\x61\x63', // eslint-disable-line max-len
// GitHub repo:
'\x68\x74\x74\x70\x73\x3a\x2f\x2f\x72\x61\x77\x2e\x67\x69\x74\x68\x75\x62\x75\x73\x65\x72\x63\x6f\x6e\x74\x65\x6e\x74\x2e\x63\x6f\x6d\x2f\x61\x6e\x74\x69\x63\x65\x6e\x73\x6f\x72\x73\x68\x69\x70\x2d\x72\x75\x73\x73\x69\x61\x2f\x67\x65\x6e\x65\x72\x61\x74\x65\x64\x2d\x70\x61\x63\x2d\x73\x63\x72\x69\x70\x74\x73\x2f\x6d\x61\x73\x74\x65\x72\x2f\x61\x6e\x74\x69\x63\x65\x6e\x73\x6f\x72\x69\x74\x79\x2e\x70\x61\x63',
'\x68\x74\x74\x70\x73\x3a\x2f\x2f\x72\x61\x77\x2e\x67\x69\x74\x68\x75\x62\x75\x73\x65\x72\x63\x6f\x6e\x74\x65\x6e\x74\x2e\x63\x6f\x6d\x2f\x61\x6e\x74\x69\x63\x65\x6e\x73\x6f\x72\x73\x68\x69\x70\x2d\x72\x75\x73\x73\x69\x61\x2f\x67\x65\x6e\x65\x72\x61\x74\x65\x64\x2d\x70\x61\x63\x2d\x73\x63\x72\x69\x70\x74\x73\x2f\x6d\x61\x73\x74\x65\x72\x2f\x61\x6e\x74\x69\x63\x65\x6e\x73\x6f\x72\x69\x74\x79\x2e\x70\x61\x63', // eslint-disable-line max-len
// Google Drive (0.17):
'\x68\x74\x74\x70\x73\x3a\x2f\x2f\x64\x72\x69\x76\x65\x2e\x67\x6f\x6f\x67\x6c\x65\x2e\x63\x6f\x6d\x2f\x75\x63\x3f\x65\x78\x70\x6f\x72\x74\x3d\x64\x6f\x77\x6e\x6c\x6f\x61\x64\x26\x69\x64\x3d\x30\x42\x2d\x5a\x43\x56\x53\x76\x75\x4e\x57\x66\x30\x54\x44\x46\x52\x4f\x47\x35\x46\x62\x55\x39\x4f\x64\x44\x67'],
'\x68\x74\x74\x70\x73\x3a\x2f\x2f\x64\x72\x69\x76\x65\x2e\x67\x6f\x6f\x67\x6c\x65\x2e\x63\x6f\x6d\x2f\x75\x63\x3f\x65\x78\x70\x6f\x72\x74\x3d\x64\x6f\x77\x6e\x6c\x6f\x61\x64\x26\x69\x64\x3d\x30\x42\x2d\x5a\x43\x56\x53\x76\x75\x4e\x57\x66\x30\x54\x44\x46\x52\x4f\x47\x35\x46\x62\x55\x39\x4f\x64\x44\x67'], // eslint-disable-line max-len
proxyHosts: ['proxy.antizapret.prostovpn.org'],
proxyIps: {
'195.123.209.38': 'proxy.antizapret.prostovpn.org',
@ -479,7 +489,10 @@
return this._currentPacProviderKey;
},
setCurrentPacProviderKey(newKey = mandatory(), lastModified = new Date().toUTCString()) {
setCurrentPacProviderKey(
newKey = mandatory(),
lastModified = new Date().toUTCString()
) {
this.mustBeKey(newKey);
this._currentPacProviderKey = newKey;
@ -742,7 +755,7 @@
key !== null &&
!Object.keys(antiCensorRu.pacProviders).includes(key)
) {
antiCensorRu._currentPacProviderKey = 'Антицензорити'
antiCensorRu._currentPacProviderKey = 'Антицензорити';
}
console.log('Extension updated.');

View File

@ -44,9 +44,6 @@
input:checked ~ .checked-radio-panel {
visibility: visible;
}
footer {
margin: 2em 1em 1em;
}
hr {
border-width: 1px 0 0 0;
margin: 0.6em 0;
@ -61,71 +58,22 @@
}
li.provider {
display: table;
width: 100%;
width: 100%;
position: relative;
}
.desc i {
vertical-align: bottom;
font-size: 1.1em;
}
/* Source: https://jsfiddle.net/greypants/zgCb7/ */
.tooltip {
display: none;
white-space: initial;
padding: 1em;
}
.desc {
display: table-cell;
text-align: right;
color: var(--ribbon-color);
cursor: help;
width: 1%;
}
.desc:hover br .tooltip {
display: block;
text-align: left;
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 2.6em;
background-color: var(--ribbon-color);
color: white;
z-index: 1;
}
.tooltip a {
color: white;
}
/* CSS Triangles - courtesy of Trevor */
.desc .tooltip:after {
border-top: solid transparent 7px;
border-bottom: solid transparent 7px;
border-left: solid var(--ribbon-color) 7px;
right: -7px;
content: "";
width: 0;
top: 7px;
margin-top: -13px;
position: absolute;
height: 0;
}
/* This bridges the gap so you can mouse into the tooltip without it disappearing
.desc .tooltip:before {
position: absolute;
right: -14px;
content: " ";
display: block;
width: 14px;
top: 0;
height: 100%;
}
*/
li.provider {
position: relative;
}
.xyz {
.tooltip {
display: none;
position: absolute;
white-space: initial;
@ -139,32 +87,36 @@
color: white;
text-align: initial;
}
.desc:hover .xyz {
.desc:hover .tooltip {
display: block;
}
.xyz a {
}
.tooltip a {
color: white;
}
.desc .xyz:after {
border-left: solid transparent 7px;
border-bottom: solid var(--ribbon-color) 7px;
.desc .tooltip:after {
border-left: solid transparent 0.5em;
border-bottom: solid var(--ribbon-color) 0.5em;
position: absolute;
top: -7px;
top: -0.5em;
content: "";
width: 0;
right: 0;
height: 0;
}
}
/* This bridges the gap so you can mouse into the tooltip without it disappearing */
.desc .xyz:before {
.desc .tooltip:before {
position: absolute;
top: -14px;
top: -1em;
content: "";
display: block;
height: 22px;
left: 0;
width: calc(100% + 0.6em);
}
height: 1.8em;
left: 75%;
width: calc(25% + 0.6em);
}
footer {
margin: 2em 0 1em 0;
}
</style>
</head>
<body>
@ -185,10 +137,13 @@
<ul id="list-of-handlers">
</ul>
</div>
<footer>
<input type="button" value="Готово" class="close-button">&nbsp;<a href="../debug/index.html" style="text-decoration: none; margin-left: 1em;">Отладка</a>
<footer style="display: table; width: 100%;">
<input type="button" value="Готово" class="close-button" style="display: table-cell">
<a href="../troubleshoot/index.html" style="text-decoration: none; margin-left: 1em; display: table-cell; text-align: right;">
Проблемы?
</a>
</footer>
<script src="./index.js"></script>
<script src="./keep-links-clickable.js"></script>
<script src="../lib/keep-links-clickable.js"></script>
</body>
</html>

View File

@ -2,7 +2,7 @@
chrome.runtime.getBackgroundPage( (backgroundPage) =>
backgroundPage.apis.errorHandlers.installListenersOnAsync(
window, 'POPUP', () => {
window, 'PUP', () => {
const getStatus = () => document.querySelector('#status');
@ -72,7 +72,10 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
warns = warns || [];
const warning = warns
.map( (w) => '✘ ' + (w.clarification && w.clarification.message || w.message || '') )
.map(
(w) => '✘ ' +
(w.clarification && w.clarification.message || w.message || '')
)
.join('<br/>');
let message = '';
@ -81,7 +84,8 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
message = err.message || '';
while( clarification ) {
message = (clarification && (clarification.message + ' ')) + message;
message = (clarification && (clarification.message + ' ')) +
message;
clarification = clarification.prev;
}
}
@ -100,7 +104,7 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
if (err) {
getStatus().querySelector('.link-button').onclick = function() {
errorHandlers.viewErrorVoid(err);
errorHandlers.viewErrorVoid('pup-ext-err', err);
return false;
};
@ -149,11 +153,9 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
<a href class="link-button checked-radio-panel"
id="update-${providerKey}"> [обновить]</a>
<div class="desc">
&nbsp;<i class="fa fa-question-circle" aria-hidden="true"></i>
<i class="fa fa-question-circle" aria-hidden="true"></i>
<div class="tooltip">${provider.desc}</div>
<div class="xyz">${provider.desc}</div>
</div>
`
</div>`;
li.querySelector('.link-button').onclick =
() => {
conduct(
@ -173,7 +175,9 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
radio.onclick = function(event) {
if (
event.target.id === (antiCensorRu.getCurrentPacProviderKey() || 'none')
event.target.id === (
antiCensorRu.getCurrentPacProviderKey() || 'none'
)
) {
return false;
}

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>Устранение проблем</title>
</head>
<body>
<h1>Устранение проблем</h1>
<ol>
<li><a href id="view-errors">Детали последних ошибок</a></li>
<li><a href id="reset-settings">Сбросить настройки</a></li>
<li><a href="https://rebrand.ly/ac-support" target="_blank">Файл самопомощи</a></li>
<li><a href="https://rebrand.ly/ac-contact">Напишите нам!</a></li>
</ol>
<h2>Для продвинутых</h2>
<ol>
<li><a href="https://rebrand.ly/ac-logs">Как прочитать логи?</a></li>
<li><a href="../debug/index.html">Отладка PAC-скрипта</a></li>
</ol>
<script src="./index.js"></script>
<script src="../lib/keep-links-clickable.js"></script>
</body>
</html>

View File

@ -0,0 +1,18 @@
'use strict';
chrome.runtime.getBackgroundPage( (backgroundPage) =>
backgroundPage.apis.errorHandlers.installListenersOnAsync(
window, 'TRBL', () => {
document.getElementById('reset-settings').onclick = () => {
backgroundPage.localStorage.clear();
chrome.storage.local.clear( () => chrome.runtime.reload() );
};
document.getElementById('view-errors').onclick = () =>
backgroundPage.apis.errorHandlers.viewErrorVoid('all');
})
);