diff --git a/README-ZH_CN.md b/README-ZH_CN.md index 786fc46..5fb9060 100644 --- a/README-ZH_CN.md +++ b/README-ZH_CN.md @@ -140,13 +140,13 @@ sudo xattr -r -d com.apple.quarantine /YOUR_PATH/ChatGPT.app - `[.chatgpt]` - 应用配置根路径 - `chat.conf.json` - 应用喜好配置 - - `chat.awesome.json` - 自定义 URL 列表,类似于浏览器书签。可以将任意 URL 作为主窗口或托盘窗口 (**Control Conter -> Awesome**) - - `chat.model.json` - ChatGPT 输入提示,通过斜杠命令来快速完成输入,主要包含三部分: - - `user_custom` - 需要手动录入 (**Control Conter -> Language Model -> User Custom**) - - `sync_prompts` - 从 [f/awesome-chatgpt-prompts](https://github.com/f/awesome-chatgpt-prompts) 同步数据 (**Control Conter -> Language Model -> Sync Prompts**) - - `sync_custom` - 同步自定义的 json 或 csv 文件数据,支持本地和远程 (**Control Conter -> Language Model -> Sync Custom**) - - `chat.model.cmd.json` - 过滤(是否启用)和排序处理后的斜杠命令数据 - - `[cache_model]` - 缓存同步或录入的数据 + + - `chat.prompt.json` - ChatGPT 输入提示,通过斜杠命令来快速完成输入,主要包含三部分: + - `user_custom` - 需要手动录入 (**Control Conter -> Prompts -> User Custom**) + - `sync_prompts` - 从 [f/awesome-chatgpt-prompts](https://github.com/f/awesome-chatgpt-prompts) 同步数据 (**Control Conter -> Prompts -> Sync Prompts**) + - `sync_custom` - 同步自定义的 json 或 csv 文件数据,支持本地和远程 (**Control Conter -> Prompts -> Sync Custom**) + - `chat.prompt.cmd.json` - 过滤(是否启用)和排序处理后的斜杠命令数据 + - `[cache_prompts]` - 缓存同步或录入的数据 - `chatgpt_prompts.json` - 缓存 `sync_prompts` 数据 - `user_custom.json` - 缓存 `user_custom` 数据 - `ae6cf32a6f8541b499d6bfe549dbfca3.json` - 随机生成的文件名,缓存 `sync_custom` 数据 diff --git a/scripts/chat.js b/scripts/chat.js index 68d347d..a5d9377 100644 --- a/scripts/chat.js +++ b/scripts/chat.js @@ -4,125 +4,122 @@ * @url https://github.com/lencx/ChatGPT/tree/main/scripts/chat.js */ -async function init() { - new MutationObserver(function (mutationsList) { - for (const mutation of mutationsList) { - if (mutation.target.closest('form')) { - chatBtns(); - } - } - }).observe(document.body, { - childList: true, - subtree: true, - }); - document.addEventListener('visibilitychange', () => - document.getElementsByTagName('textarea')[0]?.focus(), - ); -} - -async function chatBtns() { - const chatConf = (await invoke('get_app_conf')) || {}; - const synth = window.speechSynthesis; - let currentUtterance = null; - let currentIndex = -1; - const list = Array.from(document.querySelectorAll('main >div>div>div>div>div')); - list.forEach((i, idx) => { - // if (i.querySelector('.chat-item-copy')) return; - if (i.querySelector('.chat-item-voice')) return; - if (!i.querySelector('button.rounded-md')) return; - if (!i.querySelector('.self-end')) return; - // const cpbtn = i.querySelector('button.rounded-md').cloneNode(true); - // cpbtn.classList.add('chat-item-copy'); - // cpbtn.title = 'Copy to clipboard'; - // cpbtn.innerHTML = setIcon('copy'); - // i.querySelector('.self-end').appendChild(cpbtn); - // cpbtn.onclick = () => { - // copyToClipboard(i?.innerText?.trim() || '', cpbtn); - // } - - const saybtn = i.querySelector('button.rounded-md').cloneNode(true); - saybtn.classList.add('chat-item-voice'); - saybtn.title = 'Say'; - saybtn.innerHTML = setIcon('voice'); - i.querySelector('.self-end').appendChild(saybtn); - saybtn.onclick = () => { - if (currentUtterance && currentIndex !== -1) { - synth.cancel(); - if (idx === currentIndex) { - saybtn.innerHTML = setIcon('voice'); - currentUtterance = null; - currentIndex = -1; - return; - } else if (list[currentIndex].querySelector('.chat-item-voice')) { - list[currentIndex].querySelector('.chat-item-voice').innerHTML = setIcon('voice'); - list[idx].querySelector('.chat-item-voice').innerHTML = setIcon('speaking'); - } - } - const txt = i?.innerText?.trim() || ''; - if (!txt) return; - const utterance = new SpeechSynthesisUtterance(txt); - const voices = speechSynthesis.getVoices(); - let voice = voices.find((voice) => voice.voiceURI === chatConf.speech_lang); - if (!voice) { - voice = voices.find((voice) => voice.lang === 'en-US'); - } - utterance.voice = voice; - currentIndex = idx; - utterance.lang = voice.lang; - // utterance.rate = 0.7; - // utterance.pitch = 1.1; - // utterance.volume = 1; - synth.speak(utterance); - amISpeaking = synth.speaking; - saybtn.innerHTML = setIcon('speaking'); - currentUtterance = utterance; - currentIndex = idx; - utterance.onend = () => { - saybtn.innerHTML = setIcon('voice'); - currentUtterance = null; - currentIndex = -1; - }; - }; - }); -} - -// function copyToClipboard(text, btn) { -// window.clearTimeout(window.__cpTimeout); -// btn.innerHTML = setIcon('cpok'); -// if (navigator.clipboard) { -// navigator.clipboard.writeText(text); -// } else { -// var textarea = document.createElement('textarea'); -// document.body.appendChild(textarea); -// textarea.style.position = 'fixed'; -// textarea.style.clip = 'rect(0 0 0 0)'; -// textarea.style.top = '10px'; -// textarea.value = text; -// textarea.select(); -// document.execCommand('copy', true); -// document.body.removeChild(textarea); -// } -// window.__cpTimeout = setTimeout(() => { -// btn.innerHTML = setIcon('copy'); -// }, 1000); -// } - -function focusOnInput() { - // This currently works because there is only a single `