Add: use messageBox in install page

This commit is contained in:
eight 2017-11-09 12:26:50 +08:00
parent 137198e951
commit 4a8894de2e
3 changed files with 40 additions and 10 deletions

View File

@ -12,6 +12,9 @@
<script src="/js/localization.js"></script> <script src="/js/localization.js"></script>
<script src="/vendor/node-semver/semver.js"></script> <script src="/vendor/node-semver/semver.js"></script>
<script src="/msgbox/msgbox.js"></script>
<link rel="stylesheet" href="/msgbox/msgbox.css"></script>
<!-- FIXME: do we need all of these? --> <!-- FIXME: do we need all of these? -->
<script src="/vendor/codemirror/lib/codemirror.js"></script> <script src="/vendor/codemirror/lib/codemirror.js"></script>
<script src="/vendor/codemirror/keymap/sublime.js"></script> <script src="/vendor/codemirror/keymap/sublime.js"></script>

View File

@ -1,7 +1,28 @@
/* global CodeMirror semverCompare makeLink closeCurrentTab runtimeSend */ /* global CodeMirror semverCompare makeLink closeCurrentTab runtimeSend */
/* global messageBox */
'use strict'; 'use strict';
(() => { (() => {
const dialog = (() => {
function alert(text) {
return messageBox({
contents: text,
className: 'pre center',
buttons: [t('confirmClose')]
});
}
function confirm(text) {
return messageBox({
contents: text,
className: 'pre center',
buttons: [t('confirmYes'), t('confirmNo')]
}).then(result => result.button === 0 || result.enter);
}
return {alert, confirm};
})();
const params = new URLSearchParams(location.search); const params = new URLSearchParams(location.search);
let liveReload = false; let liveReload = false;
let installed = false; let installed = false;
@ -15,14 +36,14 @@
switch (msg.method) { switch (msg.method) {
case 'getSourceCodeResponse': case 'getSourceCodeResponse':
if (msg.error) { if (msg.error) {
alert(msg.error); dialog.alert(msg.error);
} else { } else {
initSourceCode(msg.sourceCode); initSourceCode(msg.sourceCode);
} }
break; break;
case 'sourceCodeChanged': case 'sourceCodeChanged':
if (msg.error) { if (msg.error) {
alert(msg.error); dialog.alert(msg.error);
} else { } else {
liveReloadUpdate(msg.sourceCode); liveReloadUpdate(msg.sourceCode);
} }
@ -185,7 +206,7 @@
window.dispatchEvent(new CustomEvent('installed')); window.dispatchEvent(new CustomEvent('installed'));
}) })
.catch(err => { .catch(err => {
alert(chrome.i18n.getMessage('styleInstallFailed', String(err))); dialog.alert(chrome.i18n.getMessage('styleInstallFailed', String(err)));
}); });
} }
@ -225,15 +246,17 @@
); );
} }
$('button.install').onclick = () => { $('button.install').onclick = () => {
if (dup) { const message = dup ?
if (confirm(chrome.i18n.getMessage('styleInstallOverwrite', [ chrome.i18n.getMessage('styleInstallOverwrite', [
data.name, dupData.version, data.version data.name, dupData.version, data.version
]))) { ]) :
install(style); chrome.i18n.getMessage('styleInstall', [data.name]);
}
} else if (confirm(chrome.i18n.getMessage('styleInstall', [data.name]))) { dialog.confirm(message).then(result => {
install(style); if (result) {
return install(style);
} }
});
}; };
// set updateUrl // set updateUrl

View File

@ -46,6 +46,10 @@
right: unset; right: unset;
} }
#message-box.pre #message-box-contents {
white-space: pre-line;
}
#message-box-title { #message-box-title {
font-weight: bold; font-weight: bold;
background-color: rgb(145, 208, 198); background-color: rgb(145, 208, 198);