Update javascript/colab_sd_models.js
Browse files- javascript/colab_sd_models.js +15 -63
javascript/colab_sd_models.js
CHANGED
@@ -6,21 +6,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
6 |
if (node.id === 'tab_models_list') {
|
7 |
// запуск кода после загрузки элементов
|
8 |
Array.from(document.querySelectorAll('#tabs > div.tab-nav > button')).find(button => button.textContent.includes('модели')).click();
|
9 |
-
// переопределение параметров колонок на основе числа моделей в категории
|
10 |
-
const models_checkbox_grids = document.querySelectorAll("#tab_models_list fieldset > div[data-testid='checkbox-group']");
|
11 |
-
models_checkbox_grids.forEach(models_checkbox_grid => {
|
12 |
-
const model_label = models_checkbox_grid.querySelectorAll('label');
|
13 |
-
const numColumns = model_label.length > 9 ? 'repeat(auto-fit, minmax(250px, 1fr))' : '1fr';
|
14 |
-
models_checkbox_grid.style.gridTemplateColumns = numColumns;
|
15 |
-
});
|
16 |
-
// подвсетка категории мужицких моделей (костаыль, потому что градио своим скриптом долбит каждые Nms переопределение классов)
|
17 |
-
const intervalId = setInterval(() => {
|
18 |
-
const modelsNavButtons = document.querySelectorAll("div#tab_models_list > div.gap > div.tabs > div.tab-nav > button");
|
19 |
-
const MaleCat = Array.from(modelsNavButtons).find(button => button.textContent.includes('мужские'));
|
20 |
-
if (MaleCat) {
|
21 |
-
MaleCat.setAttribute("id", "male_only");
|
22 |
-
}
|
23 |
-
}, 100);
|
24 |
// получение инфы по кд о свободном пространтсве из скрытого уродского текстбокса в красивый элементик в шапочке
|
25 |
const freespacetextarea = document.querySelector("#free_space_area > label > textarea");
|
26 |
const frespace_out = document.querySelector("#frespace_out");
|
@@ -32,49 +17,16 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
32 |
prevValue = currentValue;
|
33 |
}
|
34 |
}, 100);
|
35 |
-
// скликивание
|
36 |
const freespace_getButton = document.querySelector("#freespace_get");
|
37 |
const free_spaceOrigButton = document.querySelector("#free_space_button");
|
38 |
freespace_getButton.addEventListener("click", function () {
|
39 |
free_spaceOrigButton.click();
|
40 |
});
|
41 |
-
// копирование реальных элементов из вкладок с моделями в результатах поиска
|
42 |
-
const SearchBlock = document.querySelector('#clear_search_models_results').closest('label').closest('div').closest('div').closest('div');
|
43 |
-
const ModelDLHeaderBlock = document.querySelector('.models_dl_header').closest('div').parentNode.closest('div').closest('div');
|
44 |
-
const ModelDLHeaderContainer = document.querySelector('.models_dl_header').closest('div').parentNode;
|
45 |
-
ModelDLHeaderBlock.appendChild(SearchBlock);
|
46 |
// небольшой css-фикс
|
|
|
47 |
ModelDLHeaderContainer.style.cssText = `display: flex; flex-direction: row; align-items: center; justify-content: flex-start; flex-wrap: wrap;`;
|
48 |
-
document.querySelector('.models_dl_header').parentNode.
|
49 |
-
// фильтрация моделей при вводе
|
50 |
-
const searchInput = document.querySelector('input[type="text"]');
|
51 |
-
const findedModels = document.querySelector('#finded_models');
|
52 |
-
const tabModelsList = document.querySelector('#tab_models_list');
|
53 |
-
const labels = tabModelsList.querySelectorAll('label');
|
54 |
-
const clearSearchResultsButton = document.querySelector("#clear_search_models_results");
|
55 |
-
searchInput.addEventListener('input', (event) => {
|
56 |
-
const searchTerm = event.target.value.toLowerCase();
|
57 |
-
findedModels.innerHTML = '';
|
58 |
-
if (searchTerm !== '') {
|
59 |
-
labels.forEach((label) => {
|
60 |
-
const labelText = label.textContent.toLowerCase();
|
61 |
-
if (labelText.includes(searchTerm)) {
|
62 |
-
const clone = label.cloneNode(true);
|
63 |
-
findedModels.appendChild(clone);
|
64 |
-
const originalCheckbox = label.querySelector('input[type="checkbox"]');
|
65 |
-
const clonedCheckbox = clone.querySelector('input[type="checkbox"]');
|
66 |
-
clonedCheckbox.addEventListener('change', () => {
|
67 |
-
originalCheckbox.click();
|
68 |
-
});
|
69 |
-
}
|
70 |
-
});
|
71 |
-
}
|
72 |
-
});
|
73 |
-
// обработчик на кнопочку очистки результатов
|
74 |
-
clearSearchResultsButton.addEventListener('click', () => {
|
75 |
-
findedModels.innerHTML = '';
|
76 |
-
searchInput.value = '';
|
77 |
-
});
|
78 |
// автоматическое скликивание скрытых кнопок для подгрузки установленных моделей и свободного места после загрузки дополнения через 1 сек
|
79 |
setTimeout(() => document.querySelector("#files_button").click(), 1000);
|
80 |
setTimeout(() => document.querySelector("#free_space_button").click(), 1000);
|
@@ -100,7 +52,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
100 |
});
|
101 |
});
|
102 |
}
|
103 |
-
|
104 |
function updateCheckboxes() {
|
105 |
while (filesCheckbox.firstChild) {
|
106 |
filesCheckbox.removeChild(filesCheckbox.firstChild);
|
@@ -146,7 +98,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
146 |
const observer = new MutationObserver(updateCheckboxes);
|
147 |
observer.observe(filesArea, { characterData: true, subtree: true });
|
148 |
updateCheckboxes();
|
149 |
-
// скликивание
|
150 |
const RefreshFilesButton = document.querySelector("#refresh_files_button");
|
151 |
RefreshFilesButton.addEventListener("click", () => {
|
152 |
document.querySelector("#files_button").click();
|
@@ -161,7 +113,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
161 |
setTimeout(function () { updateCheckboxes(); }, 3000);
|
162 |
}, 3000);
|
163 |
});
|
164 |
-
// скликивание
|
165 |
const OrigDelButton = document.querySelector("#delete_button");
|
166 |
const CustomDelButton = document.querySelector("#delete_files_button");
|
167 |
CustomDelButton.addEventListener("click", () => {
|
@@ -169,7 +121,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
169 |
});
|
170 |
// проверка выхлопа из функции загрузки в скрытом текстбоксе
|
171 |
setInterval(function () {
|
172 |
-
|
173 |
DLresultText.textContent = document.querySelector("#dlresultbox > label > textarea").value;
|
174 |
// функция скрытия прогрессбара
|
175 |
function checkDLresult(element, text) {
|
@@ -194,12 +146,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
194 |
}
|
195 |
}
|
196 |
}, 200);
|
197 |
-
// действия по клику на
|
198 |
document.querySelector("#general_download_button").addEventListener("click", function () {
|
199 |
// очистка текстбокса от выхлопа предыдущего выполнения
|
200 |
-
|
201 |
resultTextareaDL.value = "";
|
202 |
-
|
203 |
resultTextareaDL.dispatchEvent(resultClearOut);
|
204 |
// делаем прогрессбар и место для результирующего текста видимыми
|
205 |
const DLprogressBar = document.querySelector("div.downloads_result_container > div.models_porgress_loader");
|
@@ -207,7 +159,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
207 |
const DLresultText = document.querySelector("#downloads_result_text");
|
208 |
DLresultText.style.setProperty("display", "block", "important");
|
209 |
document.querySelector("#downloads_start_text").style.setProperty("display", "block", "important");
|
210 |
-
// скликивание
|
211 |
// формирование списка из кастомных ссылок
|
212 |
document.querySelector("#ownlinks_download_button").click();
|
213 |
setTimeout(function () {
|
@@ -216,10 +168,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
216 |
}, 3000); // задержка, чтобы колаб успел одуплиться
|
217 |
});
|
218 |
// если кнопка загрузки уже нажата, запрещаем кликать еще раз пока функция загрузки не выплюнет ответ
|
219 |
-
|
220 |
-
|
221 |
if (GendownloadButton && DLprogressBar) {
|
222 |
-
|
223 |
mutations.forEach(function (mutation) {
|
224 |
if (mutation.type === "attributes" && mutation.attributeName === "style") { // отслеживание видимости прогрессбара
|
225 |
if (DLprogressBar.style.display === "block") {
|
@@ -241,4 +193,4 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
241 |
});
|
242 |
});
|
243 |
observer.observe(document.body, { childList: true, subtree: true });
|
244 |
-
});
|
|
|
6 |
if (node.id === 'tab_models_list') {
|
7 |
// запуск кода после загрузки элементов
|
8 |
Array.from(document.querySelectorAll('#tabs > div.tab-nav > button')).find(button => button.textContent.includes('модели')).click();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
// получение инфы по кд о свободном пространтсве из скрытого уродского текстбокса в красивый элементик в шапочке
|
10 |
const freespacetextarea = document.querySelector("#free_space_area > label > textarea");
|
11 |
const frespace_out = document.querySelector("#frespace_out");
|
|
|
17 |
prevValue = currentValue;
|
18 |
}
|
19 |
}, 100);
|
20 |
+
// скликивание реальной, но скрытой уродской кнопки с обработчиком проверки свободного места при нажатии на фейковую но красивую кнопочку
|
21 |
const freespace_getButton = document.querySelector("#freespace_get");
|
22 |
const free_spaceOrigButton = document.querySelector("#free_space_button");
|
23 |
freespace_getButton.addEventListener("click", function () {
|
24 |
free_spaceOrigButton.click();
|
25 |
});
|
|
|
|
|
|
|
|
|
|
|
26 |
// небольшой css-фикс
|
27 |
+
const ModelDLHeaderContainer = document.querySelector('.models_dl_header').closest('div').parentNode;
|
28 |
ModelDLHeaderContainer.style.cssText = `display: flex; flex-direction: row; align-items: center; justify-content: flex-start; flex-wrap: wrap;`;
|
29 |
+
document.querySelector('.models_dl_header').parentNode.marginRight = "50px";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
// автоматическое скликивание скрытых кнопок для подгрузки установленных моделей и свободного места после загрузки дополнения через 1 сек
|
31 |
setTimeout(() => document.querySelector("#files_button").click(), 1000);
|
32 |
setTimeout(() => document.querySelector("#free_space_button").click(), 1000);
|
|
|
52 |
});
|
53 |
});
|
54 |
}
|
55 |
+
// функция для обновления чекбоксов с файлами почти в реальном времени
|
56 |
function updateCheckboxes() {
|
57 |
while (filesCheckbox.firstChild) {
|
58 |
filesCheckbox.removeChild(filesCheckbox.firstChild);
|
|
|
98 |
const observer = new MutationObserver(updateCheckboxes);
|
99 |
observer.observe(filesArea, { characterData: true, subtree: true });
|
100 |
updateCheckboxes();
|
101 |
+
// скликивание реальной, но скрытой уродской кнопки с обработчиком обновления списка файлов при нажатии на фейковую но красивую кнопочку
|
102 |
const RefreshFilesButton = document.querySelector("#refresh_files_button");
|
103 |
RefreshFilesButton.addEventListener("click", () => {
|
104 |
document.querySelector("#files_button").click();
|
|
|
113 |
setTimeout(function () { updateCheckboxes(); }, 3000);
|
114 |
}, 3000);
|
115 |
});
|
116 |
+
// скликивание реальной, но скрытой уродской кнопки с обработчиком удаления моделей при нажатии на фейковую но красивую кнопочку
|
117 |
const OrigDelButton = document.querySelector("#delete_button");
|
118 |
const CustomDelButton = document.querySelector("#delete_files_button");
|
119 |
CustomDelButton.addEventListener("click", () => {
|
|
|
121 |
});
|
122 |
// проверка выхлопа из функции загрузки в скрытом текстбоксе
|
123 |
setInterval(function () {
|
124 |
+
const DLresultText = document.querySelector("#downloads_result_text > span.finish_dl_func");
|
125 |
DLresultText.textContent = document.querySelector("#dlresultbox > label > textarea").value;
|
126 |
// функция скрытия прогрессбара
|
127 |
function checkDLresult(element, text) {
|
|
|
146 |
}
|
147 |
}
|
148 |
}, 200);
|
149 |
+
// действия по клику на фейковую, но видимую кнопку для скачивания
|
150 |
document.querySelector("#general_download_button").addEventListener("click", function () {
|
151 |
// очистка текстбокса от выхлопа предыдущего выполнения
|
152 |
+
const resultTextareaDL = document.querySelector("#dlresultbox > label > textarea");
|
153 |
resultTextareaDL.value = "";
|
154 |
+
const resultClearOut = new Event("input", {bubbles: true}); // без этого не будет работать обноволение .value
|
155 |
resultTextareaDL.dispatchEvent(resultClearOut);
|
156 |
// делаем прогрессбар и место для результирующего текста видимыми
|
157 |
const DLprogressBar = document.querySelector("div.downloads_result_container > div.models_porgress_loader");
|
|
|
159 |
const DLresultText = document.querySelector("#downloads_result_text");
|
160 |
DLresultText.style.setProperty("display", "block", "important");
|
161 |
document.querySelector("#downloads_start_text").style.setProperty("display", "block", "important");
|
162 |
+
// скликивание реальных, но скрытых кнопок с обработчиками загрузки файлов по чекбоксам и кастомных ссылок при нажатии на фейковую но кнопочку
|
163 |
// формирование списка из кастомных ссылок
|
164 |
document.querySelector("#ownlinks_download_button").click();
|
165 |
setTimeout(function () {
|
|
|
168 |
}, 3000); // задержка, чтобы колаб успел одуплиться
|
169 |
});
|
170 |
// если кнопка загрузки уже нажата, запрещаем кликать еще раз пока функция загрузки не выплюнет ответ
|
171 |
+
const GendownloadButton = document.querySelector("#general_download_button");
|
172 |
+
const DLprogressBar = document.querySelector("div.downloads_result_container > div.models_porgress_loader");
|
173 |
if (GendownloadButton && DLprogressBar) {
|
174 |
+
const DLobserver = new MutationObserver(function (mutations) {
|
175 |
mutations.forEach(function (mutation) {
|
176 |
if (mutation.type === "attributes" && mutation.attributeName === "style") { // отслеживание видимости прогрессбара
|
177 |
if (DLprogressBar.style.display === "block") {
|
|
|
193 |
});
|
194 |
});
|
195 |
observer.observe(document.body, { childList: true, subtree: true });
|
196 |
+
});
|