window._dialogTexts = { 'zh': { 'Close': '关闭', 'Cancel': '取消', 'Confirm': '确定' } } function _getDialogDefaultText(text) { return (window._dialogTexts[navigator.language] && window._dialogTexts[navigator.language][text]) || (window._dialogTexts[navigator.language.split('-')[0]] && window._dialogTexts[navigator.language.split('-')[0]][text]) || text } window.alert = function (msg, buttonText) { return showDialog(msg, [buttonText || _getDialogDefaultText('Close')]) } window.confirm = function (msg, confirmButtonText, cancelButtonText) { return showDialog(msg, [cancelButtonText || _getDialogDefaultText('Cancel'), cancelButtonText || _getDialogDefaultText('Confirm')]) } window.prompt = function (msg, defaultValue, confirmButtonText, cancelButtonText) { return showDialog(msg, [cancelButtonText || _getDialogDefaultText('Cancel'), cancelButtonText || _getDialogDefaultText('Confirm')], [{ value: defaultValue || '' }]) } window.showDialog = function (msg, buttons, inputs) { if (!document.querySelector('#_dialogStyle')) { let sDom = document.createElement('style') sDom.id = '_dialogStyle' sDom.textContent = '._dialogMask {position:fixed;left:0;right:0;top:0;bottom:0;background:rgba(128,128,128,0.7);display:flex;justify-content:center;align-items:center}\n' + '._dialogPanel {background:#eee;padding:16px;min-width:300px;max-width:80%;max-height:80%;margin:auto;border-radius:10px;display:flex;flex-flow:column;overflow:auto}\n' + '._dialogMessage {font-size:0.875rem;flex:1;overflow:auto;white-space:pre-wrap}\n' + '._dialogInputs {display:flex;flex-flow:column;margin-top:8px}\n' + '._dialogInputs input {flex:1;border:1px solid #aaa;border-radius:4px;min-height:28px;padding:0 8px}\n' + '._dialogLine {text-align:end;padding:4px 0}\n' + '._dialogButtons {text-align:end}\n' + '._dialogButtons button {background:none;border:none;color:#999;min-height:28px;cursor:pointer;font-size:1rem;margin-left:10px}\n' + '._dialogButtons button:hover {color:#999}\n' + '._dialogButtons button:last-child {color:#06f}' document.head.append(sDom) } return new Promise(resolve => { let a = ['