From 8f5856075176ba8a599168feccd71537f7241263 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 22 Jan 2019 04:44:05 -0500 Subject: [PATCH] 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. --- chrome/content/zotero/runJS.html | 2 +- chrome/content/zotero/runJS.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/runJS.html b/chrome/content/zotero/runJS.html index f79199f74f..5b2a9bce52 100644 --- a/chrome/content/zotero/runJS.html +++ b/chrome/content/zotero/runJS.html @@ -17,7 +17,7 @@ Run as async function - +
diff --git a/chrome/content/zotero/runJS.js b/chrome/content/zotero/runJS.js index 780656c2f0..888f7035b1 100644 --- a/chrome/content/zotero/runJS.js +++ b/chrome/content/zotero/runJS.js @@ -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) {