diff --git a/chrome/content/zotero/runJS.html b/chrome/content/zotero/runJS.html index 509e279c08..86d55bfc38 100644 --- a/chrome/content/zotero/runJS.html +++ b/chrome/content/zotero/runJS.html @@ -28,8 +28,9 @@
-
-
diff --git a/chrome/content/zotero/runJS.js b/chrome/content/zotero/runJS.js index dfe8a8ccb9..c14b391092 100644 --- a/chrome/content/zotero/runJS.js +++ b/chrome/content/zotero/runJS.js @@ -14,6 +14,8 @@ async function run() { var isAsync = document.getElementById('run-as-async').checked; var result; var resultTextbox = document.getElementById('result'); + var spinner = document.getElementById("loading-spinner"); + spinner.setAttribute("status", "animate"); try { if (isAsync) { code = '(async function () {' + code + '})()'; @@ -26,10 +28,27 @@ async function run() { catch (e) { resultTextbox.classList.add('error'); resultTextbox.textContent = e; + spinner.removeAttribute("status"); return; } + // Hide the spinner after a small delay so it briefly appears even + // if the code runs fast to indicate that everything did run + setTimeout(() => { + spinner.removeAttribute("status"); + }, 100); + resultTextbox.classList.remove('error'); - resultTextbox.textContent = typeof result == 'string' ? result : Zotero.Utilities.varDump(result); + if (typeof result == 'string') { + resultTextbox.textContent = result; + } + else if (result !== undefined) { + resultTextbox.textContent = Zotero.Utilities.varDump(result); + } + else { + // when nothing is returned, log undefined as the return value but + // for clarity also add a note that the JS run was successful + resultTextbox.textContent = `===>undefined<=== (${Zotero.getString("runJS-completed")})`; + } } // eslint-disable-next-line no-unused-vars diff --git a/chrome/locale/en-US/zotero/zotero.ftl b/chrome/locale/en-US/zotero/zotero.ftl index e17ea34e46..b2430f460e 100644 --- a/chrome/locale/en-US/zotero/zotero.ftl +++ b/chrome/locale/en-US/zotero/zotero.ftl @@ -294,6 +294,7 @@ runJS-title = Run JavaScript runJS-editor-label = Code: runJS-run = Run runJS-help = { general-help } +runJS-completed = completed successfully runJS-result = { $type -> [async] Return value: diff --git a/scss/components/_runJS.scss b/scss/components/_runJS.scss index 426f1acf0e..137a97c7da 100644 --- a/scss/components/_runJS.scss +++ b/scss/components/_runJS.scss @@ -44,6 +44,14 @@ line-height: 1.5; } + .result-header { + justify-content: start; + } + + #loading-spinner { + margin-inline-start: 5px; + } + .textbox-label { font-size: 15px; }