KiteWind / hotkeys.js
gstaff's picture
Fix hotkey events across tabs.
94421aa
raw
history blame
1.24 kB
() => {
function gradioApp() {
const elems = document.getElementsByTagName('gradio-app');
const elem = elems.length == 0 ? document : elems[0];
if (elem !== document) {
elem.getElementById = function(id) {
return document.getElementById(id);
};
}
return elem.shadowRoot ? elem.shadowRoot : elem;
}
window.addEventListener('keydown', (e) => {
if ((e.ctrlKey || e.metaKey) && e.key == "`") { // CTRL + ` key
const recordButtons = gradioApp().querySelectorAll(".record-btn button");
console.log(recordButtons);
for (let recordButton of recordButtons) {
if (recordButton.checkVisibility()) {
recordButton.click();
}
}
}
});
window.addEventListener('keydown', (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === " ") { // CTRL + Space key
const updateButtons = gradioApp().querySelectorAll(".update-btn");
for (let updateButton of updateButtons) {
if (updateButton.checkVisibility()) {
updateButton.click();
}
}
}
});
}