Get rid of obsolete var

This commit is contained in:
Ilya Ig. Petrov 2016-11-20 05:33:30 -08:00
parent 1ef480acd1
commit b56a1f2484

View File

@ -3,28 +3,33 @@
chrome.runtime.getBackgroundPage( backgroundPage => { chrome.runtime.getBackgroundPage( backgroundPage => {
function getStatus() { function getStatus() {
return document.querySelector('#status'); return document.querySelector('#status');
} }
function setStatusTo(msg) { function setStatusTo(msg) {
var status = getStatus();
const status = getStatus();
if (msg) { if (msg) {
status.classList.remove('off'); status.classList.remove('off');
status.innerHTML = msg; status.innerHTML = msg;
} else } else
status.classList.add('off'); status.classList.add('off');
} }
var antiCensorRu = backgroundPage.antiCensorRu; const antiCensorRu = backgroundPage.antiCensorRu;
// SET DATE // SET DATE
function setDate() { function setDate() {
var dateForUser = 'никогда';
let dateForUser = 'никогда';
if( antiCensorRu.lastPacUpdateStamp ) { if( antiCensorRu.lastPacUpdateStamp ) {
var diff = Date.now() - antiCensorRu.lastPacUpdateStamp; let diff = Date.now() - antiCensorRu.lastPacUpdateStamp;
var units = ' мс'; let units = ' мс';
var gauges = [ const gauges = [
[1000, ' с'], [1000, ' с'],
[60, ' мин'], [60, ' мин'],
[60, ' ч'], [60, ' ч'],
@ -33,23 +38,24 @@ chrome.runtime.getBackgroundPage( backgroundPage => {
[4, ' месяцев'], [4, ' месяцев'],
[12, ' г'] [12, ' г']
]; ];
for(var g of gauges) { for(const g of gauges) {
var diffy = Math.floor(diff / g[0]); const diffy = Math.floor(diff / g[0]);
if (!diffy) if (!diffy)
break; break;
diff = diffy; diff = diffy;
var units = g[1]; units = g[1];
} }
dateForUser = diff + units + ' назад'; dateForUser = diff + units + ' назад';
} }
var dateElement = document.querySelector('.update-date'); const dateElement = document.querySelector('.update-date');
dateElement.innerText = dateForUser; dateElement.innerText = dateForUser;
dateElement.title = new Date(antiCensorRu.lastPacUpdateStamp).toLocaleString('ru-RU'); dateElement.title = new Date(antiCensorRu.lastPacUpdateStamp).toLocaleString('ru-RU');
} }
setDate(); setDate();
chrome.storage.onChanged.addListener( changes => changes.lastPacUpdateStamp.newValue && setDate() ); chrome.storage.onChanged.addListener( (changes) => changes.lastPacUpdateStamp.newValue && setDate() );
// CLOSE BUTTON // CLOSE BUTTON
@ -57,39 +63,45 @@ chrome.runtime.getBackgroundPage( backgroundPage => {
// RADIOS // RADIOS
var currentRadio = () => { const currentRadio = () => {
var id = antiCensorRu.currentPacProviderKey || 'none';
const id = antiCensorRu.currentPacProviderKey || 'none';
return document.querySelector('#'+id); return document.querySelector('#'+id);
} }
var checkChosenProvider = () => { const checkChosenProvider = () => {
var radio = currentRadio();
radio.checked = true; currentRadio().checked = true;
} }
var triggerChosenProvider = () => { const triggerChosenProvider = () => {
var event = document.createEvent('HTMLEvents');
const event = document.createEvent('HTMLEvents');
event.initEvent('change', false, true); event.initEvent('change', false, true);
currentRadio().dispatchEvent(event); currentRadio().dispatchEvent(event);
} }
var ul = document.querySelector('#list-of-providers'); const ul = document.querySelector('#list-of-providers');
var _firstChild = ul.firstChild; //const _firstChild = ul.firstChild;
for( var providerKey of Object.keys(antiCensorRu.pacProviders) ) { for( const providerKey of Object.keys(antiCensorRu.pacProviders) ) {
var li = document.createElement('li'); const li = document.createElement('li');
li.innerHTML = '<input type="radio" name="pacProvider" id="' + providerKey + '"> <label for="' + providerKey + '">'+providerKey + '</label> <a href class="link-button checked-radio-panel">[обновить]</a>'; li.innerHTML = '<input type="radio" name="pacProvider" id="' + providerKey + '"> <label for="' + providerKey + '">'+providerKey + '</label> <a href class="link-button checked-radio-panel">[обновить]</a>';
li.querySelector('.link-button').onclick = () => { triggerChosenProvider(); return false; }; li.querySelector('.link-button').onclick = () => { triggerChosenProvider(); return false; };
ul.insertBefore( li, _firstChild ); ul.insertBefore( li, ul.firstChild );
} }
var radios = [].slice.apply( document.querySelectorAll('[name=pacProvider]') ); const radios = [].slice.apply( document.querySelectorAll('[name=pacProvider]') );
for(var radio of radios) { for(const radio of radios) {
radio.onchange = function(event) { radio.onchange = function(event) {
var pacKey = event.target.id;
const pacKey = event.target.id;
if (pacKey === 'none') if (pacKey === 'none')
return antiCensorRu.clearPac(); return antiCensorRu.clearPac();
function enableDisableInputs() { function enableDisableInputs() {
var inputs = document.querySelectorAll('input'); const inputs = document.querySelectorAll('input');
for (var i = 0; i < inputs.length; i++) for (const i = 0; i < inputs.length; i++)
inputs[i].disabled = !inputs[i].disabled; inputs[i].disabled = !inputs[i].disabled;
} }
@ -102,10 +114,10 @@ chrome.runtime.getBackgroundPage( backgroundPage => {
setStatusTo('PAC-скрипт установлен.'); setStatusTo('PAC-скрипт установлен.');
} }
else { else {
var ifNotCritical = err.clarification && err.clarification.ifNotCritical; const ifNotCritical = err.clarification && err.clarification.ifNotCritical;
var message = ''; let message = '';
var clarification = err.clarification; let clarification = err.clarification;
do { do {
message = message +' '+ (clarification && clarification.message || err.message || ''); message = message +' '+ (clarification && clarification.message || err.message || '');
clarification = clarification.prev; clarification = clarification.prev;
@ -118,7 +130,8 @@ chrome.runtime.getBackgroundPage( backgroundPage => {
<a href class="link-button">[Ещё&nbsp;подробнее]</a>` <a href class="link-button">[Ещё&nbsp;подробнее]</a>`
); );
getStatus().querySelector('.link-button').onclick = function() { getStatus().querySelector('.link-button').onclick = function() {
var div = document.createElement('div');
const div = document.createElement('div');
div.innerHTML = ` div.innerHTML = `
Более подробную информацию можно узнать из логов фоновой страницы:<br/> Более подробную информацию можно узнать из логов фоновой страницы:<br/>
<a href class="ext">chrome://extensions</a> Это расширение Отладка страниц: фоновая страница Console (DevTools) <a href class="ext">chrome://extensions</a> Это расширение Отладка страниц: фоновая страница Console (DevTools)
@ -127,10 +140,13 @@ chrome.runtime.getBackgroundPage( backgroundPage => {
`; `;
getStatus().replaceChild(div, this); getStatus().replaceChild(div, this);
div.querySelector('.ext').onclick = () => { div.querySelector('.ext').onclick = () => {
chrome.tabs.create({ url: 'chrome://extensions?id='+ chrome.runtime.id }); chrome.tabs.create({ url: 'chrome://extensions?id='+ chrome.runtime.id });
return false; return false;
} }
return false; return false;
}; };
} }
enableDisableInputs(); enableDisableInputs();