1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
| <html>
<head> <meta name="referrer" content="no-referrer"> <script src="https://cdn.tailwindcss.com"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"> <script> let selectedLanguage = "中文(简体)"; // Default language
// 在页面加载时读取localStorage中的内容 window.onload = function () { const inputText = document.getElementById('inputText'); const savedText = localStorage.getItem('inputText'); if (savedText) { inputText.value = savedText; } // 添加input事件监听器,实现边输入边保存 inputText.addEventListener('input', function () { localStorage.setItem('inputText', inputText.value); });
// New code to handle openid const urlParams = new URLSearchParams(window.location.search); const openid = urlParams.get('openid'); if (openid) { localStorage.setItem('openid', openid); } else { const storedOpenid = localStorage.getItem('openid'); if (!storedOpenid) { showIllegalSourceModal(); } } }
async function translateText() { const openid = localStorage.getItem('openid'); if (!openid) { showIllegalSourceModal(); return; }
// 先清楚之前记录 clearOutputText()
// 调用成功提示 showSuccessModal()
const inputText = document.getElementById('inputText').value; // 在翻译前保存输入的内容到localStorage localStorage.setItem('inputText', inputText); // 这里ip和端口改成你自己的服务器的 const response = await fetch('http://ip:端口/translate/deepl', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ text: inputText, target_lang: selectedLanguage, openid: openid }) // 确保发送的是JSON格式 }); const result = await response.json(); document.getElementById('outputText').value = result.data; }
function toggleDropdown() { const dropdown = document.getElementById('languageDropdown'); dropdown.classList.toggle('hidden'); }
function selectLanguage(lang) { const langElement = document.querySelector('.flex.items-center.space-x-2.border-l.pl-4 span'); langElement.textContent = lang; selectedLanguage = lang; // Update the selected language toggleDropdown(); // 隐藏下拉框 }
function clearInputText() { document.getElementById('inputText').value = ''; localStorage.removeItem('inputText'); // 清除localStorage中的内容 }
function clearOutputText() { document.getElementById('outputText').value = ''; }
function showSuccessModal() { const modal = document.createElement('div'); modal.style.position = 'absolute'; modal.style.top = '12%'; modal.style.left = '50%'; modal.style.transform = 'translateX(-50%)'; modal.style.backgroundColor = 'rgba(0,0,0,0.7)'; modal.style.color = 'white'; modal.style.padding = '10px 20px'; modal.style.borderRadius = '5px'; modal.style.zIndex = '1000'; modal.style.display = 'flex'; modal.style.alignItems = 'center'; modal.style.boxShadow = '0 4px 6px rgba(0, 0, 0, 0.1)';
const message = document.createElement('span'); message.textContent = '调用成功';
const closeButton = document.createElement('button'); closeButton.innerHTML = '<i class="fas fa-check"></i>'; // 确认图标 closeButton.style.backgroundColor = 'transparent'; closeButton.style.border = 'none'; closeButton.style.marginLeft = '10px'; closeButton.style.cursor = 'pointer'; closeButton.onclick = () => document.body.removeChild(modal);
modal.appendChild(message); modal.appendChild(closeButton);
const targetElement = document.querySelector('.flex.justify-between.items-center.border-b.pb-2'); targetElement.appendChild(modal);
// 自动关闭弹窗 setTimeout(() => targetElement.removeChild(modal), 3000); }
function showIllegalSourceModal() { const modal = document.createElement('div'); modal.style.position = 'fixed'; modal.style.top = '0'; modal.style.left = '0'; modal.style.width = '100%'; modal.style.height = '100%'; modal.style.backgroundColor = 'rgba(0,0,0,0.5)'; modal.style.display = 'flex'; modal.style.justifyContent = 'center'; modal.style.alignItems = 'center'; modal.style.zIndex = '1000';
const modalContent = document.createElement('div'); modalContent.style.backgroundColor = 'white'; modalContent.style.padding = '20px'; modalContent.style.borderRadius = '5px';
const message = document.createElement('p'); message.textContent = '用户非法来源,请从圈友互联AI应用中心跳转过来(首次登录使用):';
const link = document.createElement('a'); link.href = 'https://ai.quanyouhulian.com/#/appcenter/index'; link.target = '_blank'; link.textContent = '点击跳转'; link.style.color = 'blue'; // 设置链接颜色为蓝色 link.style.textDecoration = 'underline'; // 设置链接带有下划线
const closeButton = document.createElement('button'); closeButton.textContent = '关闭'; closeButton.onclick = () => document.body.removeChild(modal);
modalContent.appendChild(message); modalContent.appendChild(link); modalContent.appendChild(closeButton); modal.appendChild(modalContent); document.body.appendChild(modal); } </script> </head>
<body class="bg-gray-50"> <!-- Navigation Bar --> <nav class="bg-blue-600 text-white p-4"> <div class="flex justify-center items-center"> <div class="text-lg font-bold text-center">全网最精准AI翻译</div> </div> <div class="flex justify-center items-center mt-2"> <div class="text-sm text-center">采用deepl专业版翻译+chatgpt4o润色,翻译结果全球最强</div> </div> </nav> <!-- End Navigation Bar --> <div class="max-w-7xl mx-auto p-4"> <div class="mt-4 bg-white rounded-lg shadow p-4"> <div class="flex justify-between items-center border-b pb-2"> <div class="text-gray-700">系统会自动检测源语言</div> <div class="flex items-center space-x-2"> <button class="bg-blue-500 text-white px-4 py-2 rounded" onclick="translateText()">翻译</button> <div class="flex items-center space-x-2 border-l pl-4 relative"> <span class="text-gray-700">中文(简体)</span> <i class="fas fa-chevron-down cursor-pointer" onclick="toggleDropdown()"></i> <div id="languageDropdown" class="hidden absolute top-full right-0 mt-2 w-48 bg-white border border-gray-300 rounded shadow-lg z-10"> <div class="py-1" role="menu" aria-orientation="vertical" aria-labelledby="options-menu"> <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem" onclick="selectLanguage('中文(简体)')">中文(简体)</a> <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem" onclick="selectLanguage('English')">English</a> </div> </div> </div> </div> </div> <!-- <div class="mt-4 grid grid-cols-2 gap-4"> <textarea id="inputText" class="w-full h-screen border border-gray-300 rounded focus:outline-none p-2" placeholder="输入并开始翻译。"></textarea> <textarea id="outputText" class="w-full h-screen border border-gray-300 rounded focus:outline-none p-2" placeholder="翻译结果" readonly></textarea> </div> --> <div class="mt-4 grid grid-cols-2 gap-4"> <div class="relative"> <textarea id="inputText" class="w-full h-screen border border-gray-300 rounded focus:outline-none p-2" placeholder="输入并点击翻译按钮开始翻译。"></textarea> <button class="absolute top-2 right-2 bg-red-500 text-white px-2 py-1 rounded" style="background-color: rgba(239, 68, 68, 0.3);" title="清除输入框文本" onmouseover="this.style.backgroundColor='rgba(239, 68, 68, 0.8)'" onmouseout="this.style.backgroundColor='rgba(239, 68, 68, 0.3)'" onclick="clearInputText()"> <i class="fas fa-times"></i> <!-- 透明的X图标 --> </button> </div> <div class="relative"> <textarea id="outputText" class="w-full h-screen border border-gray-300 rounded focus:outline-none p-2" placeholder="翻译结果,默认翻译成中文" readonly></textarea> <button class="absolute top-2 right-2 bg-red-500 text-white px-2 py-1 rounded" style="background-color: rgba(239, 68, 68, 0.3);" title="清除输出框文本" onmouseover="this.style.backgroundColor='rgba(239, 68, 68, 0.8)'" onmouseout="this.style.backgroundColor='rgba(239, 68, 68, 0.3)'" onclick="clearOutputText()"> <i class="fas fa-times"></i> <!-- 透明的X图标 --> </button> </div> </div> </div> </div> </body>
</html>
|