diff --git a/install-usercss/install-usercss.js b/install-usercss/install-usercss.js index 0dbccf22..b89547cd 100644 --- a/install-usercss/install-usercss.js +++ b/install-usercss/install-usercss.js @@ -3,26 +3,6 @@ '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); let liveReload = false; let installed = false; @@ -36,14 +16,14 @@ switch (msg.method) { case 'getSourceCodeResponse': if (msg.error) { - dialog.alert(msg.error); + messageBox.alert(msg.error); } else { initSourceCode(msg.sourceCode); } break; case 'sourceCodeChanged': if (msg.error) { - dialog.alert(msg.error); + messageBox.alert(msg.error); } else { liveReloadUpdate(msg.sourceCode); } @@ -207,7 +187,7 @@ window.dispatchEvent(new CustomEvent('installed')); }) .catch(err => { - dialog.alert(chrome.i18n.getMessage('styleInstallFailed', String(err))); + messageBox.alert(chrome.i18n.getMessage('styleInstallFailed', String(err))); }); } @@ -253,7 +233,7 @@ ]) : chrome.i18n.getMessage('styleInstall', [data.name]); - dialog.confirm(message).then(result => { + messageBox.confirm(message).then(result => { if (result) { return install(style); } diff --git a/msgbox/msgbox.js b/msgbox/msgbox.js index 6efadb5d..0562757f 100644 --- a/msgbox/msgbox.js +++ b/msgbox/msgbox.js @@ -99,3 +99,17 @@ function messageBox({ messageBox.resolve = null; } } + +messageBox.alert = text => + messageBox({ + contents: text, + className: 'pre center', + buttons: [t('confirmClose')] + }); + +messageBox.confirm = text => + messageBox({ + contents: text, + className: 'pre center', + buttons: [t('confirmYes'), t('confirmNo')] + }).then(result => result.button === 0 || result.enter);