diff --git a/chrome/content/zotero/runJS.html b/chrome/content/zotero/runJS.html index 622fad48b3..f79199f74f 100644 --- a/chrome/content/zotero/runJS.html +++ b/chrome/content/zotero/runJS.html @@ -10,12 +10,20 @@
- +
+ + +
- +
+
diff --git a/chrome/content/zotero/runJS.js b/chrome/content/zotero/runJS.js index 5662db308d..780656c2f0 100644 --- a/chrome/content/zotero/runJS.js +++ b/chrome/content/zotero/runJS.js @@ -1,11 +1,35 @@ -function run() { +function update() { + var isAsync = document.getElementById('run-as-async').checked; + var resultLabel = document.getElementById('result-label'); + var val = isAsync ? 'Return value' : 'Result'; + resultLabel.textContent = val + ':'; +} + +async function run() { var win = Zotero.getMainWindow(); if (!win) { return; } var code = document.getElementById('code').value; - var result = win.eval(code); - document.getElementById('result').value = Zotero.Utilities.varDump(result); + var isAsync = document.getElementById('run-as-async').checked; + var result; + var resultTextbox = document.getElementById('result'); + try { + if (isAsync) { + code = '(async function () {' + code + '})()'; + result = await win.eval(code); + } + else { + result = win.eval(code); + } + } + catch (e) { + resultTextbox.classList.add('error'); + resultTextbox.value = e; + return; + } + resultTextbox.classList.remove('error'); + resultTextbox.value = Zotero.Utilities.varDump(result); } window.addEventListener('keypress', function (event) { @@ -30,3 +54,5 @@ window.addEventListener('keypress', function (event) { var shortcut = Zotero.isMac ? 'Cmd-R' : 'Ctrl+R'; document.getElementById('run-label').textContent = `(${shortcut})`; + +update(); diff --git a/chrome/skin/default/zotero/runJS.css b/chrome/skin/default/zotero/runJS.css index 69029a0147..8fc6b41f4c 100644 --- a/chrome/skin/default/zotero/runJS.css +++ b/chrome/skin/default/zotero/runJS.css @@ -29,18 +29,41 @@ main { flex-direction: column; align-items: stretch; flex-grow: 1; - font-size: 14px; padding: 10px; } +.textbox-header { + display: flex; + align-items: center; + justify-content: space-between; + line-height: 1.5; +} + +.textbox-label { + font-size: 15px; +} + +#run-as-async-label { + font-size: 13px; +} + label { flex-grow: 0; } +input[type=checkbox] { + margin-top: 0; + margin-bottom: 0; +} + textarea { flex-grow: 1; margin: 5px 0; font-family: Monaco, Consolas, Inconsolata, monospace; font-size: 12px; resize: none; +} + +textarea.error { + color: red; } \ No newline at end of file