// ==UserScript== // @name 珠宝AI 0.2.7 页面清理补丁 // @namespace https://zbai.art/ // @version 0.2.7-clean // @description Clean duplicated mobile labels and add return-preview button. // @match http://zbai.art/* // @match https://zbai.art/* // @match https://jew.haistudio.ai/* // @grant none // @run-at document-idle // ==/UserScript== (function () { "use strict"; const BTN_ID = "zbai-return-preview-v027"; const STYLE_ID = "zbai-clean-style-v027"; injectStyle(); createReturnButton(); const timer = setInterval(() => { cleanComposePanel(); syncReturnButton(); }, 400); setTimeout(() => clearInterval(timer), 30000); const observer = new MutationObserver(() => { cleanComposePanel(); syncReturnButton(); }); if (document.body) { observer.observe(document.body, { childList: true, subtree: true, attributes: true }); } function createReturnButton() { if (document.getElementById(BTN_ID)) return; const btn = document.createElement("button"); btn.id = BTN_ID; btn.type = "button"; btn.textContent = "返回预览"; btn.addEventListener("click", closeMobilePanel); document.body.appendChild(btn); } function syncReturnButton() { const btn = document.getElementById(BTN_ID); if (!btn) return; const opened = document.querySelector(".zbai-m-compose-open") || document.querySelector(".zbai-m-history-open"); btn.style.display = opened ? "block" : "none"; } function closeMobilePanel() { document.querySelectorAll(".zbai-m-compose-open").forEach((node) => { node.classList.remove("zbai-m-compose-open"); }); document.querySelectorAll(".zbai-m-history-open").forEach((node) => { node.classList.remove("zbai-m-history-open"); }); document.querySelectorAll(".zbai-m-ancestor-fix").forEach((node) => { node.classList.remove("zbai-m-ancestor-fix"); }); document.documentElement.classList.remove("zbai-m-lock"); document.body.classList.remove("zbai-m-lock"); document.querySelectorAll("[id^='zbai-mobile-root']").forEach((root) => { root.removeAttribute("data-open"); }); syncReturnButton(); } function cleanComposePanel() { const panel = document.querySelector(".zbai-m-compose-open") || document.querySelector(".zbai-m-compose"); if (!panel) return; const nodes = [...panel.querySelectorAll("div, span, p, label, button")]; nodes.forEach((node) => { const text = getText(node); if (!text) return; // 隐藏英文上传提示,只保留中文 if (/^upload image$/i.test(text)) { hide(node); return; } // 隐藏文生 / 图生残留小字 if (/^(文生|图生|文生图|图生图)$/i.test(text)) { hide(node); return; } // 有些页面会拆成单字残留:文 / 图 if (/^(文|图)$/.test(text) && node.getBoundingClientRect().height < 32) { hide(node); return; } // 修正“请上传首饰图”挤压 if (/请上传首饰图/.test(text) && text.length <= 20) { node.style.setProperty("font-size", "16px", "important"); node.style.setProperty("font-weight", "700", "important"); node.style.setProperty("line-height", "1.45", "important"); node.style.setProperty("margin-bottom", "4px", "important"); node.style.setProperty("white-space", "normal", "important"); } // 修正“试试这些吧”位置 if (/^试试这些吧$/.test(text)) { node.style.setProperty("font-size", "14px", "important"); node.style.setProperty("line-height", "1.4", "important"); node.style.setProperty("margin-top", "8px", "important"); node.style.setProperty("margin-bottom", "6px", "important"); node.style.setProperty("white-space", "normal", "important"); } }); dedupeText(panel, "请上传首饰图"); } function dedupeText(panel, targetText) { const matches = [...panel.querySelectorAll("div, span, p, label")] .filter((node) => getText(node) === targetText && !node.dataset.zbaiHideNoise); if (matches.length <= 1) return; matches.slice(1).forEach(hide); } function hide(node) { node.dataset.zbaiHideNoise = "1"; node.style.setProperty("display", "none", "important"); } function getText(node) { return (node?.innerText || node?.textContent || "") .replace(/\s+/g, " ") .trim(); } function injectStyle() { if (document.getElementById(STYLE_ID)) return; const css = ` #${BTN_ID} { display: none; position: fixed !important; right: max(12px, env(safe-area-inset-right)) !important; bottom: calc(84px + env(safe-area-inset-bottom)) !important; z-index: 2147483647 !important; min-width: 92px !important; height: 42px !important; padding: 0 14px !important; border: 0 !important; border-radius: 9px !important; background: rgba(17, 19, 24, .96) !important; color: #fff !important; font-size: 15px !important; font-weight: 700 !important; line-height: 42px !important; text-align: center !important; box-shadow: 0 8px 24px rgba(20, 24, 35, .25) !important; pointer-events: auto !important; touch-action: manipulation !important; } .zbai-m-compose-open [data-zbai-hide-noise="1"] { display: none !important; } .zbai-m-compose-open div, .zbai-m-compose-open span, .zbai-m-compose-open p, .zbai-m-compose-open label { line-height: 1.35 !important; } `; const style = document.createElement("style"); style.id = STYLE_ID; style.textContent = css; document.documentElement.appendChild(style); } })();