runJS: better message if nothing is returned (#5181)
Display "===>undefined<=== (completed successfully)" instead of current "===>undefined<=== (undefined)", which is a bit misleading. Fixes: #5180
This commit is contained in:
parent
79feeaecb1
commit
76b8556c16
4 changed files with 32 additions and 3 deletions
|
@ -28,8 +28,9 @@
|
|||
</div>
|
||||
|
||||
<div class="textbox-container">
|
||||
<div class="textbox-header">
|
||||
<label id="result-label" class="textbox-label" for="result" data-l10n-id="runJS-result"/>
|
||||
<div class="textbox-header result-header">
|
||||
<label id="result-label" class="textbox-label" for="result" data-l10n-id="runJS-result"></label>
|
||||
<div id="loading-spinner" class="zotero-spinner-16"></div>
|
||||
</div>
|
||||
<textarea id="result" readonly aria-disabled="true"></textarea>
|
||||
</div>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -44,6 +44,14 @@
|
|||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.result-header {
|
||||
justify-content: start;
|
||||
}
|
||||
|
||||
#loading-spinner {
|
||||
margin-inline-start: 5px;
|
||||
}
|
||||
|
||||
.textbox-label {
|
||||
font-size: 15px;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue