From c08746a2c064b962f037d95b39d2a8e6c4a52978 Mon Sep 17 00:00:00 2001 From: Dominik Reh Date: Sat, 25 Mar 2023 13:40:04 +0100 Subject: [PATCH] Fix model name based blacklist Now also based on the hash mutation observer --- javascript/tagAutocomplete.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js index dc4e142..30ad52b 100644 --- a/javascript/tagAutocomplete.js +++ b/javascript/tagAutocomplete.js @@ -256,13 +256,14 @@ function isEnabled() { .filter(x => x.length > 0); let shortHash = currentModelHash.substring(0, 10); + let modelNameWithoutHash = currentModelName.replace(/\[.*\]$/g, "").trim(); if (CFG.activeIn.modelListMode.toLowerCase() === "blacklist") { // If the current model is in the blacklist, disable - return modelList.filter(x => x === currentModelName || x === currentModelHash || x === shortHash).length === 0; + return modelList.filter(x => x === currentModelName || x === modelNameWithoutHash || x === currentModelHash || x === shortHash).length === 0; } else { // If the current model is in the whitelist, enable. // An empty whitelist is ignored. - return modelList.length === 0 || modelList.filter(x => x === currentModelName || x === currentModelHash || x === shortHash).length > 0; + return modelList.length === 0 || modelList.filter(x => x === currentModelName || x === modelNameWithoutHash || x === currentModelHash || x === shortHash).length > 0; } } else { return false; @@ -806,14 +807,6 @@ async function setup() { }); }); - // Add change listener to model dropdown to react to model changes - let modelDropdown = gradioApp().querySelector("#setting_sd_model_checkpoint span.single-select"); - currentModelName = modelDropdown.textContent; - modelDropdown?.addEventListener("change", () => { - setTimeout(() => { - currentModelName = modelDropdown.textContent; - }, 100); - }); // Add mutation observer for the model hash text to also allow hash-based blacklist again let modelHashText = gradioApp().querySelector("#sd_checkpoint_hash"); if (modelHashText) { @@ -822,6 +815,8 @@ async function setup() { for (const mutation of mutationList) { if (mutation.type === "attributes" && mutation.attributeName === "title") { currentModelHash = mutation.target.title; + let modelDropdown = gradioApp().querySelector("#setting_sd_model_checkpoint span.single-select"); + currentModelName = modelDropdown?.textContent; } } });