live updates for date

This commit is contained in:
Ilya Ig. Petrov 2016-01-26 21:47:09 +05:00
parent a4b83d100c
commit 6c2b2eba30
2 changed files with 108 additions and 91 deletions

View File

@ -1,22 +1,30 @@
function setStatusTo(msg) {
'use strict';
renderPage();
function renderPage() {
console.log('Rendering started.');
function setStatusTo(msg) {
var status = document.querySelector('#status');
if (msg) {
status.classList.remove('off');
status.innerHTML = msg;
} else
status.classList.add('off');
}
}
chrome.runtime.getBackgroundPage( backgroundPage => {
chrome.runtime.getBackgroundPage( backgroundPage => {
var antiCensorRu = backgroundPage.antiCensorRu;
// DATE
// SET DATE
var dateForUser = 'неизвестно';
function setDate() {
var dateForUser = '...';
if( antiCensorRu.lastPacUpdateStamp ) {
var diff = Date.now() - antiCensorRu.lastPacUpdateStamp;
var units = ' мс'
var units = ' мс';
var gauges = [
[1000, ' с'],
[60, ' мин'],
@ -39,8 +47,12 @@ chrome.runtime.getBackgroundPage( backgroundPage => {
var dateElement = document.querySelector('.update-date');
dateElement.innerText = dateForUser;
dateElement.title = new Date(antiCensorRu.lastPacUpdateStamp).toLocaleString('ru-RU');
}
// CLOSE
setDate();
chrome.storage.onChanged.addListener( setDate );
// CLOSE BUTTON
document.querySelector('.close-button').onclick = () => window.close();
@ -94,7 +106,9 @@ chrome.runtime.getBackgroundPage( backgroundPage => {
setStatusTo('');
checkChosenProvider();
if (antiCensorRu.ifNotInstalled)
if (antiCensorRu.ifFirstInstall)
triggerChosenProvider();
});
});
}

View File

@ -49,7 +49,10 @@ window.antiCensorRu = {
get pacProvider() { return this.pacProviders[this.currentPacProviderKey] },
ifNotInstalled: true,
/*
Offer PAC choice if this is the first time extension was installed.
*/
ifFirstInstall: true,
// PROTECTED
@ -60,7 +63,7 @@ window.antiCensorRu = {
if (Object.getOwnPropertyDescriptor(this, key).writable && typeof(this[key]) !== 'function')
onlySettable[key] = this[key]
return chrome.storage.local.set(onlySettable, () => cb(chrome.runtime.lastError, onlySettable) );
return chrome.storage.local.set(onlySettable, () => cb && cb(chrome.runtime.lastError, onlySettable) );
},
pullFromStorage(cb) {
@ -85,7 +88,7 @@ window.antiCensorRu = {
updatePacProxyIps(
this.pacProvider,
() => {
this.ifNotInstalled = false;
this.ifFirstInstall = false;
this.pushToStorage(cb)
}
)}
@ -167,7 +170,7 @@ chrome.runtime.onInstalled.addListener( details => {
//window.antiCensorRu.installPac();
break;
case 'install':
window.antiCensorRu.ifNotInstalled = true;
window.antiCensorRu.ifFirstInstall = true;
chrome.runtime.openOptionsPage();
}
}