</div>';
//"
-var defaultTime = {hours: 0, minutes: 0, seconds: 10};
-var jsonfile = require('jsonfile')
+const TIME_HTML = '\
+<div id="time-container"> \
+<center><div id="time-contents"> \
+<span id="hours-digit">00</span> \
+<span class="colon">:</span> \
+<span id="minutes-digit">00</span> \
+<span class="colon">:</span> \
+<span id="seconds-digit">00</span> \
+</div></center> \
+</div>';
+
+var jsonfile = require('jsonfile');
+var jsonobj = {timerStart: false, time:{hours: 0, minutes: 0, seconds: 0}};
var filepath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('apps_repo'))+'apps_repo/AppManager/data/timer.json';
var app_id = location.href.split('/');
}
else if (msg.background == "timer-update") {
console.log('value, '+msg.value.time.hours+' : '+msg.value.time.minutes+' : '+msg.value.time.seconds);
+ jsonobj.time.hours = msg.value.time.hours;
+ jsonobj.time.minutes = msg.value.time.minutes;
+ jsonobj.time.seconds = msg.value.time.seconds;
+ document.getElementById('hours-digit').innerHTML = jsonobj.time.hours;
+ document.getElementById('minutes-digit').innerHTML = jsonobj.time.minutes;
+ document.getElementById('seconds-digit').innerHTML = jsonobj.time.seconds;
}
else if (msg.background == "timer-finish") {
exitPopup();
return;
}
if (obj.timerStart==true) {
+ console.log('exitPopup: '+window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')));
+ jsonobj = obj;
+ if (obj.time.hours + obj.time.minutes + obj.time.seconds > 0) {
+ initialize();
+ }
+ else {
+ exitPopup();
+ }
+ }
+});
- console.log('exitPopup: '+window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')));
-
+window.onbeforeunload = function() {
+ if (app_id[app_id.length - 2] == 'installer'
+ || app_id[app_id.length - 2] == 'launcher'
+ || app_id[app_id.length - 2] == 'extensions_settings'
+ || app_id[app_id.length - 2] == 'AppManager') {
+ console.log('Except for '+app_id[app_id.length - 2]);
+ return;
+ }
+ stop();
+}
-
- defaultTime = obj.time;
- initialize();
+window.onkeydown = function(event) {
+ if (app_id[app_id.length - 2] == 'installer'
+ || app_id[app_id.length - 2] == 'launcher'
+ || app_id[app_id.length - 2] == 'extensions_settings'
+ || app_id[app_id.length - 2] == 'AppManager') {
+ console.log('Except for '+app_id[app_id.length - 2]);
+ return;
}
-});
+ if (event.keyCode === 10009){ //esc
+ stop();
+ }
+}
function exitPopup() {
document.body.insertAdjacentHTML('beforeend', EXIT_HTML);
+ stop();
document.getElementById('exit-img').onclick= function(event) {
console.log('exitPopup: ');
- reset();
- stop();
var launcher = require('electron').remote.getCurrentWindow();
launcher.close();
};
}
function start() {
- var time = defaultTime;
- console.log('start, '+time.hours+' : '+time.minutes+' : '+time.seconds);
- if (time.hours + time.minutes + time.seconds > 0) {
- port.postMessage({contentscript: "timer-setTime", value:defaultTime});
- port.postMessage({contentscript: "timer-start"});
- }
+ console.log('start, '+jsonobj.time.hours+' : '+jsonobj.time.minutes+' : '+jsonobj.time.seconds);
+ document.body.insertAdjacentHTML('beforebegin', TIME_HTML);
+ port.postMessage({contentscript: "timer-setTime", value:jsonobj.time});
+ port.postMessage({contentscript: "timer-start"});
}
function reset() {
function stop() {
port.postMessage({contentscript: "timer-stop"});
+ jsonfile.writeFile(filepath, jsonobj, function (err) {
+ console.error(err);
+ });
}
function setTime(time) {
console.log('setTime, '+time.defaultTime.hours+' : '+time.defaultTime.minutes+' : '+time.defaultTime.seconds);
- defaultTime.hours = time.defaultTime.hours;
- defaultTime.minutes = time.defaultTime.minutes;
- defaultTime.seconds = time.defaultTime.seconds;
+ jsonobj.time.hours = time.defaultTime.hours;
+ jsonobj.time.minutes = time.defaultTime.minutes;
+ jsonobj.time.seconds = time.defaultTime.seconds;
}