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,3 +1,10 @@
'use strict';
renderPage();
function renderPage() {
console.log('Rendering started.');
function setStatusTo(msg) { function setStatusTo(msg) {
var status = document.querySelector('#status'); var status = document.querySelector('#status');
if (msg) { if (msg) {
@ -11,12 +18,13 @@ chrome.runtime.getBackgroundPage( backgroundPage => {
var antiCensorRu = backgroundPage.antiCensorRu; var antiCensorRu = backgroundPage.antiCensorRu;
// DATE // SET DATE
var dateForUser = 'неизвестно'; function setDate() {
var dateForUser = '...';
if( antiCensorRu.lastPacUpdateStamp ) { if( antiCensorRu.lastPacUpdateStamp ) {
var diff = Date.now() - antiCensorRu.lastPacUpdateStamp; var diff = Date.now() - antiCensorRu.lastPacUpdateStamp;
var units = ' мс' var units = ' мс';
var gauges = [ var gauges = [
[1000, ' с'], [1000, ' с'],
[60, ' мин'], [60, ' мин'],
@ -39,8 +47,12 @@ chrome.runtime.getBackgroundPage( backgroundPage => {
var dateElement = document.querySelector('.update-date'); var 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');
}
// CLOSE setDate();
chrome.storage.onChanged.addListener( setDate );
// CLOSE BUTTON
document.querySelector('.close-button').onclick = () => window.close(); document.querySelector('.close-button').onclick = () => window.close();
@ -94,7 +106,9 @@ chrome.runtime.getBackgroundPage( backgroundPage => {
setStatusTo(''); setStatusTo('');
checkChosenProvider(); checkChosenProvider();
if (antiCensorRu.ifNotInstalled) if (antiCensorRu.ifFirstInstall)
triggerChosenProvider(); triggerChosenProvider();
}); });
}

View File

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