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

View File

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

View File

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

View File

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