From 13d8d65ef98c1f1f52fa6e60f21025319556a6ae Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 30 Apr 2023 14:40:45 +0300 Subject: [PATCH 1/8] hints: don't process elements that already have a title --- javascript/hints.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/javascript/hints.js b/javascript/hints.js index e7d17d36..8d1967a7 100644 --- a/javascript/hints.js +++ b/javascript/hints.js @@ -118,7 +118,9 @@ titles = { onUiUpdate(function(){ gradioApp().querySelectorAll('span, button, select, p').forEach(function(span){ - tooltip = titles[span.textContent]; + if (span.title) return; // already has a title + + let tooltip = titles[span.textContent]; if(!tooltip){ tooltip = titles[span.value]; From ee973dcf1d1de44a248dc3a1b7043c9b8ebdc25a Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 30 Apr 2023 14:42:11 +0300 Subject: [PATCH 2/8] imageMaskFix.js: fix event listeners to not use anonymous trampoline --- javascript/imageMaskFix.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/javascript/imageMaskFix.js b/javascript/imageMaskFix.js index 9fe7a603..6a82928e 100644 --- a/javascript/imageMaskFix.js +++ b/javascript/imageMaskFix.js @@ -2,7 +2,6 @@ * temporary fix for https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/668 * @see https://github.com/gradio-app/gradio/issues/1721 */ -window.addEventListener( 'resize', () => imageMaskResize()); function imageMaskResize() { const canvases = gradioApp().querySelectorAll('#img2maskimg .touch-none canvas'); if ( ! canvases.length ) { @@ -15,7 +14,7 @@ function imageMaskResize() { const previewImage = wrapper.previousElementSibling; if ( ! previewImage.complete ) { - previewImage.addEventListener( 'load', () => imageMaskResize()); + previewImage.addEventListener( 'load', imageMaskResize); return; } @@ -40,6 +39,7 @@ function imageMaskResize() { c.style.maxHeight = '100%'; c.style.objectFit = 'contain'; }); - } - - onUiUpdate(() => imageMaskResize()); +} + +onUiUpdate(imageMaskResize); +window.addEventListener( 'resize', imageMaskResize); From 34a6ad80d5a3d6670a9e89089558e724d8c9f8bd Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 30 Apr 2023 14:45:56 +0300 Subject: [PATCH 3/8] Use classList.toggle wherever possible --- javascript/hires_fix.js | 12 ++++-------- javascript/imageviewer.js | 6 +----- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/javascript/hires_fix.js b/javascript/hires_fix.js index 0629475f..ba175301 100644 --- a/javascript/hires_fix.js +++ b/javascript/hires_fix.js @@ -1,13 +1,9 @@ -function setInactive(elem, inactive){ - if(inactive){ - elem.classList.add('inactive') - } else{ - elem.classList.remove('inactive') - } -} - function onCalcResolutionHires(enable, width, height, hr_scale, hr_resize_x, hr_resize_y){ + function setInactive(elem, inactive){ + elem.classList.toggle('inactive', !!inactive) + } + hrUpscaleBy = gradioApp().getElementById('txt2img_hr_scale') hrResizeX = gradioApp().getElementById('txt2img_hr_resize_x') hrResizeY = gradioApp().getElementById('txt2img_hr_resize_y') diff --git a/javascript/imageviewer.js b/javascript/imageviewer.js index 3deffa9b..f364a2a1 100644 --- a/javascript/imageviewer.js +++ b/javascript/imageviewer.js @@ -144,11 +144,7 @@ function setupImageForLightbox(e) { } function modalZoomSet(modalImage, enable) { - if (enable) { - modalImage.classList.add('modalImageFullscreen'); - } else { - modalImage.classList.remove('modalImageFullscreen'); - } + if(modalImage) modalImage.classList.toggle('modalImageFullscreen', !!enable); } function modalZoomToggle(event) { From 8ccc27127bd5abcba05f30f8a72fc37025b588ac Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 30 Apr 2023 22:08:52 +0300 Subject: [PATCH 4/8] Fix a whole bunch of implicit globals --- javascript/aspectRatioOverlay.js | 32 ++++++++++++++++---------------- javascript/contextMenus.js | 5 ++--- javascript/edit-attention.js | 8 ++++---- javascript/extensions.js | 2 +- javascript/extraNetworks.js | 14 +++++++------- javascript/generationParams.js | 2 +- javascript/hires_fix.js | 6 +++--- javascript/imageMaskFix.js | 2 +- javascript/imageviewer.js | 6 +++--- javascript/localization.js | 10 +++++----- javascript/notification.js | 2 +- javascript/progressbar.js | 3 +-- javascript/ui.js | 30 +++++++++++++++--------------- 13 files changed, 60 insertions(+), 62 deletions(-) diff --git a/javascript/aspectRatioOverlay.js b/javascript/aspectRatioOverlay.js index a8278cca..10ac81c7 100644 --- a/javascript/aspectRatioOverlay.js +++ b/javascript/aspectRatioOverlay.js @@ -45,27 +45,27 @@ function dimensionChange(e, is_width, is_height){ var viewportOffset = targetElement.getBoundingClientRect(); - viewportscale = Math.min( targetElement.clientWidth/targetElement.naturalWidth, targetElement.clientHeight/targetElement.naturalHeight ) + var viewportscale = Math.min( targetElement.clientWidth/targetElement.naturalWidth, targetElement.clientHeight/targetElement.naturalHeight ) - scaledx = targetElement.naturalWidth*viewportscale - scaledy = targetElement.naturalHeight*viewportscale + var scaledx = targetElement.naturalWidth*viewportscale + var scaledy = targetElement.naturalHeight*viewportscale - cleintRectTop = (viewportOffset.top+window.scrollY) - cleintRectLeft = (viewportOffset.left+window.scrollX) - cleintRectCentreY = cleintRectTop + (targetElement.clientHeight/2) - cleintRectCentreX = cleintRectLeft + (targetElement.clientWidth/2) + var cleintRectTop = (viewportOffset.top+window.scrollY) + var cleintRectLeft = (viewportOffset.left+window.scrollX) + var cleintRectCentreY = cleintRectTop + (targetElement.clientHeight/2) + var cleintRectCentreX = cleintRectLeft + (targetElement.clientWidth/2) - viewRectTop = cleintRectCentreY-(scaledy/2) - viewRectLeft = cleintRectCentreX-(scaledx/2) - arRectWidth = scaledx - arRectHeight = scaledy + var viewRectTop = cleintRectCentreY-(scaledy/2) // TODO: unused? + var viewRectLeft = cleintRectCentreX-(scaledx/2) // TODO: unused? + var arRectWidth = scaledx + var arRectHeight = scaledy - arscale = Math.min( arRectWidth/currentWidth, arRectHeight/currentHeight ) - arscaledx = currentWidth*arscale - arscaledy = currentHeight*arscale + var arscale = Math.min( arRectWidth/currentWidth, arRectHeight/currentHeight ) + var arscaledx = currentWidth*arscale + var arscaledy = currentHeight*arscale - arRectTop = cleintRectCentreY-(arscaledy/2) - arRectLeft = cleintRectCentreX-(arscaledx/2) + var arRectTop = cleintRectCentreY-(arscaledy/2) + var arRectLeft = cleintRectCentreX-(arscaledx/2) arRectWidth = arscaledx arRectHeight = arscaledy diff --git a/javascript/contextMenus.js b/javascript/contextMenus.js index 9468c107..5107e524 100644 --- a/javascript/contextMenus.js +++ b/javascript/contextMenus.js @@ -16,8 +16,7 @@ contextMenuInit = function(){ oldMenu.remove() } - let tabButton = uiCurrentTab - let baseStyle = window.getComputedStyle(tabButton) + let baseStyle = window.getComputedStyle(uiCurrentTab) const contextMenu = document.createElement('nav') contextMenu.id = "context-menu" @@ -63,7 +62,7 @@ contextMenuInit = function(){ function appendContextMenuOption(targetElementSelector,entryName,entryFunction){ - currentItems = menuSpecs.get(targetElementSelector) + var currentItems = menuSpecs.get(targetElementSelector) if(!currentItems){ currentItems = [] diff --git a/javascript/edit-attention.js b/javascript/edit-attention.js index 588c7b77..d2c2f190 100644 --- a/javascript/edit-attention.js +++ b/javascript/edit-attention.js @@ -69,8 +69,8 @@ function keyupEditAttention(event){ event.preventDefault(); - closeCharacter = ')' - delta = opts.keyedit_precision_attention + var closeCharacter = ')' + var delta = opts.keyedit_precision_attention if (selectionStart > 0 && text[selectionStart - 1] == '<'){ closeCharacter = '>' @@ -91,8 +91,8 @@ function keyupEditAttention(event){ selectionEnd += 1; } - end = text.slice(selectionEnd + 1).indexOf(closeCharacter) + 1; - weight = parseFloat(text.slice(selectionEnd + 1, selectionEnd + 1 + end)); + var end = text.slice(selectionEnd + 1).indexOf(closeCharacter) + 1; + var weight = parseFloat(text.slice(selectionEnd + 1, selectionEnd + 1 + end)); if (isNaN(weight)) return; weight += isPlus ? delta : -delta; diff --git a/javascript/extensions.js b/javascript/extensions.js index 3c2f995a..872259af 100644 --- a/javascript/extensions.js +++ b/javascript/extensions.js @@ -41,7 +41,7 @@ function install_extension_from_index(button, url){ button.disabled = "disabled" button.value = "Installing..." - textarea = gradioApp().querySelector('#extension_to_install textarea') + var textarea = gradioApp().querySelector('#extension_to_install textarea') textarea.value = url updateInput(textarea) diff --git a/javascript/extraNetworks.js b/javascript/extraNetworks.js index 25322138..963d5b02 100644 --- a/javascript/extraNetworks.js +++ b/javascript/extraNetworks.js @@ -11,10 +11,10 @@ function setupExtraNetworksForTab(tabname){ tabs.appendChild(refresh) search.addEventListener("input", function(evt){ - searchTerm = search.value.toLowerCase() + var searchTerm = search.value.toLowerCase() gradioApp().querySelectorAll('#'+tabname+'_extra_tabs div.card').forEach(function(elem){ - text = elem.querySelector('.name').textContent.toLowerCase() + " " + elem.querySelector('.search_term').textContent.toLowerCase() + var text = elem.querySelector('.name').textContent.toLowerCase() + " " + elem.querySelector('.search_term').textContent.toLowerCase() elem.style.display = text.indexOf(searchTerm) == -1 ? "none" : "" }) }); @@ -96,9 +96,9 @@ function saveCardPreview(event, tabname, filename){ } function extraNetworksSearchButton(tabs_id, event){ - searchTextarea = gradioApp().querySelector("#" + tabs_id + ' > div > textarea') - button = event.target - text = button.classList.contains("search-all") ? "" : button.textContent.trim() + var searchTextarea = gradioApp().querySelector("#" + tabs_id + ' > div > textarea') + var button = event.target + var text = button.classList.contains("search-all") ? "" : button.textContent.trim() searchTextarea.value = text updateInput(searchTextarea) @@ -133,7 +133,7 @@ function popup(contents){ } function extraNetworksShowMetadata(text){ - elem = document.createElement('pre') + var elem = document.createElement('pre') elem.classList.add('popup-metadata'); elem.textContent = text; @@ -165,7 +165,7 @@ function requestGet(url, data, handler, errorHandler){ } function extraNetworksRequestMetadata(event, extraPage, cardName){ - showError = function(){ extraNetworksShowMetadata("there was an error getting metadata"); } + var showError = function(){ extraNetworksShowMetadata("there was an error getting metadata"); } requestGet("./sd_extra_networks/metadata", {"page": extraPage, "item": cardName}, function(data){ if(data && data.metadata){ diff --git a/javascript/generationParams.js b/javascript/generationParams.js index 1266a266..ef64ee2e 100644 --- a/javascript/generationParams.js +++ b/javascript/generationParams.js @@ -23,7 +23,7 @@ let modalObserver = new MutationObserver(function(mutations) { }); function attachGalleryListeners(tab_name) { - gallery = gradioApp().querySelector('#'+tab_name+'_gallery') + var gallery = gradioApp().querySelector('#'+tab_name+'_gallery') gallery?.addEventListener('click', () => gradioApp().getElementById(tab_name+"_generation_info_button").click()); gallery?.addEventListener('keydown', (e) => { if (e.keyCode == 37 || e.keyCode == 39) // left or right arrow diff --git a/javascript/hires_fix.js b/javascript/hires_fix.js index ba175301..48196be4 100644 --- a/javascript/hires_fix.js +++ b/javascript/hires_fix.js @@ -4,9 +4,9 @@ function onCalcResolutionHires(enable, width, height, hr_scale, hr_resize_x, hr_ elem.classList.toggle('inactive', !!inactive) } - hrUpscaleBy = gradioApp().getElementById('txt2img_hr_scale') - hrResizeX = gradioApp().getElementById('txt2img_hr_resize_x') - hrResizeY = gradioApp().getElementById('txt2img_hr_resize_y') + var hrUpscaleBy = gradioApp().getElementById('txt2img_hr_scale') + var hrResizeX = gradioApp().getElementById('txt2img_hr_resize_x') + var hrResizeY = gradioApp().getElementById('txt2img_hr_resize_y') gradioApp().getElementById('txt2img_hires_fix_row2').style.display = opts.use_old_hires_fix_width_height ? "none" : "" diff --git a/javascript/imageMaskFix.js b/javascript/imageMaskFix.js index 6a82928e..bd0be627 100644 --- a/javascript/imageMaskFix.js +++ b/javascript/imageMaskFix.js @@ -5,7 +5,7 @@ function imageMaskResize() { const canvases = gradioApp().querySelectorAll('#img2maskimg .touch-none canvas'); if ( ! canvases.length ) { - canvases_fixed = false; + canvases_fixed = false; // TODO: this is unused..? window.removeEventListener( 'resize', imageMaskResize ); return; } diff --git a/javascript/imageviewer.js b/javascript/imageviewer.js index f364a2a1..32066ab8 100644 --- a/javascript/imageviewer.js +++ b/javascript/imageviewer.js @@ -57,7 +57,7 @@ function modalImageSwitch(offset) { }) if (result != -1) { - nextButton = galleryButtons[negmod((result + offset), galleryButtons.length)] + var nextButton = galleryButtons[negmod((result + offset), galleryButtons.length)] nextButton.click() const modalImage = gradioApp().getElementById("modalImage"); const modal = gradioApp().getElementById("lightboxModal"); @@ -148,7 +148,7 @@ function modalZoomSet(modalImage, enable) { } function modalZoomToggle(event) { - modalImage = gradioApp().getElementById("modalImage"); + var modalImage = gradioApp().getElementById("modalImage"); modalZoomSet(modalImage, !modalImage.classList.contains('modalImageFullscreen')) event.stopPropagation() } @@ -175,7 +175,7 @@ function galleryImageHandler(e) { } onUiUpdate(function() { - fullImg_preview = gradioApp().querySelectorAll('.gradio-gallery > div > img') + var fullImg_preview = gradioApp().querySelectorAll('.gradio-gallery > div > img') if (fullImg_preview != null) { fullImg_preview.forEach(setupImageForLightbox); } diff --git a/javascript/localization.js b/javascript/localization.js index 1a5a1dbb..e1ffa271 100644 --- a/javascript/localization.js +++ b/javascript/localization.js @@ -35,11 +35,11 @@ function canBeTranslated(node, text){ if(! text) return false; if(! node.parentElement) return false; - parentType = node.parentElement.nodeName + var parentType = node.parentElement.nodeName if(parentType=='SCRIPT' || parentType=='STYLE' || parentType=='TEXTAREA') return false; if (parentType=='OPTION' || parentType=='SPAN'){ - pnode = node + var pnode = node for(var level=0; level<4; level++){ pnode = pnode.parentElement if(! pnode) break; @@ -69,7 +69,7 @@ function getTranslation(text){ } function processTextNode(node){ - text = node.textContent.trim() + var text = node.textContent.trim() if(! canBeTranslated(node, text)) return @@ -105,7 +105,7 @@ function processNode(node){ } function dumpTranslations(){ - dumped = {} + var dumped = {} if (localization.rtl) { dumped.rtl = true } @@ -151,7 +151,7 @@ document.addEventListener("DOMContentLoaded", function() { }) function download_localization() { - text = JSON.stringify(dumpTranslations(), null, 4) + var text = JSON.stringify(dumpTranslations(), null, 4) var element = document.createElement('a'); element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); diff --git a/javascript/notification.js b/javascript/notification.js index 8ddd4c5d..a40de7c3 100644 --- a/javascript/notification.js +++ b/javascript/notification.js @@ -2,7 +2,7 @@ let lastHeadImg = null; -notificationButton = null +let notificationButton = null; onUiUpdate(function(){ if(notificationButton == null){ diff --git a/javascript/progressbar.js b/javascript/progressbar.js index 23bbf298..7b853a40 100644 --- a/javascript/progressbar.js +++ b/javascript/progressbar.js @@ -10,7 +10,6 @@ function getGallerySelectedIndex(id_gallery){ function request(url, data, handler, errorHandler){ var xhr = new XMLHttpRequest(); - var url = url; xhr.open("POST", url, true); xhr.setRequestHeader("Content-Type", "application/json"); xhr.onreadystatechange = function () { @@ -107,7 +106,7 @@ function requestProgress(id_task, progressbarContainer, gallery, atEnd, onProgre divProgress.style.width = rect.width + "px"; } - progressText = "" + let progressText = "" divInner.style.width = ((res.progress || 0) * 100.0) + '%' divInner.style.background = res.progress ? "" : "transparent" diff --git a/javascript/ui.js b/javascript/ui.js index e14b33f5..fed96f98 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -1,7 +1,7 @@ // various functions for interaction with ui.py not large enough to warrant putting them in separate files function set_theme(theme){ - gradioURL = window.location.href + var gradioURL = window.location.href if (!gradioURL.includes('?__theme=')) { window.location.replace(gradioURL + '?__theme=' + theme); } @@ -47,7 +47,7 @@ function extract_image_from_gallery(gallery){ return [gallery[0]]; } - index = selected_gallery_index() + var index = selected_gallery_index() if (index < 0 || index >= gallery.length){ // Use the first image in the gallery as the default @@ -58,7 +58,7 @@ function extract_image_from_gallery(gallery){ } function args_to_array(args){ - res = [] + var res = [] for(var i=0;i Date: Sun, 30 Apr 2023 22:12:24 +0300 Subject: [PATCH 5/8] Fix unused variables --- javascript/aspectRatioOverlay.js | 11 +++-------- javascript/contextMenus.js | 4 ++-- javascript/extensions.js | 4 ++-- javascript/extraNetworks.js | 4 ++-- javascript/imageMaskFix.js | 1 - javascript/imageParams.js | 1 - javascript/notification.js | 2 +- javascript/progressbar.js | 4 ++-- javascript/ui.js | 4 ++-- 9 files changed, 14 insertions(+), 21 deletions(-) diff --git a/javascript/aspectRatioOverlay.js b/javascript/aspectRatioOverlay.js index 10ac81c7..5160081d 100644 --- a/javascript/aspectRatioOverlay.js +++ b/javascript/aspectRatioOverlay.js @@ -55,19 +55,14 @@ function dimensionChange(e, is_width, is_height){ var cleintRectCentreY = cleintRectTop + (targetElement.clientHeight/2) var cleintRectCentreX = cleintRectLeft + (targetElement.clientWidth/2) - var viewRectTop = cleintRectCentreY-(scaledy/2) // TODO: unused? - var viewRectLeft = cleintRectCentreX-(scaledx/2) // TODO: unused? - var arRectWidth = scaledx - var arRectHeight = scaledy - - var arscale = Math.min( arRectWidth/currentWidth, arRectHeight/currentHeight ) + var arscale = Math.min( scaledx/currentWidth, scaledy/currentHeight ) var arscaledx = currentWidth*arscale var arscaledy = currentHeight*arscale var arRectTop = cleintRectCentreY-(arscaledy/2) var arRectLeft = cleintRectCentreX-(arscaledx/2) - arRectWidth = arscaledx - arRectHeight = arscaledy + var arRectWidth = arscaledx + var arRectHeight = arscaledy arPreviewRect.style.top = arRectTop+'px'; arPreviewRect.style.left = arRectLeft+'px'; diff --git a/javascript/contextMenus.js b/javascript/contextMenus.js index 5107e524..ec7960e1 100644 --- a/javascript/contextMenus.js +++ b/javascript/contextMenus.js @@ -35,7 +35,7 @@ contextMenuInit = function(){ menuEntries.forEach(function(entry){ let contextMenuEntry = document.createElement('a') contextMenuEntry.innerHTML = entry['name'] - contextMenuEntry.addEventListener("click", function(e) { + contextMenuEntry.addEventListener("click", function() { entry['func'](); }) contextMenuList.append(contextMenuEntry); @@ -78,7 +78,7 @@ contextMenuInit = function(){ } function removeContextMenuOption(uid){ - menuSpecs.forEach(function(v,k) { + menuSpecs.forEach(function(v) { let index = -1 v.forEach(function(e,ei){if(e['id']==uid){index=ei}}) if(index>=0){ diff --git a/javascript/extensions.js b/javascript/extensions.js index 872259af..cb68344b 100644 --- a/javascript/extensions.js +++ b/javascript/extensions.js @@ -1,5 +1,5 @@ -function extensions_apply(_, _, disable_all){ +function extensions_apply(_disabled_list, _update_list, disable_all){ var disable = [] var update = [] @@ -16,7 +16,7 @@ function extensions_apply(_, _, disable_all){ return [JSON.stringify(disable), JSON.stringify(update), disable_all] } -function extensions_check(_, _){ +function extensions_check(){ var disable = [] gradioApp().querySelectorAll('#extensions input[type="checkbox"]').forEach(function(x){ diff --git a/javascript/extraNetworks.js b/javascript/extraNetworks.js index 963d5b02..c8f6b386 100644 --- a/javascript/extraNetworks.js +++ b/javascript/extraNetworks.js @@ -10,7 +10,7 @@ function setupExtraNetworksForTab(tabname){ tabs.appendChild(search) tabs.appendChild(refresh) - search.addEventListener("input", function(evt){ + search.addEventListener("input", function(){ var searchTerm = search.value.toLowerCase() gradioApp().querySelectorAll('#'+tabname+'_extra_tabs div.card').forEach(function(elem){ @@ -55,7 +55,7 @@ function tryToRemoveExtraNetworkFromPrompt(textarea, text){ var partToSearch = m[1] var replaced = false - var newTextareaText = textarea.value.replaceAll(re_extranet_g, function(found, index){ + var newTextareaText = textarea.value.replaceAll(re_extranet_g, function(found){ m = found.match(re_extranet); if(m[1] == partToSearch){ replaced = true; diff --git a/javascript/imageMaskFix.js b/javascript/imageMaskFix.js index bd0be627..a612705d 100644 --- a/javascript/imageMaskFix.js +++ b/javascript/imageMaskFix.js @@ -23,7 +23,6 @@ function imageMaskResize() { const nw = previewImage.naturalWidth; const nh = previewImage.naturalHeight; const portrait = nh > nw; - const factor = portrait; const wW = Math.min(w, portrait ? h/nh*nw : w/nw*nw); const wH = Math.min(h, portrait ? h/nh*nh : w/nw*nh); diff --git a/javascript/imageParams.js b/javascript/imageParams.js index 67404a89..64aee93b 100644 --- a/javascript/imageParams.js +++ b/javascript/imageParams.js @@ -1,7 +1,6 @@ window.onload = (function(){ window.addEventListener('drop', e => { const target = e.composedPath()[0]; - const idx = selected_gallery_index(); if (target.placeholder.indexOf("Prompt") == -1) return; let prompt_target = get_tab_index('tabs') == 1 ? "img2img_prompt_image" : "txt2img_prompt_image"; diff --git a/javascript/notification.js b/javascript/notification.js index a40de7c3..32913bac 100644 --- a/javascript/notification.js +++ b/javascript/notification.js @@ -9,7 +9,7 @@ onUiUpdate(function(){ notificationButton = gradioApp().getElementById('request_notifications') if(notificationButton != null){ - notificationButton.addEventListener('click', function (evt) { + notificationButton.addEventListener('click', () => { Notification.requestPermission(); },true); } diff --git a/javascript/progressbar.js b/javascript/progressbar.js index 7b853a40..8d2c3492 100644 --- a/javascript/progressbar.js +++ b/javascript/progressbar.js @@ -1,10 +1,10 @@ // code related to showing and updating progressbar shown as the image is being made -function rememberGallerySelection(id_gallery){ +function rememberGallerySelection(){ } -function getGallerySelectedIndex(id_gallery){ +function getGallerySelectedIndex(){ } diff --git a/javascript/ui.js b/javascript/ui.js index fed96f98..aa440bf6 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -207,7 +207,7 @@ function submit_img2img(){ return res } -function restoreProgressTxt2img(x){ +function restoreProgressTxt2img(){ var id = localStorage.getItem("txt2img_task_id") if(id) { @@ -218,7 +218,7 @@ function restoreProgressTxt2img(x){ return [id] } -function restoreProgressImg2img(x){ +function restoreProgressImg2img(){ var id = localStorage.getItem("img2img_task_id") if(id) { From b7269f781c0c673c09beff6ec5fb33ea6b4779a6 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 30 Apr 2023 22:14:51 +0300 Subject: [PATCH 6/8] Mark Notification.requestPermission's retval as purposely ignored --- javascript/notification.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/notification.js b/javascript/notification.js index 32913bac..83fce1f8 100644 --- a/javascript/notification.js +++ b/javascript/notification.js @@ -10,7 +10,7 @@ onUiUpdate(function(){ if(notificationButton != null){ notificationButton.addEventListener('click', () => { - Notification.requestPermission(); + void Notification.requestPermission(); },true); } } From 4bb441bb08aa3692bdd7d347016b4d70e9cdf365 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 30 Apr 2023 22:15:11 +0300 Subject: [PATCH 7/8] Remove redundant return --- javascript/contextMenus.js | 1 - 1 file changed, 1 deletion(-) diff --git a/javascript/contextMenus.js b/javascript/contextMenus.js index ec7960e1..1f682c74 100644 --- a/javascript/contextMenus.js +++ b/javascript/contextMenus.js @@ -111,7 +111,6 @@ contextMenuInit = function(){ if(e.composedPath()[0].matches(k)){ showContextMenu(e,e.composedPath()[0],v) e.preventDefault() - return } }) }); From c714300265919e325ae1340459c4866541940687 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 30 Apr 2023 22:15:59 +0300 Subject: [PATCH 8/8] Use substring instead of deprecated substr --- javascript/contextMenus.js | 2 +- javascript/extensions.js | 6 +++--- javascript/ui.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/javascript/contextMenus.js b/javascript/contextMenus.js index 1f682c74..42f301ab 100644 --- a/javascript/contextMenus.js +++ b/javascript/contextMenus.js @@ -4,7 +4,7 @@ contextMenuInit = function(){ let menuSpecs = new Map(); const uid = function(){ - return Date.now().toString(36) + Math.random().toString(36).substr(2); + return Date.now().toString(36) + Math.random().toString(36).substring(2); } function showContextMenu(event,element,menuEntries){ diff --git a/javascript/extensions.js b/javascript/extensions.js index cb68344b..2a2d2f8e 100644 --- a/javascript/extensions.js +++ b/javascript/extensions.js @@ -5,10 +5,10 @@ function extensions_apply(_disabled_list, _update_list, disable_all){ gradioApp().querySelectorAll('#extensions input[type="checkbox"]').forEach(function(x){ if(x.name.startsWith("enable_") && ! x.checked) - disable.push(x.name.substr(7)) + disable.push(x.name.substring(7)) if(x.name.startsWith("update_") && x.checked) - update.push(x.name.substr(7)) + update.push(x.name.substring(7)) }) restart_reload() @@ -21,7 +21,7 @@ function extensions_check(){ gradioApp().querySelectorAll('#extensions input[type="checkbox"]').forEach(function(x){ if(x.name.startsWith("enable_") && ! x.checked) - disable.push(x.name.substr(7)) + disable.push(x.name.substring(7)) }) gradioApp().querySelectorAll('#extensions .extension_status').forEach(function(x){ diff --git a/javascript/ui.js b/javascript/ui.js index aa440bf6..e2b9bfe4 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -351,7 +351,7 @@ onUiUpdate(function(){ onOptionsChanged(function(){ var elem = gradioApp().getElementById('sd_checkpoint_hash') var sd_checkpoint_hash = opts.sd_checkpoint_hash || "" - var shorthash = sd_checkpoint_hash.substr(0,10) + var shorthash = sd_checkpoint_hash.substring(0,10) if(elem && elem.textContent != shorthash){ elem.textContent = shorthash