stylus/options/index.js

81 lines
1.7 KiB
JavaScript
Raw Normal View History

/* global update */
2017-02-14 15:35:53 +00:00
'use strict';
2017-04-04 17:21:03 +00:00
setupLivePrefs([
'show-badge',
'popup.stylesFirst',
'badgeNormal',
'badgeDisabled',
'popupWidth',
'updateInterval',
]);
enforceInputRange($('#popupWidth'));
// overwrite the default URL if browser is Opera
$('[data-cmd="open-keyboard"]').href = configureCommands.url;
2017-02-14 15:35:53 +00:00
// actions
document.onclick = e => {
const cmd = e.target.dataset.cmd;
let total = 0;
let updated = 0;
2017-02-14 15:35:53 +00:00
function showProgress() {
$('#update-counter').textContent = `${updated} / ${total}`;
2017-02-14 15:35:53 +00:00
}
function done(target) {
2017-02-14 15:35:53 +00:00
target.disabled = false;
window.setTimeout(() => {
$('#update-counter').textContent = '';
2017-02-14 15:35:53 +00:00
}, 750);
}
function check() {
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'
});
}
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-04-04 17:21:03 +00:00
case 'reset':
$$('input')
.filter(input => input.id in prefs.readOnlyValues)
.forEach(input => prefs.reset(input.id));
break;
}
};