Finish categories for UI

This commit is contained in:
Ilya Ig. Petrov 2017-04-24 05:16:32 -07:00
parent a1f6784fae
commit 8d1def5a85
4 changed files with 464 additions and 382 deletions

View File

@ -65,25 +65,27 @@
desc: 'Учитывать сайты, добавленные вручную. Только для своих прокси-серверов! Без своих прокси работать не будет.',
order: 6,
},
ifProxyErrors: {
dflt: false,
category: 'exceptions',
label: 'проксировать <a href>выбранные</a> ошибки',
desc: 'Предлагать добавить сайт в исключения при выбранных ошибках',
order: 7,
},
customProxyStringRaw: {
dflt: '',
category: 'ownProxies',
label: 'использовать СВОИ прокси',
url: 'https://rebrand.ly/ac-own-proxy',
order: 8,
order: 7,
},
ifProxyMoreDomains: {
ifDisabled: true,
dflt: false,
category: 'ownProxies',
label: 'проксировать .onion, .i2p и OpenNIC',
desc: 'Проксировать особые домены. Необходима поддержка со стороны прокси.',
order: 8,
},
ifProxyErrors: {
ifDisabled: true,
dflt: false,
category: 'ownProxies',
label: 'проксировать <a href>избранные</a> ошибки',
desc: 'Предлагать добавить сайт в исключения при выбранных ошибках.',
order: 9,
},

View File

@ -8,8 +8,10 @@
--ribbon-color: #4169e1;
--blue-bg: dodgerblue;
--default-grey: #bfbfbf;
--mild-hr: #d3d3d3;
--hr: #bababa;
--cr-options-headline: #d3d3d3;
--cr-icon-selected: #d7d7d7;
--cr-popup-border: #bababa;
--cr-grey-panel: #f2f2f2;
max-width: 28em;
}
body {
@ -70,7 +72,7 @@
}
hr {
border: none;
border-top: 1px solid var(--hr);
border-top: 1px solid var(--cr-popup-border);
margin: 0 0 0.6em 0;
padding: 0;
}
@ -143,12 +145,18 @@
section[data-for] {
padding: 0.6em 0 1em;
}
section[data-for] li label {
display: inline-block; /* Needed for ::first-letter below. */
}
section[data-for] li label::first-letter {
text-transform: uppercase;
}
:root.if-options-page section[data-for] {
padding-bottom: 0.6em;
}
:root.if-options-page section[data-for]:not(:last-child),
.underlined {
border-bottom: 1px solid var(--mild-hr);
border-bottom: 1px solid var(--cr-options-headline);
}
/* HIDE starts. */
@ -158,7 +166,7 @@
:root:not(.if-options-page) #acc-mods:not(:checked) ~ .main-nav section[data-for="acc-mods"],
:root:not(.if-options-page) #acc-ntf:not(:checked) ~ .main-nav section[data-for="acc-ntf"],
/* One button shared between two sections: */
:root:not(.if-options-page) #acc-own-mods:not(:checked) + #acc-mods:not(:checked) ~ .main-nav #apply-mods-button
:root:not(.if-options-page) #acc-own-mods:not(:checked) + #acc-mods:not(:checked) ~ .main-nav #apply-mods-section
{
/* Hide, but preclude width resizes. */
height: 0px !important;
@ -178,7 +186,7 @@
:root:not(.if-options-page) #acc-mods:not(:checked) ~ .main-nav section[data-for="acc-mods"] *,
:root:not(.if-options-page) #acc-ntf:not(:checked) ~ .main-nav section[data-for="acc-ntf"] *,
/* One button shared between two sections: */
:root:not(.if-options-page) #acc-own-mods:not(:checked) + #acc-mods:not(:checked) ~ .main-nav #apply-mods-button *
:root:not(.if-options-page) #acc-own-mods:not(:checked) + #acc-mods:not(:checked) ~ .main-nav #apply-mods-section *
{
margin-top: 0 !important;
margin-bottom: 0 !important;
@ -186,7 +194,7 @@
/* HIDE ends. */
.nav-labels {
background-color: var(--chrome-grey);
background-color: var(--cr-grey-panel);
text-align: center;
}
.nav-labels li label {
@ -242,6 +250,11 @@
/* INFO SIGNS */
input:disabled + .label-container label {
color: var(--default-grey);
pointer-events: none;
}
.info-row {
position: relative;
}
@ -302,7 +315,7 @@
width: calc(25% + 0.6em);
}
/* TAB_1 PAC PROVIDER */
/* TAB_1: PAC PROVIDER */
.update-button {
visibility: hidden;
@ -323,14 +336,8 @@
margin-top: 0.5em;
}
/* TAB_2 PAC MODS */
/* TAB_2: PAC MODS */
#pac-mods label {
display: block;
}
#pac-mods label:first-letter {
text-transform: uppercase;
}
#mods-custom-proxy-string-raw ~ textarea {
width: 100%;
height: 7em;
@ -341,7 +348,9 @@
display: none;
}
/* TAB_3 EXCEPTIONS */
/* TAB_3: EXCEPTIONS */
/* EXC-EDITOR starts. */
#exc-address-container {
display: flex;
align-items: center;
@ -389,6 +398,14 @@
color: red;
}
/* EXC-EDITOR ends. */
#exc-mods {
padding-top: 1em;
}
#exc-mods input#mods-if-mind-exceptions:not(:checked) + .label-container label {
color: red;
}
/* CONTROL RAW = BUTTON + LINK */
.hor-flex {
@ -401,7 +418,7 @@
margin: 1em 0 1em 0;
}
.hor-flex > input:not([type="button"]) {
.hor-flex input:not([type="button"]) {
align-self: flex-end;
}
.label-container {
@ -495,6 +512,7 @@
</section>
<section data-for="acc-exc" class="hidden-for-options-page">
<section class="exc-editor-section" style="padding-bottom: 1em;">
<div>Проксировать указанный сайт?</div>
<div id="exc-address-container">
<div id="exc-address">
@ -515,18 +533,20 @@
<li><input id="this-yes" type="radio" name="if-proxy-this-site"/> <label for="this-yes">&nbsp;да</label></li>
<li><input id="this-no" type="radio" name="if-proxy-this-site"/> <label for="this-no">&nbsp;нет</label></li>
</ol>
</section>
<ul id="exc-mods"></ul>
</section>
<section data-for="acc-own-mods">
<ul id="own-proxies"></ul>
<ul id="own-mods"></ul>
</section>
<section data-for="acc-mods">
<ul id="pac-mods"></ul>
</section>
<section id="apply-mods-button" class="control-row hor-flex" style="margin-top: 0.2em">
<section id="apply-mods-section" class="control-row hor-flex" style="margin-top: 0.2em">
<input type="button" value="Применить" id="apply-mods" disabled/>
<a href id="reset-mods">К изначальным!</a>
</section>

View File

@ -1,13 +1,21 @@
'use strict';
const START = Date.now();
{
document.getElementById('pac-mods').onchange = function() {
const enableButton = function enablebutton() {
this.classList.add('changed');
document.getElementById('apply-mods').disabled = false;
};
};
['pac-mods', 'own-mods'].forEach((id) => {
document.getElementById(id).onchange = enableButton;
});
}
chrome.runtime.getBackgroundPage( (backgroundPage) =>
backgroundPage.apis.errorHandlers.installListenersOn(
@ -131,7 +139,13 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
const inputs = document.querySelectorAll('input');
for ( let i = 0; i < inputs.length; i++ ) {
inputs[i].disabled = val === 'on' ? false : true;
const input = inputs[i];
if (val === 'off') {
input.dataset.previousDisabledValue = input.disabled;
input.disabled = true;
} else {
input.disabled = input.dataset.previousDisabledValue === 'true';
}
}
};
@ -176,18 +190,22 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
const appendInfoRow = (mountEl, conf, inputTypeName, inputId, htmlAfterLabel = '') => {
mountEl.classList.add('info-row', 'hor-flex');
if (conf.ifDisabled) {
mountEl.title = 'В РАЗРАБОТКЕ!';
}
mountEl.innerHTML = `
<input ${inputTypeName} id="${inputId}">
<input ${inputTypeName} id="${inputId}" ${conf.ifDisabled ? 'disabled' : ''}>
<div class="label-container">
<label for="${inputId}"> ${conf.label}</label>
<label for="${inputId}">${conf.label}</label>
${htmlAfterLabel}
</div>` + (conf.desc ? infoSign(conf.desc) : infoUrl(conf.url));
};
{
const ul = document.querySelector('#list-of-providers');
const _firstChild = ul.firstChild;
{ // PAC-PROVIDERS starts.
const ul = document.getElementById('list-of-providers');
const _firstChildOrNull = ul.firstChild;
for(
const provConf of antiCensorRu.getSortedEntriesForProviders()
) {
@ -204,16 +222,11 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
);
return false;
};
ul.insertBefore( li, _firstChild );
ul.insertBefore( li, _firstChildOrNull );
}
checkChosenProvider();
}
const radios = [].slice.apply(
document.querySelectorAll('[name=pacProvider]')
);
for(const radio of radios) {
radio.onclick = function(event) {
const radioClickHandler = function radioClickHandler(event) {
if (
event.target.id === (
@ -240,7 +253,14 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
}
return false;
};
}
document.querySelectorAll('input[name=pacProvider]').forEach((radio) => {
radio.onclick = radioClickHandler;
});
} // PAC-PROVIDERS ends.
// IF MINI
@ -266,9 +286,53 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
{ // KITCHEN PANELS starts.
const pacKitchen = backgroundPage.apis.pacKitchen;
const camelToDash = (name) => name.replace(/([A-Z])/g, (_, p) => '-' + p.toLowerCase());
const modKeyToLi = {};
const applyMods = function applyMods(newMods) {
conduct(
'Применяем настройки...',
(cb) => pacKitchen.keepCookedNowAsync(newMods, cb),
'Настройки применены.',
() => {
document.getElementById('apply-mods').disabled = true;
}
);
};
{ // EXCEPTIONS TAB starts.
{ // EXC-MODS starts.
const emodsList = document.getElementById('exc-mods');
const _firstChildOrNull = emodsList.firstChild;
for(const conf of pacKitchen.getOrderedConfigs('exceptions')) {
const key = conf.key;
const iddy = 'mods-' + camelToDash(conf.key);
const li = document.createElement('li');
appendInfoRow(li, conf, `type="checkbox" ${conf.value ? 'checked' : ''}`, iddy);
emodsList.insertBefore( li, _firstChildOrNull );
modKeyToLi[key] = li;
li.querySelector('input').onclick = function() {
const oldMods = pacKitchen.getPacMods();
oldMods[key] = this.checked;
applyMods(oldMods);
};
};
}// EXC-MODS ends.
{ // EXC-EDITOR starts.
const excEditor = document.getElementById('exc-editor');
const validateHost = function validateHost(host) {
@ -524,17 +588,35 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
};
} // EXC-EDITOR ends.
} // EXCEPTIONS TAB ends.
const camelToDash = (name) => name.replace(/([A-Z])/g, (_, p) => '-' + p.toLowerCase());
{ // PAC MODS TAB starts.
const modsList = document.getElementById('pac-mods');
const _firstChildOrNull = modsList.firstChild;
for(const conf of pacKitchen.getOrderedConfigs('general')) {
const key = conf.key;
const iddy = 'mods-' + camelToDash(conf.key);
const li = document.createElement('li');
appendInfoRow(li, conf, `type="checkbox" ${conf.value ? 'checked' : ''}`, iddy);
modsList.insertBefore( li, _firstChildOrNull );
modKeyToLi[key] = li;
};
} // PAC MODS TAB ends.
const customProxyStringKey = 'customProxyStringRaw';
const uiRaw = 'ui-proxy-string-raw';
{ // OWN PROXIES TAB starts.
const ownsList = document.getElementById('own-proxies');
const _firstChild = ownsList.firstChild;
const keyToLi = {};
const customProxyStringKey = 'customProxyStringRaw';
const uiRaw = 'ui-proxy-string-raw';
const ownsList = document.getElementById('own-mods');
const _firstChildOrNull = ownsList.firstChild;
for(const conf of pacKitchen.getOrderedConfigs('ownProxies')) {
@ -561,39 +643,26 @@ PROXY foobar.com:8080; # Not HTTP!">${conf.value || localStorage.getItem(uiRaw)
};
}
ownsList.insertBefore( li, _firstChild );
ownsList.insertBefore( li, _firstChildOrNull );
modKeyToLi[key] = li;
}
} // OWN PROXIES TAB ends.
{ // PAC MODS TAB starts.
{ // APPLY MODS PANEL starts.
const modsList = document.getElementById('pac-mods');
const _firstChild = modsList.firstChild;
const keyToLi = {};
for(const conf of pacKitchen.getOrderedConfigs('general')) {
const key = conf.key;
const iddy = 'mods-' + camelToDash(conf.key);
const li = document.createElement('li');
appendInfoRow(li, conf, `type="checkbox" ${conf.value ? 'checked' : ''}`, iddy);
keyToLi[key] = li;
modsList.insertBefore( li, _firstChild );
};
document.getElementById('apply-mods').onclick = () => {
const oldMods = pacKitchen.getPacMods();
for(const key of Object.keys(keyToLi)) {
oldMods[key] = keyToLi[key].querySelector('input').checked;
for(const key of Object.keys(modKeyToLi)) {
oldMods[key] = modKeyToLi[key].querySelector('input').checked;
};
{
// OWN PROXY
const liPs = keyToLi[customProxyStringKey];
const liPs = modKeyToLi[customProxyStringKey];
oldMods[customProxyStringKey]
= liPs.querySelector('input').checked
&& liPs.querySelector('textarea').value.trim();
@ -621,17 +690,7 @@ PROXY foobar.com:8080; # Not HTTP!">${conf.value || localStorage.getItem(uiRaw)
}
}
conduct(
'Применяем настройки...',
(cb) => pacKitchen.keepCookedNowAsync(oldMods, cb),
'Настройки применены.',
() => {
document.getElementById('apply-mods').disabled = true;
}
);
applyMods(oldMods);
};
@ -653,9 +712,9 @@ PROXY foobar.com:8080; # Not HTTP!">${conf.value || localStorage.getItem(uiRaw)
() => window.close()
);
};
}
} // PAC MODS TAB ends.
} // APPLY MODS PANEL ends.
} // KITCHEN PANELS ends.

View File

@ -16,7 +16,8 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
# Комментарии НЕ сохраняются!
# Сначала идёт список проксируемых сайтов,
# затем ==== на отдельной строке,
# затем исключённые сайты, отсортированные с конца строки.
# затем исключённые сайты.
# Сортировка с конца строки.
# ПРОКСИРОВАТЬ: