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;
|
width: 22px;
|
||||||
height: 22px;
|
height: 22px;
|
||||||
}
|
}
|
||||||
|
.chatappico.copy {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
}
|
||||||
@media screen and (max-width: 767px) {
|
@media screen and (max-width: 767px) {
|
||||||
#download-png-button, #download-pdf-button, #download-html-button {
|
#download-png-button, #download-pdf-button, #download-html-button {
|
||||||
display: none;
|
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.uid = uid;
|
||||||
window.invoke = invoke;
|
window.invoke = invoke;
|
||||||
|
window.message = message;
|
||||||
window.transformCallback = transformCallback;
|
window.transformCallback = transformCallback;
|
||||||
|
|
||||||
async function init() {
|
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') {
|
if (window.location.host === 'chat.openai.com') {
|
||||||
window.__sync_prompts = async function() {
|
window.__sync_prompts = async function() {
|
||||||
await invoke('sync_prompts', { time: Date.now() });
|
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() {
|
function copyBtns() {
|
||||||
document.querySelectorAll("main >div>div>div>div>div").forEach(i => {
|
Array.from(document.querySelectorAll("main >div>div>div>div>div"))
|
||||||
if (!/flex-shrink/i.test(i.getAttribute('class'))) return;
|
.forEach(i => {
|
||||||
const btn = i.querySelector('button').cloneNode(true);
|
if (i.querySelector('.chat-item-copy')) return;
|
||||||
btn.innerHTML = setIcon('copy');
|
if (!i.querySelector('button.rounded-md')) return;
|
||||||
i.querySelector('.self-end').appendChild(btn);
|
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 (
|
if (
|
||||||
document.readyState === "complete" ||
|
document.readyState === "complete" ||
|
||||||
|
|||||||
Reference in New Issue
Block a user