mirror of
https://github.com/zotero/zotero.git
synced 2026-10-04 02:31:47 +00:00
Run JavaScript: Automatically switch to async mode if await is used
This will allow examples from the documentation to work without the async option being explicitly chosen.
This commit is contained in:
parent
39eb2962a6
commit
8f58560751
2 changed files with 15 additions and 1 deletions
|
|
@ -17,7 +17,7 @@
|
|||
Run as async function
|
||||
</label>
|
||||
</div>
|
||||
<textarea id="code"></textarea>
|
||||
<textarea id="code" oninput="handleInput()"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="textbox-container">
|
||||
|
|
|
|||
|
|
@ -32,6 +32,20 @@ async function run() {
|
|||
resultTextbox.value = Zotero.Utilities.varDump(result);
|
||||
}
|
||||
|
||||
function handleInput() {
|
||||
var checkbox = document.getElementById('run-as-async');
|
||||
var isAsync = checkbox.checked;
|
||||
if (isAsync) {
|
||||
return;
|
||||
}
|
||||
var code = document.getElementById('code').value;
|
||||
// If `await` is used, switch to async mode
|
||||
if (/^\s*await\s/m.test(code)) {
|
||||
checkbox.checked = true;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('keypress', function (event) {
|
||||
if (Zotero.isMac) {
|
||||
if (!event.metaKey) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue