Merge branch 'autosuggest' into development

This commit is contained in:
Ilya Ig. Petrov 2017-05-28 22:31:34 +05:00
commit d0f9960831
24 changed files with 776 additions and 128 deletions

View File

@ -74,7 +74,7 @@
ifProxyMoreDomains: {
ifDisabled: true,
dflt: false,
category: 'exceptions',
category: 'ownProxies',
label: 'проксировать .onion, .i2p и OpenNIC',
desc: 'Проксировать особые домены. Необходима поддержка со стороны СВОИХ прокси.',
order: 8,

View File

@ -0,0 +1,63 @@
'use strict';
{
window.apis.menus = {
getItemsAsObject: () => ({
googleTranslate: {
title: 'Через Google Translate',
getUrl: (blockedUrl) => (
'https://translate.google.com/translate?hl=&sl=en&tl=ru&anno=2&sandbox=1&u=' + blockedUrl),
order: 0,
},
hostTracker: {
title: 'Из кэша Google',
getUrl: (blockedUrl) => 'http://webcache.googleusercontent.com/search?q=cache:' + blockedUrl,
order: 1,
},
archiveOrg: {
title: 'Из архива archive.org',
getUrl: (blockedUrl) => 'https://web.archive.org/web/*/' + blockedUrl,
order: 2,
},
otherUnblock: {
title: 'Разблокировать по-другому',
getUrl: (blockedUrl) => ('https://rebrand.ly/ac-unblock#' + blockedUrl),
order: 3,
},
antizapretInfo: {
title: 'Сайт в реестре блокировок?',
getUrl: (blockedUrl) => 'https://antizapret.info/index.php?search=' + new URL(blockedUrl).hostname,
order: 4,
},
support: {
title: 'Документация / Помощь / Поддержка',
getUrl: (blockedUrl) => 'https://rebrand.ly/ac-support',
order: 99,
},
}),
getItemsAsArray: function() {
const itemsObj = this.getItemsAsObject();
return Object.keys(itemsObj).reduce((acc, key) => {
acc.push(itemsObj[key]);
return acc;
}, [])
.sort((a, b) => a.order - b.order);
},
};
}

View File

@ -0,0 +1,45 @@
'use strict';
{
const chromified = window.utils.chromified;
let seqId = 0;
const createMenuLinkEntry = (title, tab2url) => {
const id = (++seqId).toString();
chrome.contextMenus.create({
id: id,
title: title,
contexts: ['browser_action'],
}, chromified((err) => {
if(err) {
console.warn('Context menu error ignored:', err);
}
}));
chrome.contextMenus.onClicked.addListener((info, tab) => {
if(info.menuItemId === id) {
Promise.resolve( tab2url( tab ) )
.then( (url) => chrome.tabs.create({url: url}) );
}
});
};
window.apis.menus.getItemsAsArray().forEach((item) => {
createMenuLinkEntry(
item.title,
(tab) => item.getUrl(tab.url),
);
});
}

View File

@ -1,72 +0,0 @@
'use strict';
{
const chromified = window.utils.chromified;
let seqId = 0;
const createMenuLinkEntry = (title, tab2url) => {
const id = (++seqId).toString();
chrome.contextMenus.create({
id: id,
title: title,
contexts: ['browser_action'],
}, chromified((err) => {
if(err) {
console.warn('Context menu error ignored:', err);
}
}));
chrome.contextMenus.onClicked.addListener((info, tab) => {
if(info.menuItemId === id) {
Promise.resolve( tab2url( tab ) )
.then( (url) => chrome.tabs.create({url: url}) );
}
});
};
createMenuLinkEntry(
'Сайт доступен из-за границы? Is up?',
(tab) => `data:text/html;charset=utf8,<title>Запрашиваю...</title>
<form class='tracker-form' method='POST'
action='https://www.host-tracker.com/ru/InstantCheck/Create'>
<input name='InstantCheckUrl' value='${new URL(tab.url).hostname}'
type='hidden'>
</form>
<script>document.querySelector('.tracker-form').submit()<\/script>`
);
createMenuLinkEntry(
'Сайт в реестре блокировок?',
(tab) => 'https://antizapret.info/index.php?search=' + new URL(tab.url).hostname
);
createMenuLinkEntry(
'Из архива archive.org',
(tab) => 'https://web.archive.org/web/*/' + tab.url
);
createMenuLinkEntry(
'Через Google Translate',
(tab) => 'https://translate.google.com/translate?hl=&sl=en&tl=ru&anno=2&sandbox=1&u=' + tab.url
);
createMenuLinkEntry(
'Разблокировать по-другому',
(tab) => 'https://rebrand.ly/ac-unblock#' + tab.url
);
createMenuLinkEntry(
'Документация / Помощь / Поддержка',
(tab) => 'https://rebrand.ly/ac-support'
);
}

View File

@ -32,8 +32,9 @@
${scripts_2x}
, "35-pac-kitchen-api.js"
, "37-sync-pac-script-with-pac-provider-api.js"
${scripts_7x}
, "80-context-menus.js"
${scripts_8x}
, "70-menu-items.js"
, "75-context-menus.js"
]
},
"browser_action": {
@ -42,6 +43,6 @@
},
"options_ui": {
"page": "/pages/options/index.html",
"chrome_style": true
"chrome_style": false
}
}

View File

@ -0,0 +1,58 @@
<!DOCTYPE html>
<html style="display: none; will-change: contents, display">
<head>
<meta charset="utf-8">
<title>Последние ошибки</title>
<style>
html {
display: flex;
}
body {
display: inline-block;
margin: 0 auto;
}
table {
border-collapse: collapse;
background-color: #f3f5f6;
margin-bottom: 1em;
}
td, th {
border-style: solid;
border-width: 1px;
padding: 0.5em;
}
a:not(:hover) {
text-decoration: none;
}
tr > td:first-child {
text-align: center;
}
main {
display: block-inline;
margin: 0 auto;
}
h1,h2,h3,h4 {
text-align: center;
}
#addBtn {
float: right;
}
</style>
</head>
<body>
<h3>Список последних ошибок</h3>
<table>
<thead>
<tr>
<th>Индекс</th>
<th>Хост</th>
<th>Ошибка</th>
<th><a href id="allBtn">Все</a></th>
</tr>
</thead>
<tbody id="errorsTable"></tbody>
</table>
<button id="addBtn">Добавить в исключения</button>
<script src="./index.js"></script>
</body>
</html>

View File

@ -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 = `
<td>${index}</td>
<td ${style}>${err.hostname}</td>
<td>${err.message}</td>
<td><input type="checkbox" ${ err.ifChecked ? 'checked' : '' }></td>
`;
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 = '';
})
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

View File

@ -0,0 +1,346 @@
/*
* Copyright 2014 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* This stylesheet is used to apply Chrome styles to extension pages that opt in
* to using them.
*
* These styles have been copied from ui/webui/resources/css/chrome_shared.css
* and ui/webui/resources/css/widgets.css *with CSS class logic removed*, so
* that it's as close to a user-agent stylesheet as possible.
*
* For example, extensions shouldn't be able to set a .link-button class and
* have it do anything.
*
* Other than that, keep this file and chrome_shared.css/widgets.cc in sync as
* much as possible.
*/
body {
color: #333;
cursor: default;
/* Note that the correct font-family and font-size are set in
* extension_fonts.css. */
/* This top margin of 14px matches the top padding on the h1 element on
* overlays (see the ".overlay .page h1" selector in overlay.css), which
* every dialogue has.
*
* Similarly, the bottom 14px margin matches the bottom padding of the area
* which hosts the buttons (see the ".overlay .page * .action-area" selector
* in overlay.css).
*
* Both have a padding left/right of 17px.
*
* Note that we're putting this here in the Extension content, rather than
* the WebUI element which contains the content, so that scrollbars in the
* Extension content don't get a 6px margin, which looks quite odd.
*/
margin: 14px 17px;
}
p {
line-height: 1.8em;
}
h1,
h2,
h3 {
-webkit-user-select: none;
font-weight: normal;
/* Makes the vertical size of the text the same for all fonts. */
line-height: 1;
}
h1 {
font-size: 1.5em;
}
h2 {
font-size: 1.3em;
margin-bottom: 0.4em;
}
h3 {
color: black;
font-size: 1.2em;
margin-bottom: 0.8em;
}
a {
color: rgb(17, 85, 204);
text-decoration: underline;
}
a:active {
color: rgb(5, 37, 119);
}
/* Default state **************************************************************/
:-webkit-any(button,
input[type='button'],
input[type='submit']),
select,
input[type='checkbox'],
input[type='radio'] {
-webkit-appearance: none;
-webkit-user-select: none;
background-image: linear-gradient(#ededed, #ededed 38%, #dedede);
border: 1px solid rgba(0, 0, 0, 0.25);
border-radius: 2px;
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08),
inset 0 1px 2px rgba(255, 255, 255, 0.75);
color: #444;
font: inherit;
margin: 0 1px 0 0;
outline: none;
text-shadow: 0 1px 0 rgb(240, 240, 240);
}
:-webkit-any(button,
input[type='button'],
input[type='submit']),
select {
min-height: 2em;
min-width: 4em;
/*<if expr="is_win">
/* The following platform-specific rule is necessary to get adjacent
* buttons, text inputs, and so forth to align on their borders while also
* aligning on the text's baselines. */
padding-bottom: 1px;
/*</if>*/
}
:-webkit-any(button,
input[type='button'],
input[type='submit']) {
-webkit-padding-end: 10px;
-webkit-padding-start: 10px;
}
select {
-webkit-appearance: none;
-webkit-padding-end: 20px;
-webkit-padding-start: 6px;
/* OVERRIDE */
background-image: /*url(../../../ui/webui/resources/images/select.png),*/
linear-gradient(#ededed, #ededed 38%, #dedede);
background-position: right center;
background-repeat: no-repeat;
}
html[dir='rtl'] select {
background-position: center left;
}
input[type='checkbox'] {
height: 13px;
position: relative;
vertical-align: middle;
width: 13px;
}
input[type='radio'] {
/* OVERRIDE */
border-radius: 100%;
height: 15px;
position: relative;
vertical-align: middle;
width: 15px;
}
/* TODO(estade): add more types here? */
input[type='number'],
input[type='password'],
input[type='search'],
input[type='text'],
input[type='url'],
input:not([type]),
textarea {
border: 1px solid #bfbfbf;
border-radius: 2px;
box-sizing: border-box;
color: #444;
font: inherit;
margin: 0;
/* Use min-height to accommodate addditional padding for touch as needed. */
min-height: 2em;
padding: 3px;
outline: none;
<if expr="is_win or is_macosx or is_ios">
/* For better alignment between adjacent buttons and inputs. */
padding-bottom: 4px;
</if>
}
input[type='search'] {
-webkit-appearance: textfield;
/* NOTE: Keep a relatively high min-width for this so we don't obscure the end
* of the default text in relatively spacious languages (i.e. German). */
min-width: 160px;
}
/* Checked ********************************************************************/
input[type='checkbox']:checked::before {
-webkit-user-select: none;
background-image: url(./check.png);
background-size: 100% 100%;
content: '';
display: block;
height: 100%;
width: 100%;
}
input[type='radio']:checked::before {
background-color: #666;
border-radius: 100%;
bottom: 3px;
content: '';
display: block;
left: 3px;
position: absolute;
right: 3px;
top: 3px;
}
/* Hover **********************************************************************/
:enabled:hover:-webkit-any(
select,
input[type='checkbox'],
input[type='radio'],
:-webkit-any(
button,
input[type='button'],
input[type='submit'])) {
background-image: linear-gradient(#f0f0f0, #f0f0f0 38%, #e0e0e0);
border-color: rgba(0, 0, 0, 0.3);
box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12),
inset 0 1px 2px rgba(255, 255, 255, 0.95);
color: black;
}
:enabled:hover:-webkit-any(select) {
/* OVERRIDE */
background-image: /*url(../../../ui/webui/resources/images/select.png)*/,
linear-gradient(#f0f0f0, #f0f0f0 38%, #e0e0e0);
}
/* Active *********************************************************************/
:enabled:active:-webkit-any(
select,
input[type='checkbox'],
input[type='radio'],
:-webkit-any(
button,
input[type='button'],
input[type='submit'])) {
background-image: linear-gradient(#e7e7e7, #e7e7e7 38%, #d7d7d7);
box-shadow: none;
text-shadow: none;
}
:enabled:active:-webkit-any(select) {
/* OVERRIDE */
background-image: /*url(../../../ui/webui/resources/images/select.png),*/
linear-gradient(#e7e7e7, #e7e7e7 38%, #d7d7d7);
}
/* Disabled *******************************************************************/
:disabled:-webkit-any(
button,
input[type='button'],
input[type='submit']),
select:disabled {
background-image: linear-gradient(#f1f1f1, #f1f1f1 38%, #e6e6e6);
border-color: rgba(80, 80, 80, 0.2);
box-shadow: 0 1px 0 rgba(80, 80, 80, 0.08),
inset 0 1px 2px rgba(255, 255, 255, 0.75);
color: #aaa;
}
select:disabled {
/* OVERRIDE */
background-image: /*url(../../../ui/webui/resources/images/disabled_select.png),*/
linear-gradient(#f1f1f1, #f1f1f1 38%, #e6e6e6);
}
input:disabled:-webkit-any([type='checkbox'],
[type='radio']) {
opacity: .75;
}
input:disabled:-webkit-any([type='password'],
[type='search'],
[type='text'],
[type='url'],
:not([type])) {
color: #999;
}
/* Focus **********************************************************************/
:enabled:focus:-webkit-any(
select,
input[type='checkbox'],
input[type='number'],
input[type='password'],
input[type='radio'],
input[type='search'],
input[type='text'],
input[type='url'],
input:not([type]),
:-webkit-any(
button,
input[type='button'],
input[type='submit'])) {
/* OVERRIDE */
-webkit-transition: border-color 200ms;
/* We use border color because it follows the border radius (unlike outline).
* This is particularly noticeable on mac. */
border-color: rgb(77, 144, 254);
outline: none;
}
/* Checkbox/radio helpers ******************************************************
*
* .checkbox and .radio classes wrap labels. Checkboxes and radios should use
* these classes with the markup structure:
*
* <div class="checkbox">
* <label>
* <input type="checkbox"></input>
* <span>
* </label>
* </div>
*/
:-webkit-any(.checkbox, .radio) label {
/* Don't expand horizontally: <http://crbug.com/112091>. */
align-items: center;
display: inline-flex;
padding-bottom: 7px;
padding-top: 7px;
}
:-webkit-any(.checkbox, .radio) label input {
flex-shrink: 0;
}
:-webkit-any(.checkbox, .radio) label input ~ span {
-webkit-margin-start: 0.6em;
/* Make sure long spans wrap at the same horizontal position they start. */
display: block;
}
:-webkit-any(.checkbox, .radio) label:hover {
color: black;
}
label > input:disabled:-webkit-any([type='checkbox'], [type='radio']) ~ span {
color: #999;
}

View File

@ -0,0 +1 @@
ChromeStyle: https://cs.chromium.org/chromium/src/extensions/renderer/resources/extension.css

View File

@ -3,6 +3,7 @@
<head>
<meta charset="utf-8">
<title>Настройки</title>
<link rel="stylesheet" href="../lib/chrome-style/index.css">
<style><!-- Don't delete this mount point! --></style>
</head>
<body>

View File

@ -17,9 +17,15 @@ export default function getApp(theState) {
constructor(props) {
super(props);
const hash = window.location.hash.substr(1);
const hashParams = new URLSearchParams(hash);
console.log('GOT from', hash, hashParams.toString());
this.state = {
status: 'Загрузка...',
status: hashParams.get('status') || 'Загрузка...',
ifInputsDisabled: false,
hashParams,
};
}
@ -131,6 +137,7 @@ export default function getApp(theState) {
showErrors: this.showErrors.bind(this),
},
ifInputsDisabled: this.state.ifInputsDisabled,
hashParams: this.state.hashParams,
});
return createElement('div', null, [

View File

@ -332,7 +332,11 @@ export default function getExcEditor(theState) {
</li>
<li>
<input id="this-yes" type="radio" name="if-proxy-this-site" checked={inputProxyingState === true} onClick={onradio}/>
{' '}<label for="this-yes"><span class="emoji"></span>&nbsp;да</label>
{' '}<label for="this-yes">
<span
class="emoji____buggy"
></span>&nbsp;да
</label>
</li>
<li>
<input id="this-no" type="radio" name="if-proxy-this-site" checked={inputProxyingState === false} onClick={onradio}/>

View File

@ -62,6 +62,21 @@ export default function getExceptions(theState) {
})
}
<InfoLi
type="checkbox"
conf={{
key: 'lookupLastErrors',
desc: 'Собирать последние ошибки в запросах, чтобы вручную добавлять избранные из них в исключения.',
value: props.bgWindow.apis.lastErrors.ifCollecting
}}
onChange={(event) => {
props.bgWindow.apis.lastErrors.ifCollecting = event.target.checked;
props.funs.setStatusTo('Сделано.');
}}
nodeAfterLabel={(<span>Собирать <a href="../errors-to-exc/index.html">последние ошибки</a> сайтов</span>)}
/>
</ul>
</div>
);

View File

@ -1,4 +1,5 @@
import Inferno from 'inferno';
import createElement from 'inferno-create-element';
import css from 'csjs-inject';
export default function getInfoLi() {
@ -23,7 +24,6 @@ export default function getInfoLi() {
.infoRow {
position: relative;
flex-wrap: wrap;
}
.infoRow > input[type="checkbox"] {
position: relative;
@ -119,19 +119,11 @@ export default function getInfoLi() {
const iddy = props.idPrefix + ( props.ifDashify ? camelToDash(props.conf.key) : props.conf.key );
return (
<li class={scopedCss.infoRow + ' horFlex'}>
<input
type={props.type}
name={props.name}
checked={props.checked}
id={iddy}
onClick={props.onClick}
onChange={props.onChange}
disabled={props.disabled}
/>
<li class={scopedCss.infoRow + ' horFlex'} style={ props.children && 'flex-wrap: wrap'}>
{ createElement('input', Object.assign({}, props, {id: iddy})) }
<div class={scopedCss.labelContainer}>
<label for={iddy} dangerouslySetInnerHTML={{__html: props.conf.label}}></label>
&nbsp;{props.nodeAfterLabel}
{props.nodeAfterLabel}
</div>
{props.conf.desc
? (

View File

@ -69,6 +69,7 @@ export default function getMain(theState) {
handleModChange({targetConf, targetIndex, newValue}) {
console.log('NEW VALUE', newValue);
const oldCats = this.state.catToOrderedMods;
const newCats = Object.keys(this.state.catToOrderedMods).reduce((acc, cat) => {
@ -110,7 +111,7 @@ export default function getMain(theState) {
onConfChanged: this.handleModChange,
};
return createElement(TabPanel, {
return createElement(TabPanel, Object.assign({}, props, {
tabs: [
{
label: 'PAC-скрипт',
@ -160,7 +161,7 @@ export default function getMain(theState) {
alwaysShownWith: {
'applyMods': ['ownProxies', 'mods'],
},
});
}));
}

View File

@ -20,15 +20,13 @@ export default function getModList(theState) {
handleCheck(confMeta, ifChecked) {
this.state.checks[confMeta.index] = ifChecked;
if (ifChecked === false || !confMeta.ifChild) {
this.handleNewValue(confMeta, ifChecked);
} else {
this.setState({
checks: this.state.checks.map(
(ch, i) => i === confMeta.index ? ifChecked : ch
)
});
if (ifChecked === false || !confMeta.ifChild) {
this.handleNewValue(confMeta, ifChecked);
}
}
@ -63,7 +61,7 @@ export default function getModList(theState) {
conf={conf}
type='checkbox'
name={props.name}
checked={conf.value}
checked={this.state.checks[index]}
key={index}
onChange={(event) => this.handleCheck(confMeta, event.target.checked)}
>

View File

@ -28,6 +28,7 @@ export default function getPacChooser(theState) {
.updateButton {
visibility: hidden;
margin-left: 0.5em;
}
input:checked + div .updateButton {
visibility: inherit;

View File

@ -25,14 +25,38 @@ export default function getProxyEditor(theState) {
height: 100%;
}
table.editor input,
table.editor button,
table.editor select
{
min-width: 0;
min-height: 0;
}
/* 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) input /* PORT */
{
font-size: 0.9em;
}
table.editor tr.addPanel td:nth-last-child(2) input /* PORT */
{
min-width: 4em;
}
/* 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;
@ -56,8 +80,6 @@ export default function getProxyEditor(theState) {
/* BUTTONS */
table.editor input[type="submit"],
table.editor button {
min-width: 0;
min-height: 0;
width: 100%;
padding: 0;
border: none;
@ -74,7 +96,7 @@ export default function getProxyEditor(theState) {
font-weight: 900;
}
table.editor .export {
padding-right: 2px;
/*padding-right: 2px;*/
}
/* LAST COLUMN: BUTTONS */
@ -93,7 +115,7 @@ export default function getProxyEditor(theState) {
padding: 0;
}
.padLeft {
padding-left: 2px;
padding-left: 2px !important;
}
textarea.textarea {
@ -266,7 +288,7 @@ export default function getProxyEditor(theState) {
<td>
{/* LAST-1: PORT */}
<input required type="number" disabled={props.ifInputsDisabled}
class={scopedCss.noPad + ' ' + scopedCss.padLeft} style="min-width: 4em"
class={scopedCss.noPad + ' ' + scopedCss.padLeft}
placeholder="9150"
min="0" step="1" max={MAX_PORT} pattern="[0-9]{1,5}"
name="port"
@ -296,7 +318,10 @@ export default function getProxyEditor(theState) {
class={scopedCss.only} title="Удалить"
onClick={() => this.handleDelete(this, {proxyAsString, index})}
>X</button>
</td><td>{type}</td><td>{hostname}</td><td>{port}</td>
</td>
<td>{type}</td>
<td><input value={hostname} name="hostname" readonly/></td>
<td>{port}</td>
<td>
<button type="button" disabled={props.ifInputsDisabled}
class={scopedCss.only} title="Повысить приоритет"

View File

@ -114,8 +114,9 @@ export default function getTabPannel({ flags, baseCss }) {
constructor(props) {
super(props);
const fromHash = props.hashParams.get('tab');
this.state = {
chosenTabIndex: 0,
chosenTabKeyRaw: fromHash,
};
}
@ -123,7 +124,19 @@ export default function getTabPannel({ flags, baseCss }) {
render(props) {
const indexedTabs = props.tabs.filter((tab) => tab.label);
const chosenTabKey = indexedTabs[this.state.chosenTabIndex].key;
let [chosenTabIndex] = indexedTabs
.map((tab, index) => tab.key === this.state.chosenTabKeyRaw ? index : false)
.filter((index) => index !== false);
if (!(chosenTabIndex >= 0)) {
chosenTabIndex = 0;
}
const chosenTabKey = indexedTabs[chosenTabIndex].key;
if (chosenTabKey !== props.hashParams.get('tab')) {
props.hashParams.set('tab', chosenTabKey);
window.location.hash = props.hashParams.toString();
}
return (
<div>
@ -132,8 +145,8 @@ export default function getTabPannel({ flags, baseCss }) {
{
indexedTabs.map((tab, index) =>
(<li>
<input type="radio" name="selectedTabLabel" id={'radioLabel' + index} checked={this.state.chosenTabIndex === index} class="off"/>
<label onClick={() => this.setState({chosenTabIndex: index})} for={'radioLabel' + index} class={scopedCss.navLabel}>{tab.label}</label>
<input type="radio" name="selectedTabLabel" id={'radioLabel' + index} checked={chosenTabIndex === index} class="off"/>
<label onClick={() => this.setState({chosenTabKeyRaw: tab.key})} for={'radioLabel' + index} class={scopedCss.navLabel}>{tab.label}</label>
</li>)
)
}

View File

@ -0,0 +1,35 @@
'use strict';
{
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;
}
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: '●●●',
});
});
}

View File

@ -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: ['<all_urls>']}
);
}

View File

@ -18,10 +18,6 @@
const chromified = window.utils.chromified;
window.chrome.browserAction.setBadgeBackgroundColor({
color: '#db4b2f',
});
const _tabCallbacks = {};
const afterTabUpdated = function afterTabUpdated(tabId, cb) {
@ -45,6 +41,15 @@
chrome.tabs.onUpdated.addListener( onTabUpdate );
const setRedBadge = (opts) => {
window.chrome.browserAction.setBadgeBackgroundColor({
color: '#db4b2f',
});
chrome.browserAction.setBadgeText(opts);
};
const updateTitle = function updateTitle(requestDetails, proxyHost, cb) {
chrome.browserAction.getTitle(
@ -71,7 +76,7 @@
+ proxyTitle + '\n' + indent + proxyHost;
ifShouldUpdateTitle = true;
chrome.browserAction.setBadgeText({
setRedBadge({
tabId: requestDetails.tabId,
text: requestDetails.type === 'main_frame' ? '1' : '%1',
});
@ -101,13 +106,11 @@
{tabId: requestDetails.tabId},
(result) => {
chrome.browserAction.setBadgeText(
{
setRedBadge({
tabId: requestDetails.tabId,
text: (isNaN( result.charAt(0)) && result.charAt(0) || '')
+ (hostsProxiesPair[0].split('\n').length - 1),
}
);
});
return _cb();
}

View File

@ -10,10 +10,10 @@ exports.contexts.full = Object.assign({}, commonContext, {
versionSuffix: '',
nameSuffixEn: '',
nameSuffixRu: '',
extra_permissions: ', "webRequest"',
extra_permissions: ', "webRequest", "webNavigation"',
persistent: '',
scripts_2x: ', "20-ip-to-host-api.js"',
scripts_7x: ', "70-block-informer.js"',
scripts_8x: ', "80-error-menu.js", "83-last-errors.js", "85-block-informer.js"',
});
exports.contexts.mini = Object.assign({}, commonContext, {
@ -23,6 +23,6 @@ exports.contexts.mini = Object.assign({}, commonContext, {
extra_permissions: '',
persistent: '"persistent": false,',
scripts_2x: ', "20-for-mini-only.js"',
scripts_7x: '',
scripts_8x: '',
});