From 9420177df246ec45994dfb3ac9d0403139c5aa95 Mon Sep 17 00:00:00 2001 From: "Ilya Ig. Petrov" Date: Tue, 26 Jan 2016 15:38:40 +0500 Subject: [PATCH] update button added --- .../extnesion/manifest.json | 2 +- .../pages/choose-pac-provider/index.html | 29 +++++++++- .../pages/choose-pac-provider/index.js | 58 +++++++++++++++---- .../sync-pac-script-with-pac-provider.js | 8 ++- 4 files changed, 83 insertions(+), 14 deletions(-) diff --git a/extensions/chromium/minimalistic-pac-setter/extnesion/manifest.json b/extensions/chromium/minimalistic-pac-setter/extnesion/manifest.json index 2d6e80f..a56de05 100755 --- a/extensions/chromium/minimalistic-pac-setter/extnesion/manifest.json +++ b/extensions/chromium/minimalistic-pac-setter/extnesion/manifest.json @@ -25,6 +25,6 @@ }, "options_ui": { "page": "/pages/choose-pac-provider/index.html", - "chrome_style": false + "chrome_style": true } } diff --git a/extensions/chromium/minimalistic-pac-setter/extnesion/pages/choose-pac-provider/index.html b/extensions/chromium/minimalistic-pac-setter/extnesion/pages/choose-pac-provider/index.html index cf38dbe..7aaa7a4 100755 --- a/extensions/chromium/minimalistic-pac-setter/extnesion/pages/choose-pac-provider/index.html +++ b/extensions/chromium/minimalistic-pac-setter/extnesion/pages/choose-pac-provider/index.html @@ -7,21 +7,48 @@ list-style-type: none; padding: 0; margin: 0; + margin-bottom: 1em; } li { display: block; white-space: nowrap; } + li > * { + vertical-align: middle; + } + input[type="radio"], label { + cursor: pointer; + } .off { display: none; } + .link-button, .link-button:visited { + color: #0000EE; + text-decoration: none; + display: none; + } + .link-button:hover { + text-decoration: underline; + } + input:checked ~ .link-button { + display: inline; + } + .button-panel { + margin-top: 1em; + } -
Загрузка...
+
+ Обновлялись: ... +
+
Загрузка...
+
+ +
diff --git a/extensions/chromium/minimalistic-pac-setter/extnesion/pages/choose-pac-provider/index.js b/extensions/chromium/minimalistic-pac-setter/extnesion/pages/choose-pac-provider/index.js index 7ffd79f..e35dac8 100755 --- a/extensions/chromium/minimalistic-pac-setter/extnesion/pages/choose-pac-provider/index.js +++ b/extensions/chromium/minimalistic-pac-setter/extnesion/pages/choose-pac-provider/index.js @@ -11,20 +11,48 @@ chrome.runtime.getBackgroundPage( backgroundPage => { var antiCensorRu = backgroundPage.antiCensorRu; - var ul = document.querySelector('#list-of-providers'); - var _firstChild = ul.firstChild; - for( var providerKey of Object.keys(antiCensorRu.pacProviders) ) { - var li = document.createElement('li'); - li.innerHTML = ' '; - ul.insertBefore( li, _firstChild ); + // DATE + + var dateForUser = 'неизвестно'; + if( antiCensorRu.lastPacUpdateStamp ) { + var diff = Date.now() - antiCensorRu.lastPacUpdateStamp; + var units = ' мс' + var gauges = [ + [1000, ' с'], + [60, ' мин'], + [60, ' ч'], + [24, ' дн'], + [7, ' недель'], + [4, ' месяцев'], + [12, ' г'] + ]; + for(var g of gauges) { + var diffy = Math.floor(diff / g[0]); + if (!diffy) + break; + diff = diffy; + var units = g[1]; + } + dateForUser = diff + units + ' назад'; } + var dateElement = document.querySelector('.update-date'); + dateElement.innerText = dateForUser; + dateElement.title = new Date(antiCensorRu.lastPacUpdateStamp).toLocaleString('ru-RU'); + + // CLOSE + + document.querySelector('.close-button').onclick = () => window.close(); + + // RADIOS + var currentRadio = () => { var id = antiCensorRu.currentPacProviderKey || 'none'; return document.querySelector('#'+id); } var checkChosenProvider = () => { - currentRadio().checked = true; + var radio = currentRadio(); + radio.checked = true; } var triggerChosenProvider = () => { var event = document.createEvent('HTMLEvents'); @@ -32,15 +60,25 @@ chrome.runtime.getBackgroundPage( backgroundPage => { currentRadio().dispatchEvent(event); } + var ul = document.querySelector('#list-of-providers'); + var _firstChild = ul.firstChild; + for( var providerKey of Object.keys(antiCensorRu.pacProviders) ) { + var li = document.createElement('li'); + li.innerHTML = ' [обновить]'; + li.querySelector('.link-button').onclick = () => {triggerChosenProvider(); return false;}; + ul.insertBefore( li, _firstChild ); + } + var radios = [].slice.apply( document.querySelectorAll('[name=pacProvider]') ); for(var radio of radios) { radio.onchange = function(event) { var pacKey = event.target.id; if (pacKey === 'none') - return antiCensorRu.clearPac( () => window && window.close() ); + return antiCensorRu.clearPac(); function enableDisableInputs() { - var inputs = document.querySelectorAll('[name="pacProvider"]'); + var inputs = document.querySelectorAll('input'); + console.log(inputs.length); for (var i = 0; i < inputs.length; i++) inputs[i].disabled = !inputs[i].disabled; } @@ -49,7 +87,7 @@ chrome.runtime.getBackgroundPage( backgroundPage => { setStatusTo('Установка...'); antiCensorRu.installPac(pacKey, () => { setStatusTo('PAC-скрипт установлен.'); - if(window) window.close(); + enableDisableInputs(); }); } } diff --git a/extensions/chromium/minimalistic-pac-setter/extnesion/sync-pac-script-with-pac-provider.js b/extensions/chromium/minimalistic-pac-setter/extnesion/sync-pac-script-with-pac-provider.js index 567ae0f..72021a6 100755 --- a/extensions/chromium/minimalistic-pac-setter/extnesion/sync-pac-script-with-pac-provider.js +++ b/extensions/chromium/minimalistic-pac-setter/extnesion/sync-pac-script-with-pac-provider.js @@ -73,10 +73,14 @@ window.antiCensorRu = { }); }, + lastPacUpdateStamp: 0, + syncWithPacProvider(cb) { setPacScriptFromProvider( this.pacProvider, - () => { + err => { + if (!err) + this.lastPacUpdateStamp = Date.now(); updatePacProxyIps( this.pacProvider, () => { @@ -155,7 +159,7 @@ window.antiCensorRu.pullFromStorage( () => { chrome.alarms.onAlarm.addListener( alarm => { if (alarm.name === window.antiCensorRu._periodicUpdateAlarmReason) { - console.log('Periodic update triggered.'); + console.log('Periodic update triggered:', new Date()); window.antiCensorRu.syncWithPacProvider(); } }