| document.addEventListener('DOMContentLoaded', () => { |
| const observer = new MutationObserver((mutations) => { |
| mutations.forEach((mutation) => { |
| if (mutation.addedNodes) { |
| mutation.addedNodes.forEach((node) => { |
| if (node.id === 'tab_models_list') { |
| |
| Array.from(document.querySelectorAll('#tabs > div.tab-nav > button')).find(button => button.textContent.includes('модели')).click(); |
| |
| const freespacetextarea = document.querySelector("#free_space_area > label > textarea"); |
| const frespace_out = document.querySelector("#frespace_out"); |
| let prevValue = freespacetextarea.value; |
| setInterval(function () { |
| const currentValue = freespacetextarea.value; |
| if (currentValue !== prevValue) { |
| frespace_out.innerHTML = `${currentValue}`; |
| prevValue = currentValue; |
| } |
| }, 100); |
| |
| const freespace_getButton = document.querySelector("#freespace_get"); |
| const free_spaceOrigButton = document.querySelector("#free_space_button"); |
| freespace_getButton.addEventListener("click", function () { |
| free_spaceOrigButton.click(); |
| }); |
| |
| const ModelDLHeaderContainer = document.querySelector('.models_dl_header').closest('div').parentNode; |
| ModelDLHeaderContainer.style.cssText = `display: flex; flex-direction: row; align-items: center; justify-content: flex-start; flex-wrap: wrap;`; |
| document.querySelector('.models_dl_header').parentNode.marginRight = "50px"; |
| |
| setTimeout(() => document.querySelector("#files_button").click(), 1000); |
| setTimeout(() => document.querySelector("#free_space_button").click(), 1000); |
| |
| setTimeout(() => { |
| const filesArea = document.querySelector("#files_area > label > textarea"); |
| const filesCheckbox = document.querySelector("#files_checkbox"); |
| const deleteArea = document.querySelector("#delete_area > label > textarea"); |
| |
| function addCheckboxEventListeners() { |
| const delete_checkboxes = document.querySelectorAll("#files_checkbox > label > input[type=checkbox]"); |
| delete_checkboxes.forEach(checkbox => { |
| checkbox.addEventListener("change", event => { |
| |
| const delete_span = event.target.parentElement.querySelector("span"); |
| if (event.target.checked) { |
| delete_span.style.textDecoration = "line-through"; |
| delete_span.style.color = "#ed5252"; |
| } else { |
| delete_span.style.textDecoration = "none"; |
| delete_span.style.color = ""; |
| } |
| }); |
| }); |
| } |
| |
| function updateCheckboxes() { |
| while (filesCheckbox.firstChild) { |
| filesCheckbox.removeChild(filesCheckbox.firstChild); |
| } |
| const fileNames = filesArea.value.split("\n").map(path => path.split("/").pop()); |
| if (fileNames.length === 0 || (fileNames.length === 1 && fileNames[0] === "")) { |
| const message = document.createElement("p"); |
| message.textContent = "ничего не найдено"; |
| filesCheckbox.appendChild(message); |
| } else { |
| fileNames.forEach(fileName => { |
| const checkbox = document.createElement("input"); |
| checkbox.type = "checkbox"; |
| checkbox.id = fileName; |
| checkbox.addEventListener("change", event => { |
| if (event.target.checked) { |
| deleteArea.value += (deleteArea.value ? "\n" : "") + fileName; |
| } else { |
| const lines = deleteArea.value.split("\n"); |
| const index = lines.indexOf(fileName); |
| if (index !== -1) { |
| lines.splice(index, 1); |
| deleteArea.value = lines.join("\n"); |
| } |
| } |
| deleteArea.dispatchEvent(new Event('input')); |
| }); |
| const label = document.createElement("label"); |
| label.htmlFor = fileName; |
| label.className = "filecheckbox"; |
| const span = document.createElement("span"); |
| span.textContent = fileName; |
| label.appendChild(checkbox); |
| label.appendChild(span); |
| filesCheckbox.appendChild(label); |
| }); |
| } |
| deleteArea.value = deleteArea.value.trim(); |
| deleteArea.dispatchEvent(new Event('input')); |
| addCheckboxEventListeners() |
| } |
| |
| const observer = new MutationObserver(updateCheckboxes); |
| observer.observe(filesArea, { characterData: true, subtree: true }); |
| updateCheckboxes(); |
| |
| const RefreshFilesButton = document.querySelector("#refresh_files_button"); |
| RefreshFilesButton.addEventListener("click", () => { |
| document.querySelector("#files_button").click(); |
| |
| setTimeout(function () { updateCheckboxes(); }, 3000); |
| }); |
| |
| document.querySelector("#delete_button").addEventListener("click", function () { |
| setTimeout(function () { |
| document.querySelector("#files_button").click(); |
| |
| setTimeout(function () { updateCheckboxes(); }, 3000); |
| }, 3000); |
| }); |
| |
| const OrigDelButton = document.querySelector("#delete_button"); |
| const CustomDelButton = document.querySelector("#delete_files_button"); |
| CustomDelButton.addEventListener("click", () => { |
| OrigDelButton.click(); |
| }); |
| |
| setInterval(function () { |
| const DLresultText = document.querySelector("#downloads_result_text > span.finish_dl_func"); |
| DLresultText.textContent = document.querySelector("#dlresultbox > label > textarea").value; |
| |
| function checkDLresult(element, text) { |
| if (element.textContent.includes(text)) { |
| document.querySelector("div.downloads_result_container > div.models_porgress_loader").style.removeProperty("display"); |
| document.querySelector("#downloads_start_text").style.removeProperty("display"); |
| document.querySelector("#downloads_result_text > span.dl_progress_info").textContent = "чтобы новые файлы появились в выпадающем списке моделей, нужно обновить их список по соответсвующей кнопке"; |
| } |
| } |
| |
| checkDLresult(DLresultText, "заверш"); |
| checkDLresult(DLresultText, "слишком"); |
| checkDLresult(DLresultText, "ОШИБКА"); |
| |
| if (DLresultText) { |
| if (DLresultText.textContent.includes("слишком")) { |
| DLresultText.style.setProperty("color", "#ff4f8b", "important"); |
| } else if (DLresultText.textContent.includes("ОШИБКА")) { |
| DLresultText.style.setProperty("color", "#de2f2f", "important"); |
| } else if (DLresultText.textContent.includes("заверш")) { |
| DLresultText.style.setProperty("color", "#99fb99", "important"); |
| } |
| } |
| }, 200); |
| |
| document.querySelector("#general_download_button").addEventListener("click", function () { |
| |
| const resultTextareaDL = document.querySelector("#dlresultbox > label > textarea"); |
| resultTextareaDL.value = ""; |
| const resultClearOut = new Event("input", {bubbles: true}); |
| resultTextareaDL.dispatchEvent(resultClearOut); |
| |
| const DLprogressBar = document.querySelector("div.downloads_result_container > div.models_porgress_loader"); |
| DLprogressBar.style.setProperty("display", "block", "important"); |
| const DLresultText = document.querySelector("#downloads_result_text"); |
| DLresultText.style.setProperty("display", "block", "important"); |
| document.querySelector("#downloads_start_text").style.setProperty("display", "block", "important"); |
| |
| |
| document.querySelector("#ownlinks_download_button").click(); |
| setTimeout(function () { |
| |
| document.querySelector("#checkboxes_download_button").click(); |
| }, 3000); |
| }); |
| |
| const GendownloadButton = document.querySelector("#general_download_button"); |
| const DLprogressBar = document.querySelector("div.downloads_result_container > div.models_porgress_loader"); |
| if (GendownloadButton && DLprogressBar) { |
| const DLobserver = new MutationObserver(function (mutations) { |
| mutations.forEach(function (mutation) { |
| if (mutation.type === "attributes" && mutation.attributeName === "style") { |
| if (DLprogressBar.style.display === "block") { |
| GendownloadButton.setAttribute("disabled", "disabled"); |
| } else { |
| setTimeout(function () { |
| GendownloadButton.removeAttribute("disabled"); |
| }, 3000); |
| } |
| } |
| }); |
| }); |
| DLobserver.observe(DLprogressBar, { attributes: true }); |
| } |
| }, 9000); |
| } |
| }); |
| } |
| }); |
| }); |
| observer.observe(document.body, { childList: true, subtree: true }); |
| }); |