mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
feat: copy to clipboard (#191)
This commit is contained in:
4
src-tauri/src/scripts/cmd.js
vendored
4
src-tauri/src/scripts/cmd.js
vendored
@@ -75,6 +75,10 @@ function init() {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
}
|
||||
.chatappico.copy {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
@media screen and (max-width: 767px) {
|
||||
#download-png-button, #download-pdf-button, #download-html-button {
|
||||
display: none;
|
||||
|
||||
25
src-tauri/src/scripts/core.js
vendored
25
src-tauri/src/scripts/core.js
vendored
@@ -36,8 +36,22 @@ async function invoke(cmd, args) {
|
||||
});
|
||||
}
|
||||
|
||||
async function message(message) {
|
||||
invoke('messageDialog', {
|
||||
__tauriModule: 'Dialog',
|
||||
message: {
|
||||
cmd: 'messageDialog',
|
||||
message: message.toString(),
|
||||
title: null,
|
||||
type: null,
|
||||
buttonLabel: null
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
window.uid = uid;
|
||||
window.invoke = invoke;
|
||||
window.message = message;
|
||||
window.transformCallback = transformCallback;
|
||||
|
||||
async function init() {
|
||||
@@ -87,17 +101,6 @@ async function init() {
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('wheel', function(event) {
|
||||
const deltaX = event.wheelDeltaX;
|
||||
if (Math.abs(deltaX) >= 50) {
|
||||
if (deltaX > 0) {
|
||||
window.history.go(-1);
|
||||
} else {
|
||||
window.history.go(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (window.location.host === 'chat.openai.com') {
|
||||
window.__sync_prompts = async function() {
|
||||
await invoke('sync_prompts', { time: Date.now() });
|
||||
|
||||
35
src-tauri/src/scripts/export.js
vendored
35
src-tauri/src/scripts/export.js
vendored
@@ -275,14 +275,37 @@ function setIcon(type) {
|
||||
}
|
||||
|
||||
function copyBtns() {
|
||||
document.querySelectorAll("main >div>div>div>div>div").forEach(i => {
|
||||
if (!/flex-shrink/i.test(i.getAttribute('class'))) return;
|
||||
const btn = i.querySelector('button').cloneNode(true);
|
||||
btn.innerHTML = setIcon('copy');
|
||||
i.querySelector('.self-end').appendChild(btn);
|
||||
})
|
||||
Array.from(document.querySelectorAll("main >div>div>div>div>div"))
|
||||
.forEach(i => {
|
||||
if (i.querySelector('.chat-item-copy')) return;
|
||||
if (!i.querySelector('button.rounded-md')) return;
|
||||
const btn = i.querySelector('button.rounded-md').cloneNode(true);
|
||||
btn.classList.add('chat-item-copy');
|
||||
btn.title = 'Copy to clipboard';
|
||||
btn.innerHTML = setIcon('copy');
|
||||
i.querySelector('.self-end').appendChild(btn);
|
||||
btn.onclick = () => {
|
||||
copyToClipboard(i?.innerText?.trim() || '');
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function copyToClipboard(text) {
|
||||
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);
|
||||
}
|
||||
message('Copied to clipboard');
|
||||
}
|
||||
|
||||
if (
|
||||
document.readyState === "complete" ||
|
||||
|
||||
Reference in New Issue
Block a user