// ==UserScript== // @name Sexy.AI to SillyTavern origin // @namespace http://tampermonkey.net/ // @version 1.0 // @description Sync between Sexy.AI and SillyTavern // @author You // @match https://sexy.ai/workflow* // @match https://staticui.sexy.ai/* // @match http://ducninh.top:8000/* // @grant GM_setValue // @grant GM_getValue // @grant unsafeWindow // @downloadURL none // ==/UserScript== (function() { 'use strict'; const isSexyAI = window.location.href.includes('sexy.ai') || window.location.href.includes('staticui.sexy.ai'); const isSillyTavern = window.location.href.includes('ducninh.top:8000'); function createStyledButton(text, onClick, isFixed = false) { const button = document.createElement('button'); button.textContent = text; let style = ` display: inline-block; padding: 8px 12px; background-color: #4CAF50; color: white; border: none; border-radius: 3px; cursor: pointer; font-size: 16px; margin: 5px; opacity: 0.8; transition: opacity 0.3s; -webkit-tap-highlight-color: transparent; touch-action: manipulation; `; if(isFixed) { style += ` position: fixed; right: 20px; z-index: 9999; `; } button.style.cssText = style; button.addEventListener('click', onClick); button.addEventListener('touchstart', () => button.style.opacity = '1'); button.addEventListener('touchend', () => button.style.opacity = '0.8'); return button; } if (isSexyAI) { if (window.location.href.includes('staticui.sexy.ai')) { const promptButton = createStyledButton('Get Prompt', () => { const prompt = GM_getValue('st_prompt', null); if (prompt) { const positiveInput = document.querySelector('textarea') || document.querySelector('input[type="text"]'); if (positiveInput) { positiveInput.value = prompt; const event = new Event('input', { bubbles: true }); positiveInput.dispatchEvent(event); GM_setValue('st_prompt', null); alert('Prompt added!'); } else { alert('Input field not found.'); } } else { alert('No prompt found. Copy from SillyTavern first.'); } }, true); promptButton.style.top = '80px'; document.body.appendChild(promptButton); } document.addEventListener('click', (e) => { if (e.target.tagName === 'IMG') { const markdownUrls = [`![alt-text](${e.target.src})`]; GM_setValue('sexyai_images', markdownUrls.join('\n')); alert('Image copied! Switch to SillyTavern tab.'); } }, true); } else if (isSillyTavern) { const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { mutation.addedNodes.forEach((node) => { if (node.classList?.contains('mes')) { const messageText = node.querySelector('.mes_text'); if (messageText && !messageText.querySelector('.button-container')) { const buttonContainer = document.createElement('div'); buttonContainer.className = 'button-container'; buttonContainer.style.cssText = 'display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; width: 100%;'; const syncButton = createStyledButton('📥 Sync Image', () => { const markdownUrls = GM_getValue('sexyai_images', null); if (!markdownUrls) { alert('No images found. Click an image in Sexy.AI first.'); return; } const editButton = node.querySelector('.mes_edit'); if (editButton) { editButton.click(); setTimeout(() => { const textarea = document.getElementById('curEditTextarea'); if (textarea) { textarea.value = textarea.value + '\n' + markdownUrls; setTimeout(() => { const confirmButton = node.querySelector('.mes_edit_done'); if (confirmButton) { confirmButton.click(); GM_setValue('sexyai_images', null); alert('Images added successfully!'); } }, 100); } }, 100); } }); const sendPromptButton = createStyledButton('📤 Send Prompt', () => { const text = messageText.textContent; const match = text.match(/image###([^#]+)###/); if (match) { const prompt = match[1].trim(); GM_setValue('st_prompt', prompt); alert('Prompt copied! Click "Get Prompt" in Sexy.AI tab'); } else { alert('No valid prompt found. Message should contain image###prompt###'); } }); buttonContainer.appendChild(syncButton); buttonContainer.appendChild(sendPromptButton); messageText.appendChild(buttonContainer); } } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); } })();