From bcf647d684e7a35168281e876db64819b2854bdc Mon Sep 17 00:00:00 2001 From: "Ilya Ig. Petrov" Date: Wed, 11 Jan 2017 15:48:08 +0000 Subject: [PATCH] Add troubleshoot, no debug, lint, visual changes --- extensions/chromium/.eslintrc.js | 2 +- .../extension/00-init-apis.js | 15 ++- .../extension/11-api-error-handlers.js | 15 ++- ...2-api-sync-pac-script-with-pac-provider.js | 65 ++++++----- .../pages/choose-pac-provider/index.html | 101 +++++------------- .../pages/choose-pac-provider/index.js | 22 ++-- .../keep-links-clickable.js | 0 .../extension/pages/troubleshoot/index.html | 22 ++++ .../extension/pages/troubleshoot/index.js | 18 ++++ 9 files changed, 144 insertions(+), 116 deletions(-) rename extensions/chromium/runet-censorship-bypass/extension/pages/{choose-pac-provider => lib}/keep-links-clickable.js (100%) create mode 100644 extensions/chromium/runet-censorship-bypass/extension/pages/troubleshoot/index.html create mode 100644 extensions/chromium/runet-censorship-bypass/extension/pages/troubleshoot/index.js diff --git a/extensions/chromium/.eslintrc.js b/extensions/chromium/.eslintrc.js index 917c5ed..14a26e3 100644 --- a/extensions/chromium/.eslintrc.js +++ b/extensions/chromium/.eslintrc.js @@ -1,5 +1,5 @@ module.exports = { - "extends": ["eslint:recommended", "google"], + "extends": ["google"], "plugins": [ //"hapi" ], diff --git a/extensions/chromium/runet-censorship-bypass/extension/00-init-apis.js b/extensions/chromium/runet-censorship-bypass/extension/00-init-apis.js index f7d0a64..75bf363 100644 --- a/extensions/chromium/runet-censorship-bypass/extension/00-init-apis.js +++ b/extensions/chromium/runet-censorship-bypass/extension/00-init-apis.js @@ -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'] diff --git a/extensions/chromium/runet-censorship-bypass/extension/11-api-error-handlers.js b/extensions/chromium/runet-censorship-bypass/extension/11-api-error-handlers.js index 54376ae..42c0c4c 100644 --- a/extensions/chromium/runet-censorship-bypass/extension/11-api-error-handlers.js +++ b/extensions/chromium/runet-censorship-bypass/extension/11-api-error-handlers.js @@ -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 ); diff --git a/extensions/chromium/runet-censorship-bypass/extension/12-api-sync-pac-script-with-pac-provider.js b/extensions/chromium/runet-censorship-bypass/extension/12-api-sync-pac-script-with-pac-provider.js index 8f66318..50ebbc4 100644 --- a/extensions/chromium/runet-censorship-bypass/extension/12-api-sync-pac-script-with-pac-provider.js +++ b/extensions/chromium/runet-censorship-bypass/extension/12-api-sync-pac-script-with-pac-provider.js @@ -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-ах.' + - '
Страница проекта.', + ' Блокировка определятся по доменному имени или IP адресу.' + + ' Работает на switch-ах.
' + + ' Страница проекта.', /* 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.'); diff --git a/extensions/chromium/runet-censorship-bypass/extension/pages/choose-pac-provider/index.html b/extensions/chromium/runet-censorship-bypass/extension/pages/choose-pac-provider/index.html index 9165a39..65bdc67 100755 --- a/extensions/chromium/runet-censorship-bypass/extension/pages/choose-pac-provider/index.html +++ b/extensions/chromium/runet-censorship-bypass/extension/pages/choose-pac-provider/index.html @@ -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; + } @@ -185,10 +137,13 @@ -