From f50301febcc4adf92407ed2b572bc22a51514ab9 Mon Sep 17 00:00:00 2001 From: "Ilya Ig. Petrov" Date: Sat, 27 May 2017 11:42:18 -0700 Subject: [PATCH 1/8] Mend ProxyEditor sizings and overflow --- .../options/src/components/ProxyEditor.js | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ProxyEditor.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ProxyEditor.js index 73b82e6..cf00ac8 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ProxyEditor.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/ProxyEditor.js @@ -26,13 +26,25 @@ export default function getProxyEditor(theState) { } /* ADD PANEL */ - table.editor tr.addPanel td { + table.editor tr.addPanel td, + table.editor tr.addPanel td input + { padding: 0; } + table.editor tr.addPanel td > select[name="proxyType"], + table.editor tr.addPanel td:nth-last-child(2) /* port */ + { + font-size: 0.9em; + } /* PROXY ROW */ - table.editor tr.proxyRow td:nth-child(2) { + table.editor tr.proxyRow td:nth-child(2), /* type */ + table.editor tr.proxyRow td:nth-child(4) /* port */ + { text-align: center; } + table.editor tr.proxyRow input[name="hostname"] { + padding: 0; + } table.editor th:not(:last-child) { padding: 0 0.6em; @@ -93,7 +105,7 @@ export default function getProxyEditor(theState) { padding: 0; } .padLeft { - padding-left: 2px; + padding-left: 2px !important; } textarea.textarea { @@ -296,7 +308,10 @@ export default function getProxyEditor(theState) { class={scopedCss.only} title="Удалить" onClick={() => this.handleDelete(this, {proxyAsString, index})} >X - {type}{hostname}{port} + + {type} + + {port} + + + diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/errors-to-exc/index.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/errors-to-exc/index.js new file mode 100644 index 0000000..3af7694 --- /dev/null +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/errors-to-exc/index.js @@ -0,0 +1,75 @@ +'use strict'; + +chrome.runtime.getBackgroundPage( (bgWindow) => + bgWindow.apis.errorHandlers.installListenersOn( + window, 'LERR', () => { + + const tbody = document.getElementById('errorsTable'); + const errors = bgWindow.apis.lastErrors.get().map( + ({url, error}, index) => ({ message: error, hostname: new URL(url).hostname, ifChecked: false }) + ); + + const renderTbody = () => { + + const exc = bgWindow.apis.pacKitchen.getPacMods().exceptions || {}; + tbody.innerHTML = ''; + errors.forEach((err, index) => { + + const ifProxy = exc[err.hostname]; + let style = ''; + if (ifProxy !== undefined) { + style = `style="color: ${ifProxy ? 'green' : 'red' }"`; + } + const tr = document.createElement('tr'); + tr.innerHTML = ` + ${index} + ${err.hostname} + ${err.message} + + `; + tr.querySelector('input').onchange = function() { + + errors[index].ifChecked = this.checked; + return false; + + }; + tbody.appendChild(tr); + + }); + + }; + + document.getElementById('allBtn').onclick = () => { + + const ifAllChecked = errors.every((err) => err.ifChecked); + if (ifAllChecked) { + errors.forEach((err) => { err.ifChecked = false; }) + } else { + errors.forEach((err) => { err.ifChecked = true; }) + } + renderTbody(); + return false; + + }; + + document.getElementById('addBtn').onclick = () => { + + const mutatedMods = bgWindow.apis.pacKitchen.getPacMods(); + const exc = mutatedMods.exceptions || {}; + mutatedMods.exceptions = errors.reduce((acc, err) => { + + if (err.ifChecked) { + acc[err.hostname] = true; + } + return acc; + + }, exc); + bgWindow.apis.pacKitchen.keepCookedNowAsync(mutatedMods, (err) => alert(err || 'Сделано!')); + + }; + + renderTbody(); + document.documentElement.style.display = ''; + + }) +); diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/Exceptions.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/Exceptions.js index a722cf3..7df8ec1 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/Exceptions.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/Exceptions.js @@ -62,7 +62,21 @@ export default function getExceptions(theState) { }) } -
  • Смотреть последние ошибки
  • + { + + props.bgWindow.apis.lastErrors.ifCollecting = event.target.checked; + props.funs.setStatusTo('Сделано.'); + + }} + nodeAfterLabel={(Собирать последние ошибки сайтов)} + /> ); diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/InfoLi.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/InfoLi.js index 6a183b0..e966878 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/InfoLi.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/InfoLi.js @@ -1,4 +1,5 @@ import Inferno from 'inferno'; +import createElement from 'inferno-create-element'; import css from 'csjs-inject'; export default function getInfoLi() { @@ -119,18 +120,10 @@ export default function getInfoLi() { const iddy = props.idPrefix + ( props.ifDashify ? camelToDash(props.conf.key) : props.conf.key ); return (
  • - + { createElement('input', Object.assign({}, props, {id: iddy})) }
    -  {props.nodeAfterLabel} + {props.nodeAfterLabel}
    {props.conf.desc ? ( diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/PacChooser.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/PacChooser.js index 1dcc388..92dd30b 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/PacChooser.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/components/PacChooser.js @@ -28,6 +28,7 @@ export default function getPacChooser(theState) { .updateButton { visibility: hidden; + margin-left: 0.5em; } input:checked + div .updateButton { visibility: inherit; diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-full/80-error-menu.js b/extensions/chromium/runet-censorship-bypass/src/extension-full/80-error-menu.js index 3e4da41..2c4976f 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-full/80-error-menu.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-full/80-error-menu.js @@ -1,38 +1,35 @@ 'use strict'; -/* -window.chrome.browserAction.setBadgeBackgroundColor({ - color: '#db4b2f', -}); -*/ +{ -chrome.webNavigation.onErrorOccurred.addListener((details) => { + chrome.webNavigation.onErrorOccurred.addListener((details) => { - const tabId = details.tabId; - console.log(details.url, details.error, details); - if ( !(details.frameId === 0 && tabId >= 0) || - [ - 'net::ERR_BLOCKED_BY_CLIENT', - 'net::ERR_ABORTED', - ].includes(details.error) ) { - return; - } + const tabId = details.tabId; + console.log(details.url, details.error, details); + if ( !(details.frameId === 0 && tabId >= 0) || + [ + 'net::ERR_BLOCKED_BY_CLIENT', + 'net::ERR_ABORTED', + ].includes(details.error) ) { + return; + } - console.log(details.url, details.error, details); + console.log(details.url, details.error, details); + + chrome.browserAction.setPopup({ + tabId, + popup: './pages/options/index.html#tab=exceptions&status=Правый клик по иконке = меню инструментов!', + }); + + window.chrome.browserAction.setBadgeBackgroundColor({ + tabId, + color: '#4285f4', + }); + chrome.browserAction.setBadgeText({ + tabId, + text: '●●●', + }); - chrome.browserAction.setPopup({ - tabId, - popup: './pages/options/index.html#tab=exceptions&status=Правый клик по иконке = меню инструментов!', }); - window.chrome.browserAction.setBadgeBackgroundColor({ - tabId, - color: '#4285f4', - }); - chrome.browserAction.setBadgeText({ - tabId, - text: '●●●', - }); - -}); - +} diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-full/83-last-errors.js b/extensions/chromium/runet-censorship-bypass/src/extension-full/83-last-errors.js new file mode 100644 index 0000000..2577903 --- /dev/null +++ b/extensions/chromium/runet-censorship-bypass/src/extension-full/83-last-errors.js @@ -0,0 +1,36 @@ +'use strict'; + +{ + + const lastErrors = []; + const lastErrorsLength = 20; + + const that = window.apis.lastErrors = { + ifCollecting: false, + get: () => lastErrors, + } + + chrome.webRequest.onErrorOccurred.addListener((details) => { + + if (!that.ifCollecting || [ + 'net::ERR_BLOCKED_BY_CLIENT', + 'net::ERR_ABORTED', + ].includes(details.error) ) { + return; + } + const last = lastErrors[0]; + if (last && details.error === last.error && details.url === last.url) { + // Dup. + return; + } + + lastErrors.unshift(details); + if (lastErrors.length > lastErrorsLenght) { + lastErrors.pop(); + } + + }, + {urls: ['']} + ); + +} diff --git a/extensions/chromium/runet-censorship-bypass/src/templates-data.js b/extensions/chromium/runet-censorship-bypass/src/templates-data.js index 7d9d533..366e37e 100644 --- a/extensions/chromium/runet-censorship-bypass/src/templates-data.js +++ b/extensions/chromium/runet-censorship-bypass/src/templates-data.js @@ -13,7 +13,7 @@ exports.contexts.full = Object.assign({}, commonContext, { extra_permissions: ', "webRequest", "webNavigation"', persistent: '', scripts_2x: ', "20-ip-to-host-api.js"', - scripts_8x: ', "80-error-menu.js", "85-block-informer.js"', + scripts_8x: ', "80-error-menu.js", "83-last-errors.js", "85-block-informer.js"', }); exports.contexts.mini = Object.assign({}, commonContext, {