// Ждем, пока DOM полностью загрузится document.addEventListener('DOMContentLoaded', function() { // --- Часть 1: Добавление опции "Возврат сделан" в селектор --- const selectElement1 = document.getElementById('Deal_change_status'); if (selectElement1) { const newOption1 = document.createElement('option'); newOption1.value = 'return_made'; newOption1.textContent = 'Возврат сделан'; selectElement1.appendChild(newOption1); } // --- Часть 2: Коррекция отображения статуса после сохранения --- const statusDisplayElement = document.querySelector('.deal-status'); if (statusDisplayElement) { const currentStatusText = statusDisplayElement.textContent.trim(); if (currentStatusText === 'return_made') { statusDisplayElement.textContent = 'Возврат сделан'; } } }); // Весь остальной код внутри DOMContentLoaded для гарантии правильной работы (function() { // ─── Ждем, пока DOM полностью загрузится ─── document.addEventListener('DOMContentLoaded', function() { // --- Часть 3: Добавление опции "Возврат сделан" в select через jQuery --- function addReturnMadeOption() { var $select = $("#changestatusoperation-status"); if ($select.length && $select.find("option[value='return_made']").length === 0) { $select.find("option[value='waiting_for_return']").after( '' ); return true; } return false; } if (!addReturnMadeOption()) { var observer = new MutationObserver(function () { if (addReturnMadeOption()) { observer.disconnect(); } }); observer.observe(document.body, { childList: true, subtree: true }); } // Логика показа блока "Причина отказа" $(document).on("change", "#changestatusoperation-status", function () { var $cancelReasonEl = $('#widgetw0 .cancel-reason'); if ($(this).val() == "cancelled" || $(this).val() == "false") { $cancelReasonEl.show(); } else { $cancelReasonEl.hide(); } }); }); })(); // ─── Утилита: заменить return_made → «Возврат сделан» ─── (function() { function replaceInTextNode(node) { if (!node.nodeValue) return; const parent = node.parentElement; if (parent && (parent.tagName === 'SCRIPT' || parent.tagName === 'STYLE')) return; if (/return_made/i.test(node.nodeValue)) { node.nodeValue = node.nodeValue.replace(/return_made/gi, 'Возврат сделан'); } } function replaceAllTextNodes(root) { const walker = document.createTreeWalker( root || document.body, NodeFilter.SHOW_TEXT, null ); let node; while ((node = walker.nextNode())) { replaceInTextNode(node); } } // Создаем стиль для статуса const style = document.createElement('style'); style.textContent = ` .deal-status.status-return_made { background: red !important; color: white !important; border-radius: 1px; display: inline-block; } `; document.head.appendChild(style); // Наблюдатель за DOM const observer = new MutationObserver((mutations) => { for (const mutation of mutations) { for (const node of mutation.addedNodes) { if (node.nodeType === Node.TEXT_NODE) { replaceInTextNode(node); } else if (node.nodeType === Node.ELEMENT_NODE) { replaceAllTextNodes(node); } } } }); observer.observe(document.body, { childList: true, subtree: true, characterData: false, }); // Первичный запуск replaceAllTextNodes(); })(); // ─── Основной скрипт для добавления "Возврат сделан" в select и изменения статуса ─── (function() { document.addEventListener('DOMContentLoaded', function() { // Добавление новой опции const selectElement = document.getElementById('widgetw0'); if (selectElement) { const newOption = document.createElement('option'); newOption.value = 'return_made'; newOption.textContent = 'Возврат сделан'; selectElement.appendChild(newOption); } // Обновление отображения статуса const statusDisplayElement = document.querySelector('.deal-status'); if (statusDisplayElement) { const currentStatusText = statusDisplayElement.textContent.trim(); if (currentStatusText === 'return_made') { statusDisplayElement.textContent = 'Возврат сделан'; } } }); })();