2017-03-28 10:05:58 +00:00
|
|
|
/* global update */
|
2017-02-14 15:35:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-03-25 06:30:34 +00:00
|
|
|
|
2017-03-26 02:30:59 +00:00
|
|
|
function restore() {
|
2017-03-28 10:05:58 +00:00
|
|
|
setupLivePrefs([
|
|
|
|
'show-badge',
|
|
|
|
'popup.stylesFirst'
|
|
|
|
]);
|
|
|
|
//$('#show-badge').value = bg.prefs.get('show-badge');
|
|
|
|
$('#badgeDisabled').value = prefs.get('badgeDisabled');
|
|
|
|
$('#badgeNormal').value = prefs.get('badgeNormal');
|
2017-03-31 12:22:38 +00:00
|
|
|
$('#popupWidth').value = prefs.get('popupWidth');
|
2017-03-28 10:05:58 +00:00
|
|
|
$('#updateInterval').value = prefs.get('updateInterval');
|
|
|
|
enforceValueRange('popupWidth');
|
2017-02-14 15:35:53 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 06:30:34 +00:00
|
|
|
|
2017-03-26 02:30:59 +00:00
|
|
|
function save() {
|
2017-03-28 10:05:58 +00:00
|
|
|
prefs.set('badgeDisabled', $('#badgeDisabled').value);
|
|
|
|
prefs.set('badgeNormal', $('#badgeNormal').value);
|
2017-03-31 12:22:38 +00:00
|
|
|
prefs.set('popupWidth', enforceValueRange('popupWidth'));
|
2017-03-28 10:05:58 +00:00
|
|
|
prefs.set(
|
|
|
|
'updateInterval',
|
|
|
|
Math.max(0, Number($('#updateInterval').value))
|
|
|
|
);
|
|
|
|
animateElement($('#save-status'), {className: 'fadeinout'});
|
2017-02-14 15:35:53 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 06:30:34 +00:00
|
|
|
|
2017-03-21 01:32:38 +00:00
|
|
|
function enforceValueRange(id) {
|
2017-03-26 02:30:59 +00:00
|
|
|
const element = document.getElementById(id);
|
2017-03-21 01:32:38 +00:00
|
|
|
const min = Number(element.min);
|
|
|
|
const max = Number(element.max);
|
2017-03-26 02:30:59 +00:00
|
|
|
let value = Number(element.value);
|
2017-03-21 01:32:38 +00:00
|
|
|
if (value < min || value > max) {
|
|
|
|
value = Math.max(min, Math.min(max, value));
|
|
|
|
element.value = value;
|
|
|
|
}
|
|
|
|
element.onchange = element.onchange || (() => enforceValueRange(id));
|
2017-03-31 12:22:38 +00:00
|
|
|
return value | 0;
|
2017-03-21 01:32:38 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 06:30:34 +00:00
|
|
|
|
2017-03-28 10:05:58 +00:00
|
|
|
restore();
|
2017-03-25 06:30:34 +00:00
|
|
|
$('#save').onclick = save;
|
|
|
|
|
|
|
|
// overwrite the default URL if browser is Opera
|
2017-03-28 00:42:07 +00:00
|
|
|
$('[data-cmd="open-keyboard"]').href = configureCommands.url;
|
2017-02-14 15:35:53 +00:00
|
|
|
|
|
|
|
// actions
|
2017-03-25 06:30:34 +00:00
|
|
|
document.onclick = e => {
|
2017-03-26 02:30:59 +00:00
|
|
|
const cmd = e.target.dataset.cmd;
|
|
|
|
let total = 0;
|
|
|
|
let updated = 0;
|
2017-02-14 15:35:53 +00:00
|
|
|
|
2017-03-28 10:05:58 +00:00
|
|
|
function showProgress() {
|
|
|
|
$('#update-counter').textContent = `${updated} / ${total}`;
|
2017-02-14 15:35:53 +00:00
|
|
|
}
|
2017-03-26 02:30:59 +00:00
|
|
|
|
|
|
|
function done(target) {
|
2017-02-14 15:35:53 +00:00
|
|
|
target.disabled = false;
|
|
|
|
window.setTimeout(() => {
|
2017-03-25 06:30:34 +00:00
|
|
|
$('#update-counter').textContent = '';
|
2017-02-14 15:35:53 +00:00
|
|
|
}, 750);
|
|
|
|
}
|
|
|
|
|
2017-03-26 02:30:59 +00:00
|
|
|
function check() {
|
2017-03-28 10:05:58 +00:00
|
|
|
chrome.extension.getBackgroundPage().update.perform((cmd, value) => {
|
|
|
|
switch (cmd) {
|
|
|
|
case 'count':
|
|
|
|
total = value;
|
|
|
|
if (!total) {
|
|
|
|
done(e.target);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'single-updated':
|
|
|
|
case 'single-skipped':
|
|
|
|
updated++;
|
|
|
|
if (total && updated === total) {
|
|
|
|
done(e.target);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
showProgress();
|
2017-02-14 15:35:53 +00:00
|
|
|
});
|
|
|
|
// notify the automatic updater to reset the next automatic update accordingly
|
|
|
|
chrome.runtime.sendMessage({
|
|
|
|
method: 'resetInterval'
|
|
|
|
});
|
2017-03-26 02:30:59 +00:00
|
|
|
}
|
2017-03-25 06:30:34 +00:00
|
|
|
|
2017-03-26 02:30:59 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case 'open-manage':
|
|
|
|
openURL({url: '/manage.html'});
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'check-updates':
|
|
|
|
e.target.disabled = true;
|
|
|
|
check();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'open-keyboard':
|
|
|
|
configureCommands.open();
|
|
|
|
break;
|
2017-03-25 06:30:34 +00:00
|
|
|
|
2017-02-15 05:48:47 +00:00
|
|
|
}
|
2017-03-25 06:30:34 +00:00
|
|
|
};
|