From 6c36fe5719a824fa18f6ad3e02727783f095bc5f Mon Sep 17 00:00:00 2001 From: Melan Date: Mon, 10 Oct 2022 18:16:04 +0200 Subject: Add ctrl+enter as a shortcut to quickly start a generation. --- script.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'script.js') diff --git a/script.js b/script.js index cf989605..a92c0f77 100644 --- a/script.js +++ b/script.js @@ -40,6 +40,22 @@ document.addEventListener("DOMContentLoaded", function() { mutationObserver.observe( gradioApp(), { childList:true, subtree:true }) }); +/** + * Add a ctrl+enter as a shortcut to start a generation + */ + document.addEventListener('keydown', function(e) { + var handled = false; + if (e.key !== undefined) { + if((e.key == "Enter" && (e.metaKey || e.ctrlKey))) handled = true; + } else if (e.keyCode !== undefined) { + if((e.keyCode == 13 && (e.metaKey || e.ctrlKey))) handled = true; + } + if (handled) { + gradioApp().querySelector("#txt2img_generate").click(); + e.preventDefault(); + } +}) + /** * checks that a UI element is not in another hidden element or tab content */ -- cgit v1.2.3 From 8b7d3f1bef47bbe048f644ed0d8dd3ad46554045 Mon Sep 17 00:00:00 2001 From: Jairo Correa Date: Tue, 11 Oct 2022 02:22:46 -0300 Subject: Make the ctrl+enter shortcut use the generate button on the current tab --- script.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'script.js') diff --git a/script.js b/script.js index a92c0f77..9543cbe6 100644 --- a/script.js +++ b/script.js @@ -6,6 +6,10 @@ function get_uiCurrentTab() { return gradioApp().querySelector('.tabs button:not(.border-transparent)') } +function get_uiCurrentTabContent() { + return gradioApp().querySelector('.tabitem[id^=tab_]:not([style*="display: none"])') +} + uiUpdateCallbacks = [] uiTabChangeCallbacks = [] let uiCurrentTab = null @@ -50,8 +54,11 @@ document.addEventListener("DOMContentLoaded", function() { } else if (e.keyCode !== undefined) { if((e.keyCode == 13 && (e.metaKey || e.ctrlKey))) handled = true; } - if (handled) { - gradioApp().querySelector("#txt2img_generate").click(); + if (handled) { + button = get_uiCurrentTabContent().querySelector('button[id$=_generate]'); + if (button) { + button.click(); + } e.preventDefault(); } }) -- cgit v1.2.3 From db27b987a97fc8b7894a9dd34bd7641536f9c424 Mon Sep 17 00:00:00 2001 From: aoirusann Date: Sat, 15 Oct 2022 11:48:13 +0800 Subject: Add hint for `ctrl/alt enter` And duplicate implementations are removed --- script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'script.js') diff --git a/script.js b/script.js index 9543cbe6..88f2c839 100644 --- a/script.js +++ b/script.js @@ -50,9 +50,9 @@ document.addEventListener("DOMContentLoaded", function() { document.addEventListener('keydown', function(e) { var handled = false; if (e.key !== undefined) { - if((e.key == "Enter" && (e.metaKey || e.ctrlKey))) handled = true; + if((e.key == "Enter" && (e.metaKey || e.ctrlKey || e.altKey))) handled = true; } else if (e.keyCode !== undefined) { - if((e.keyCode == 13 && (e.metaKey || e.ctrlKey))) handled = true; + if((e.keyCode == 13 && (e.metaKey || e.ctrlKey || e.altKey))) handled = true; } if (handled) { button = get_uiCurrentTabContent().querySelector('button[id$=_generate]'); -- cgit v1.2.3 From cf47d13c1e11fcb7169bac7488d2c39e579ee491 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Mon, 17 Oct 2022 21:15:32 +0300 Subject: localization support --- script.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'script.js') diff --git a/script.js b/script.js index 88f2c839..8b3b67e3 100644 --- a/script.js +++ b/script.js @@ -21,20 +21,20 @@ function onUiTabChange(callback){ uiTabChangeCallbacks.push(callback) } -function runCallback(x){ +function runCallback(x, m){ try { - x() + x(m) } catch (e) { (console.error || console.log).call(console, e.message, e); } } -function executeCallbacks(queue) { - queue.forEach(runCallback) +function executeCallbacks(queue, m) { + queue.forEach(function(x){runCallback(x, m)}) } document.addEventListener("DOMContentLoaded", function() { var mutationObserver = new MutationObserver(function(m){ - executeCallbacks(uiUpdateCallbacks); + executeCallbacks(uiUpdateCallbacks, m); const newTab = get_uiCurrentTab(); if ( newTab && ( newTab !== uiCurrentTab ) ) { uiCurrentTab = newTab; -- cgit v1.2.3 From 2eb5f103ab1b41477440cc391165ea7ef5f7f959 Mon Sep 17 00:00:00 2001 From: apolinario Date: Mon, 5 Dec 2022 16:30:15 +0100 Subject: Fix WebUI not working inside of iframes --- script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'script.js') diff --git a/script.js b/script.js index 8b3b67e3..d9424de9 100644 --- a/script.js +++ b/script.js @@ -1,5 +1,5 @@ function gradioApp(){ - return document.getElementsByTagName('gradio-app')[0].shadowRoot; + return document } function get_uiCurrentTab() { @@ -82,4 +82,4 @@ function uiElementIsVisible(el) { } } return isVisible; -} \ No newline at end of file +} -- cgit v1.2.3 From 1075819b16ef328805dd946acaffd43efa2eb444 Mon Sep 17 00:00:00 2001 From: apolinario Date: Tue, 6 Dec 2022 15:13:41 +0100 Subject: Use shadowRoot if inside of an iframe and don't use it if outside This makes sure it will work everywhere --- script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'script.js') diff --git a/script.js b/script.js index d9424de9..49b6c557 100644 --- a/script.js +++ b/script.js @@ -1,5 +1,5 @@ function gradioApp(){ - return document + return !!document.getElementsByTagName('gradio-app')[0].shadowRoot ? document.getElementsByTagName('gradio-app')[0].shadowRoot : document } function get_uiCurrentTab() { -- cgit v1.2.3 From 8eb638cdd3d08ad6e9373569fd81d0a6e8a63f16 Mon Sep 17 00:00:00 2001 From: apolinario Date: Tue, 6 Dec 2022 15:14:22 +0100 Subject: style change --- script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'script.js') diff --git a/script.js b/script.js index 49b6c557..1c8fcbf1 100644 --- a/script.js +++ b/script.js @@ -1,5 +1,5 @@ function gradioApp(){ - return !!document.getElementsByTagName('gradio-app')[0].shadowRoot ? document.getElementsByTagName('gradio-app')[0].shadowRoot : document + return !!document.getElementsByTagName('gradio-app')[0].shadowRoot ? document.getElementsByTagName('gradio-app')[0].shadowRoot : document; } function get_uiCurrentTab() { -- cgit v1.2.3 From 37139d8aac10bd13758f52e3d361f3d017c4ad46 Mon Sep 17 00:00:00 2001 From: apolinario Date: Sat, 10 Dec 2022 12:51:40 +0100 Subject: No code repeat --- script.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'script.js') diff --git a/script.js b/script.js index 1c8fcbf1..9748ec90 100644 --- a/script.js +++ b/script.js @@ -1,5 +1,6 @@ -function gradioApp(){ - return !!document.getElementsByTagName('gradio-app')[0].shadowRoot ? document.getElementsByTagName('gradio-app')[0].shadowRoot : document; +function gradioApp() { + const gradioShadowRoot = document.getElementsByTagName('gradio-app')[0].shadowRoot + return !!gradioShadowRoot ? gradioShadowRoot : document; } function get_uiCurrentTab() { -- cgit v1.2.3 From 4fc81542077af73610279ad7b6b26e38718a0f81 Mon Sep 17 00:00:00 2001 From: Gerschel Date: Tue, 3 Jan 2023 23:25:34 -0800 Subject: better targetting, class tabs was autoassigned I moved a preset manager into quicksettings, this function was targeting my component instead of the tabs. This is because class tabs is autoassigned, while element id #tabs is not, this allows a tabbed component to live in the quicksettings. --- script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'script.js') diff --git a/script.js b/script.js index 9748ec90..0e117d06 100644 --- a/script.js +++ b/script.js @@ -4,7 +4,7 @@ function gradioApp() { } function get_uiCurrentTab() { - return gradioApp().querySelector('.tabs button:not(.border-transparent)') + return gradioApp().querySelector('#tabs button:not(.border-transparent)') } function get_uiCurrentTabContent() { -- cgit v1.2.3