mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
chore: scripts
This commit is contained in:
280
src-tauri/src/assets/cmd.js
vendored
280
src-tauri/src/assets/cmd.js
vendored
@@ -1,280 +0,0 @@
|
|||||||
// *** Core Script - CMD ***
|
|
||||||
|
|
||||||
function init() {
|
|
||||||
const styleDom = document.createElement('style');
|
|
||||||
styleDom.innerHTML = `form {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
.chat-model-cmd-list {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 60px;
|
|
||||||
max-height: 100px;
|
|
||||||
overflow: auto;
|
|
||||||
z-index: 9999;
|
|
||||||
}
|
|
||||||
.chat-model-cmd-list>div {
|
|
||||||
border: solid 2px rgba(80,80,80,.3);
|
|
||||||
border-radius: 5px;
|
|
||||||
background-color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
html.dark .chat-model-cmd-list>div {
|
|
||||||
background-color: #4a4a4a;
|
|
||||||
}
|
|
||||||
html.dark .chat-model-cmd-list .cmd-item {
|
|
||||||
border-color: #666;
|
|
||||||
}
|
|
||||||
html.dark .chat-model-cmd-list .cmd-item b {
|
|
||||||
color: #e8e8e8;
|
|
||||||
}
|
|
||||||
html.dark .chat-model-cmd-list .cmd-item i {
|
|
||||||
color: #999;
|
|
||||||
}
|
|
||||||
html.dark .chat-model-cmd-list .cmd-item.selected {
|
|
||||||
background: rgba(59,130,246,.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
.chat-model-cmd-list .cmd-item {
|
|
||||||
font-size: 12px;
|
|
||||||
border-bottom: solid 1px rgba(80,80,80,.2);
|
|
||||||
padding: 2px 4px;
|
|
||||||
display: flex;
|
|
||||||
user-select: none;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
.chat-model-cmd-list .cmd-item:last-child {
|
|
||||||
border-bottom: none;
|
|
||||||
}
|
|
||||||
.chat-model-cmd-list .cmd-item.selected {
|
|
||||||
background: rgba(59,130,246,.3);
|
|
||||||
}
|
|
||||||
.chat-model-cmd-list .cmd-item b {
|
|
||||||
display: inline-block;
|
|
||||||
width: 100px;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
border-radius: 4px;
|
|
||||||
margin-right: 10px;
|
|
||||||
color: #2a2a2a;
|
|
||||||
}
|
|
||||||
.chat-model-cmd-list .cmd-item i {
|
|
||||||
width: 100%;
|
|
||||||
max-width: 200px;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
text-align: right;
|
|
||||||
color: #888;
|
|
||||||
}
|
|
||||||
.chatappico {
|
|
||||||
width: 20px;
|
|
||||||
height: 20px;
|
|
||||||
}
|
|
||||||
.chatappico.pdf {
|
|
||||||
width: 24px;
|
|
||||||
height: 24px;
|
|
||||||
}
|
|
||||||
@media screen and (max-width: 767px) {
|
|
||||||
#download-png-button, #download-pdf-button, #download-html-button {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
document.head.append(styleDom);
|
|
||||||
|
|
||||||
if (window.formInterval) {
|
|
||||||
clearInterval(window.formInterval);
|
|
||||||
}
|
|
||||||
window.formInterval = setInterval(() => {
|
|
||||||
const form = document.querySelector("form");
|
|
||||||
if (!form) return;
|
|
||||||
clearInterval(window.formInterval);
|
|
||||||
cmdTip();
|
|
||||||
}, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function cmdTip() {
|
|
||||||
const chatModelJson = await invoke('get_chat_model_cmd') || {};
|
|
||||||
const data = chatModelJson.data;
|
|
||||||
if (data.length <= 0) return;
|
|
||||||
|
|
||||||
const modelDom = document.createElement('div');
|
|
||||||
modelDom.classList.add('chat-model-cmd-list');
|
|
||||||
|
|
||||||
// fix: tray window
|
|
||||||
if (__TAURI_METADATA__.__currentWindow.label === 'tray') {
|
|
||||||
modelDom.style.bottom = '54px';
|
|
||||||
}
|
|
||||||
|
|
||||||
document.querySelector('form').appendChild(modelDom);
|
|
||||||
const itemDom = (v) => `<div class="cmd-item" title="${v.prompt}" data-cmd="${v.cmd}" data-prompt="${encodeURIComponent(v.prompt)}"><b title="${v.cmd}">/${v.cmd}</b><i>${v.act}</i></div>`;
|
|
||||||
const renderList = (v) => {
|
|
||||||
modelDom.innerHTML = `<div>${v.map(itemDom).join('')}</div>`;
|
|
||||||
window.__CHAT_MODEL_CMD_PROMPT__ = v[0]?.prompt.trim();
|
|
||||||
window.__CHAT_MODEL_CMD__ = v[0]?.cmd.trim();
|
|
||||||
window.__list = modelDom.querySelectorAll('.cmd-item');
|
|
||||||
window.__index = 0;
|
|
||||||
window.__list[window.__index].classList.add('selected');
|
|
||||||
};
|
|
||||||
const setPrompt = (v = '') => {
|
|
||||||
if (v.trim()) {
|
|
||||||
window.__CHAT_MODEL_CMD_PROMPT__ = window.__CHAT_MODEL_CMD_PROMPT__?.replace(/\{([^{}]*)\}/, `{${v.trim()}}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const searchInput = document.querySelector('form textarea');
|
|
||||||
|
|
||||||
// Enter a command starting with `/` and press a space to automatically fill `chatgpt prompt`.
|
|
||||||
// If more than one command appears in the search results, the first one will be used by default.
|
|
||||||
searchInput.addEventListener('keydown', (event) => {
|
|
||||||
if (!window.__CHAT_MODEL_CMD_PROMPT__) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------ Keyboard scrolling (ArrowUp | ArrowDown) --------------------------
|
|
||||||
if (event.keyCode === 38 && window.__index > 0) { // ArrowUp
|
|
||||||
window.__list[window.__index].classList.remove('selected');
|
|
||||||
window.__index = window.__index - 1;
|
|
||||||
window.__list[window.__index].classList.add('selected');
|
|
||||||
window.__CHAT_MODEL_CMD_PROMPT__ = decodeURIComponent(window.__list[window.__index].getAttribute('data-prompt'));
|
|
||||||
searchInput.value = `/${window.__list[window.__index].getAttribute('data-cmd')}`;
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.keyCode === 40 && window.__index < window.__list.length - 1) { // ArrowDown
|
|
||||||
window.__list[window.__index].classList.remove('selected');
|
|
||||||
window.__index = window.__index + 1;
|
|
||||||
window.__list[window.__index].classList.add('selected');
|
|
||||||
window.__CHAT_MODEL_CMD_PROMPT__ = decodeURIComponent(window.__list[window.__index].getAttribute('data-prompt'));
|
|
||||||
searchInput.value = `/${window.__list[window.__index].getAttribute('data-cmd')}`;
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
const containerHeight = modelDom.offsetHeight;
|
|
||||||
const itemHeight = window.__list[0].offsetHeight + 1;
|
|
||||||
|
|
||||||
const itemTop = window.__list[window.__index].offsetTop;
|
|
||||||
const itemBottom = itemTop + itemHeight;
|
|
||||||
if (itemTop < modelDom.scrollTop || itemBottom > modelDom.scrollTop + containerHeight) {
|
|
||||||
modelDom.scrollTop = itemTop;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------ TAB key replaces `{q}` tag content -------------------------------
|
|
||||||
// feat: https://github.com/lencx/ChatGPT/issues/54
|
|
||||||
if (event.keyCode === 9 && !window.__CHAT_MODEL_STATUS__) {
|
|
||||||
const strGroup = window.__CHAT_MODEL_CMD_PROMPT__.match(/\{([^{}]*)\}/) || [];
|
|
||||||
|
|
||||||
if (strGroup[1]) {
|
|
||||||
searchInput.value = `/${window.__CHAT_MODEL_CMD__}` + ` {${strGroup[1]}}` + ' |-> ';
|
|
||||||
window.__CHAT_MODEL_STATUS__ = 1;
|
|
||||||
}
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (window.__CHAT_MODEL_STATUS__ === 1 && event.keyCode === 9) { // TAB
|
|
||||||
const data = searchInput.value.split('|->');
|
|
||||||
if (data[1]?.trim()) {
|
|
||||||
setPrompt(data[1]);
|
|
||||||
window.__CHAT_MODEL_STATUS__ = 2;
|
|
||||||
}
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
// input text
|
|
||||||
if (window.__CHAT_MODEL_STATUS__ === 2 && event.keyCode === 9) { // TAB
|
|
||||||
searchInput.value = window.__CHAT_MODEL_CMD_PROMPT__;
|
|
||||||
modelDom.innerHTML = '';
|
|
||||||
delete window.__CHAT_MODEL_STATUS__;
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------ type in a space to complete the fill ------------------------------------
|
|
||||||
if (event.keyCode === 32) {
|
|
||||||
searchInput.value = window.__CHAT_MODEL_CMD_PROMPT__;
|
|
||||||
modelDom.innerHTML = '';
|
|
||||||
delete window.__CHAT_MODEL_CMD_PROMPT__;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------ send --------------------------------------------------------------------
|
|
||||||
if (event.keyCode === 13 && window.__CHAT_MODEL_CMD_PROMPT__) { // Enter
|
|
||||||
const data = searchInput.value.split('|->');
|
|
||||||
setPrompt(data[1]);
|
|
||||||
|
|
||||||
searchInput.value = window.__CHAT_MODEL_CMD_PROMPT__;
|
|
||||||
modelDom.innerHTML = '';
|
|
||||||
delete window.__CHAT_MODEL_CMD_PROMPT__;
|
|
||||||
delete window.__CHAT_MODEL_CMD__;
|
|
||||||
delete window.__CHAT_MODEL_STATUS__;
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
searchInput.addEventListener('input', () => {
|
|
||||||
if (searchInput.value === '') {
|
|
||||||
delete window.__CHAT_MODEL_CMD_PROMPT__;
|
|
||||||
delete window.__CHAT_MODEL_CMD__;
|
|
||||||
delete window.__CHAT_MODEL_STATUS__;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (window.__CHAT_MODEL_STATUS__) return;
|
|
||||||
|
|
||||||
const query = searchInput.value;
|
|
||||||
if (!query || !/^\//.test(query)) {
|
|
||||||
modelDom.innerHTML = '';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// all cmd result
|
|
||||||
if (query === '/') {
|
|
||||||
renderList(data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = data.filter(i => new RegExp(query.substring(1)).test(i.cmd));
|
|
||||||
if (result.length > 0) {
|
|
||||||
renderList(result);
|
|
||||||
} else {
|
|
||||||
modelDom.innerHTML = '';
|
|
||||||
delete window.__CHAT_MODEL_CMD_PROMPT__;
|
|
||||||
delete window.__CHAT_MODEL_CMD__;
|
|
||||||
delete window.__CHAT_MODEL_STATUS__;
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
capture: false,
|
|
||||||
passive: true,
|
|
||||||
once: false
|
|
||||||
});
|
|
||||||
|
|
||||||
if (window.searchInterval) {
|
|
||||||
clearInterval(window.searchInterval);
|
|
||||||
}
|
|
||||||
window.searchInterval = setInterval(() => {
|
|
||||||
// The `chatgpt prompt` fill can be done by clicking on the event.
|
|
||||||
const searchDom = document.querySelector("form .chat-model-cmd-list>div");
|
|
||||||
if (!searchDom) return;
|
|
||||||
searchDom.addEventListener('click', (event) => {
|
|
||||||
// .cmd-item
|
|
||||||
const item = event.target.closest("div");
|
|
||||||
if (item) {
|
|
||||||
const val = decodeURIComponent(item.getAttribute('data-prompt'));
|
|
||||||
searchInput.value = val;
|
|
||||||
document.querySelector('form textarea').focus();
|
|
||||||
window.__CHAT_MODEL_CMD_PROMPT__ = val;
|
|
||||||
modelDom.innerHTML = '';
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
capture: false,
|
|
||||||
passive: true,
|
|
||||||
once: false
|
|
||||||
});
|
|
||||||
}, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
document.readyState === "complete" ||
|
|
||||||
document.readyState === "interactive"
|
|
||||||
) {
|
|
||||||
init();
|
|
||||||
} else {
|
|
||||||
document.addEventListener("DOMContentLoaded", init);
|
|
||||||
}
|
|
||||||
103
src-tauri/src/assets/core.js
vendored
103
src-tauri/src/assets/core.js
vendored
@@ -1,103 +0,0 @@
|
|||||||
// *** Core Script - IPC ***
|
|
||||||
|
|
||||||
const uid = () => window.crypto.getRandomValues(new Uint32Array(1))[0];
|
|
||||||
function transformCallback(callback = () => {}, once = false) {
|
|
||||||
const identifier = uid();
|
|
||||||
const prop = `_${identifier}`;
|
|
||||||
Object.defineProperty(window, prop, {
|
|
||||||
value: (result) => {
|
|
||||||
if (once) {
|
|
||||||
Reflect.deleteProperty(window, prop);
|
|
||||||
}
|
|
||||||
return callback(result)
|
|
||||||
},
|
|
||||||
writable: false,
|
|
||||||
configurable: true,
|
|
||||||
})
|
|
||||||
return identifier;
|
|
||||||
}
|
|
||||||
async function invoke(cmd, args) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
if (!window.__TAURI_POST_MESSAGE__) reject('__TAURI_POST_MESSAGE__ does not exist!');
|
|
||||||
const callback = transformCallback((e) => {
|
|
||||||
resolve(e);
|
|
||||||
Reflect.deleteProperty(window, `_${error}`);
|
|
||||||
}, true)
|
|
||||||
const error = transformCallback((e) => {
|
|
||||||
reject(e);
|
|
||||||
Reflect.deleteProperty(window, `_${callback}`);
|
|
||||||
}, true)
|
|
||||||
window.__TAURI_POST_MESSAGE__({
|
|
||||||
cmd,
|
|
||||||
callback,
|
|
||||||
error,
|
|
||||||
...args
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
window.uid = uid;
|
|
||||||
window.invoke = invoke;
|
|
||||||
window.transformCallback = transformCallback;
|
|
||||||
|
|
||||||
async function init() {
|
|
||||||
if (__TAURI_METADATA__.__currentWindow.label === 'tray') {
|
|
||||||
document.getElementsByTagName('html')[0].style['font-size'] = '70%';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (__TAURI_METADATA__.__currentWindow.label !== 'core') return;
|
|
||||||
|
|
||||||
async function platform() {
|
|
||||||
return invoke('platform', {
|
|
||||||
__tauriModule: 'Os',
|
|
||||||
message: { cmd: 'platform' }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const _platform = await platform();
|
|
||||||
const chatConf = await invoke('get_chat_conf') || {};
|
|
||||||
if (/darwin/.test(_platform) && !chatConf.titlebar) {
|
|
||||||
const topStyleDom = document.createElement("style");
|
|
||||||
topStyleDom.innerHTML = `#chatgpt-app-window-top{position:fixed;top:0;z-index:999999999;width:100%;height:24px;background:transparent;cursor:grab;cursor:-webkit-grab;user-select:none;-webkit-user-select:none;}#chatgpt-app-window-top:active {cursor:grabbing;cursor:-webkit-grabbing;}`;
|
|
||||||
document.head.appendChild(topStyleDom);
|
|
||||||
const topDom = document.createElement("div");
|
|
||||||
topDom.id = "chatgpt-app-window-top";
|
|
||||||
document.body.appendChild(topDom);
|
|
||||||
|
|
||||||
topDom.addEventListener("mousedown", () => invoke("drag_window"));
|
|
||||||
topDom.addEventListener("touchstart", () => invoke("drag_window"));
|
|
||||||
topDom.addEventListener("dblclick", () => invoke("fullscreen"));
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener("click", (e) => {
|
|
||||||
const origin = e.target.closest("a");
|
|
||||||
if (!origin.target) return;
|
|
||||||
if (origin && origin.href && origin.target !== '_self') {
|
|
||||||
invoke('open_link', { url: origin.href });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
window.__sync_prompts = async function() {
|
|
||||||
await invoke('sync_prompts', { time: Date.now() });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
document.readyState === "complete" ||
|
|
||||||
document.readyState === "interactive"
|
|
||||||
) {
|
|
||||||
init();
|
|
||||||
} else {
|
|
||||||
document.addEventListener("DOMContentLoaded", init);
|
|
||||||
}
|
|
||||||
40
src-tauri/src/assets/dalle2.js
vendored
40
src-tauri/src/assets/dalle2.js
vendored
@@ -1,40 +0,0 @@
|
|||||||
// *** Core Script - DALL·E 2 ***
|
|
||||||
|
|
||||||
async function init() {
|
|
||||||
document.addEventListener("click", (e) => {
|
|
||||||
const origin = e.target.closest("a");
|
|
||||||
if (!origin.target) return;
|
|
||||||
if (origin && origin.href && origin.target !== '_self') {
|
|
||||||
if (/\/(login|signup)$/.test(window.location.href)) {
|
|
||||||
origin.target = '_self';
|
|
||||||
} else {
|
|
||||||
invoke('open_link', { url: origin.href });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (window.searchInterval) {
|
|
||||||
clearInterval(window.searchInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.searchInterval = setInterval(() => {
|
|
||||||
const searchInput = document.querySelector('.image-prompt-form-wrapper form>.text-input');
|
|
||||||
if (searchInput) {
|
|
||||||
clearInterval(window.searchInterval);
|
|
||||||
|
|
||||||
if (!window.__CHATGPT_QUERY__) return;
|
|
||||||
const query = decodeURIComponent(window.__CHATGPT_QUERY__);
|
|
||||||
searchInput.focus();
|
|
||||||
searchInput.value = query;
|
|
||||||
}
|
|
||||||
}, 200)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
document.readyState === "complete" ||
|
|
||||||
document.readyState === "interactive"
|
|
||||||
) {
|
|
||||||
init();
|
|
||||||
} else {
|
|
||||||
document.addEventListener("DOMContentLoaded", init);
|
|
||||||
}
|
|
||||||
287
src-tauri/src/assets/export.js
vendored
287
src-tauri/src/assets/export.js
vendored
@@ -1,287 +0,0 @@
|
|||||||
// *** Core Script - Export ***
|
|
||||||
// @ref: https://github.com/liady/ChatGPT-pdf
|
|
||||||
|
|
||||||
const buttonOuterHTMLFallback = `<button class="btn flex justify-center gap-2 btn-neutral" id="download-png-button">Try Again</button>`;
|
|
||||||
async function init() {
|
|
||||||
if (window.innerWidth < 767) return;
|
|
||||||
const chatConf = await invoke('get_chat_conf') || {};
|
|
||||||
if (window.buttonsInterval) {
|
|
||||||
clearInterval(window.buttonsInterval);
|
|
||||||
}
|
|
||||||
window.buttonsInterval = setInterval(() => {
|
|
||||||
const actionsArea = document.querySelector("form>div>div");
|
|
||||||
if (!actionsArea) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (shouldAddButtons(actionsArea)) {
|
|
||||||
let TryAgainButton = actionsArea.querySelector("button");
|
|
||||||
if (!TryAgainButton) {
|
|
||||||
const parentNode = document.createElement("div");
|
|
||||||
parentNode.innerHTML = buttonOuterHTMLFallback;
|
|
||||||
TryAgainButton = parentNode.querySelector("button");
|
|
||||||
}
|
|
||||||
addActionsButtons(actionsArea, TryAgainButton, chatConf);
|
|
||||||
} else if (shouldRemoveButtons()) {
|
|
||||||
removeButtons();
|
|
||||||
}
|
|
||||||
}, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
const Format = {
|
|
||||||
PNG: "png",
|
|
||||||
PDF: "pdf",
|
|
||||||
};
|
|
||||||
|
|
||||||
function shouldRemoveButtons() {
|
|
||||||
const isOpenScreen = document.querySelector("h1.text-4xl");
|
|
||||||
if(isOpenScreen){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
const inConversation = document.querySelector("form button>div");
|
|
||||||
if(inConversation){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldAddButtons(actionsArea) {
|
|
||||||
// first, check if there's a "Try Again" button and no other buttons
|
|
||||||
const buttons = actionsArea.querySelectorAll("button");
|
|
||||||
const hasTryAgainButton = Array.from(buttons).some((button) => {
|
|
||||||
return !button.id?.includes("download");
|
|
||||||
});
|
|
||||||
if (hasTryAgainButton && buttons.length === 1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// otherwise, check if open screen is not visible
|
|
||||||
const isOpenScreen = document.querySelector("h1.text-4xl");
|
|
||||||
if (isOpenScreen) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if the conversation is finished and there are no share buttons
|
|
||||||
const finishedConversation = document.querySelector("form button>svg");
|
|
||||||
const hasShareButtons = actionsArea.querySelectorAll("button[share-ext]");
|
|
||||||
if (finishedConversation && !hasShareButtons.length) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeButtons() {
|
|
||||||
const downloadButton = document.getElementById("download-png-button");
|
|
||||||
const downloadPdfButton = document.getElementById("download-pdf-button");
|
|
||||||
const downloadHtmlButton = document.getElementById("download-html-button");
|
|
||||||
if (downloadButton) {
|
|
||||||
downloadButton.remove();
|
|
||||||
}
|
|
||||||
if (downloadPdfButton) {
|
|
||||||
downloadPdfButton.remove();
|
|
||||||
}
|
|
||||||
if (downloadHtmlButton) {
|
|
||||||
downloadHtmlButton.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addActionsButtons(actionsArea, TryAgainButton) {
|
|
||||||
const downloadButton = TryAgainButton.cloneNode(true);
|
|
||||||
downloadButton.id = "download-png-button";
|
|
||||||
downloadButton.setAttribute("share-ext", "true");
|
|
||||||
// downloadButton.innerText = "Generate PNG";
|
|
||||||
downloadButton.title = "Generate PNG";
|
|
||||||
downloadButton.innerHTML = setIcon('png');
|
|
||||||
downloadButton.onclick = () => {
|
|
||||||
downloadThread();
|
|
||||||
};
|
|
||||||
actionsArea.appendChild(downloadButton);
|
|
||||||
const downloadPdfButton = TryAgainButton.cloneNode(true);
|
|
||||||
downloadPdfButton.id = "download-pdf-button";
|
|
||||||
downloadButton.setAttribute("share-ext", "true");
|
|
||||||
// downloadPdfButton.innerText = "Download PDF";
|
|
||||||
downloadPdfButton.title = "Download PDF";
|
|
||||||
downloadPdfButton.innerHTML = setIcon('pdf');
|
|
||||||
downloadPdfButton.onclick = () => {
|
|
||||||
downloadThread({ as: Format.PDF });
|
|
||||||
};
|
|
||||||
actionsArea.appendChild(downloadPdfButton);
|
|
||||||
const exportHtml = TryAgainButton.cloneNode(true);
|
|
||||||
exportHtml.id = "download-html-button";
|
|
||||||
downloadButton.setAttribute("share-ext", "true");
|
|
||||||
// exportHtml.innerText = "Share Link";
|
|
||||||
exportHtml.title = "Share Link";
|
|
||||||
exportHtml.innerHTML = setIcon('link');
|
|
||||||
exportHtml.onclick = () => {
|
|
||||||
sendRequest();
|
|
||||||
};
|
|
||||||
actionsArea.appendChild(exportHtml);
|
|
||||||
}
|
|
||||||
|
|
||||||
function downloadThread({ as = Format.PNG } = {}) {
|
|
||||||
const elements = new Elements();
|
|
||||||
elements.fixLocation();
|
|
||||||
const pixelRatio = window.devicePixelRatio;
|
|
||||||
const minRatio = as === Format.PDF ? 2 : 2.5;
|
|
||||||
window.devicePixelRatio = Math.max(pixelRatio, minRatio);
|
|
||||||
|
|
||||||
html2canvas(elements.thread, {
|
|
||||||
letterRendering: true,
|
|
||||||
}).then(async function (canvas) {
|
|
||||||
elements.restoreLocation();
|
|
||||||
window.devicePixelRatio = pixelRatio;
|
|
||||||
const imgData = canvas.toDataURL("image/png");
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
if (as === Format.PDF) {
|
|
||||||
return handlePdf(imgData, canvas, pixelRatio);
|
|
||||||
} else {
|
|
||||||
handleImg(imgData);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleImg(imgData) {
|
|
||||||
const binaryData = atob(imgData.split("base64,")[1]);
|
|
||||||
const data = [];
|
|
||||||
for (let i = 0; i < binaryData.length; i++) {
|
|
||||||
data.push(binaryData.charCodeAt(i));
|
|
||||||
}
|
|
||||||
invoke('download', { name: `chatgpt-${Date.now()}.png`, blob: Array.from(new Uint8Array(data)) });
|
|
||||||
}
|
|
||||||
|
|
||||||
function handlePdf(imgData, canvas, pixelRatio) {
|
|
||||||
const { jsPDF } = window.jspdf;
|
|
||||||
const orientation = canvas.width > canvas.height ? "l" : "p";
|
|
||||||
var pdf = new jsPDF(orientation, "pt", [
|
|
||||||
canvas.width / pixelRatio,
|
|
||||||
canvas.height / pixelRatio,
|
|
||||||
]);
|
|
||||||
var pdfWidth = pdf.internal.pageSize.getWidth();
|
|
||||||
var pdfHeight = pdf.internal.pageSize.getHeight();
|
|
||||||
pdf.addImage(imgData, "PNG", 0, 0, pdfWidth, pdfHeight, '', 'FAST');
|
|
||||||
|
|
||||||
const data = pdf.__private__.getArrayBuffer(pdf.__private__.buildDocument());
|
|
||||||
invoke('download', { name: `chatgpt-${Date.now()}.pdf`, blob: Array.from(new Uint8Array(data)) });
|
|
||||||
}
|
|
||||||
|
|
||||||
class Elements {
|
|
||||||
constructor() {
|
|
||||||
this.init();
|
|
||||||
}
|
|
||||||
init() {
|
|
||||||
// this.threadWrapper = document.querySelector(".cdfdFe");
|
|
||||||
this.spacer = document.querySelector(".w-full.h-48.flex-shrink-0");
|
|
||||||
this.thread = document.querySelector(
|
|
||||||
"[class*='react-scroll-to-bottom']>[class*='react-scroll-to-bottom']>div"
|
|
||||||
);
|
|
||||||
this.positionForm = document.querySelector("form").parentNode;
|
|
||||||
// this.styledThread = document.querySelector("main");
|
|
||||||
// this.threadContent = document.querySelector(".gAnhyd");
|
|
||||||
this.scroller = Array.from(
|
|
||||||
document.querySelectorAll('[class*="react-scroll-to"]')
|
|
||||||
).filter((el) => el.classList.contains("h-full"))[0];
|
|
||||||
this.hiddens = Array.from(document.querySelectorAll(".overflow-hidden"));
|
|
||||||
this.images = Array.from(document.querySelectorAll("img[srcset]"));
|
|
||||||
}
|
|
||||||
fixLocation() {
|
|
||||||
this.hiddens.forEach((el) => {
|
|
||||||
el.classList.remove("overflow-hidden");
|
|
||||||
});
|
|
||||||
this.spacer.style.display = "none";
|
|
||||||
this.thread.style.maxWidth = "960px";
|
|
||||||
this.thread.style.marginInline = "auto";
|
|
||||||
this.positionForm.style.display = "none";
|
|
||||||
this.scroller.classList.remove("h-full");
|
|
||||||
this.scroller.style.minHeight = "100vh";
|
|
||||||
this.images.forEach((img) => {
|
|
||||||
const srcset = img.getAttribute("srcset");
|
|
||||||
img.setAttribute("srcset_old", srcset);
|
|
||||||
img.setAttribute("srcset", "");
|
|
||||||
});
|
|
||||||
//Fix to the text shifting down when generating the canvas
|
|
||||||
document.body.style.lineHeight = "0.5";
|
|
||||||
}
|
|
||||||
restoreLocation() {
|
|
||||||
this.hiddens.forEach((el) => {
|
|
||||||
el.classList.add("overflow-hidden");
|
|
||||||
});
|
|
||||||
this.spacer.style.display = null;
|
|
||||||
this.thread.style.maxWidth = null;
|
|
||||||
this.thread.style.marginInline = null;
|
|
||||||
this.positionForm.style.display = null;
|
|
||||||
this.scroller.classList.add("h-full");
|
|
||||||
this.scroller.style.minHeight = null;
|
|
||||||
this.images.forEach((img) => {
|
|
||||||
const srcset = img.getAttribute("srcset_old");
|
|
||||||
img.setAttribute("srcset", srcset);
|
|
||||||
img.setAttribute("srcset_old", "");
|
|
||||||
});
|
|
||||||
document.body.style.lineHeight = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function selectElementByClassPrefix(classPrefix) {
|
|
||||||
const element = document.querySelector(`[class^='${classPrefix}']`);
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function sendRequest() {
|
|
||||||
const data = getData();
|
|
||||||
const uploadUrlResponse = await fetch(
|
|
||||||
"https://chatgpt-static.s3.amazonaws.com/url.txt"
|
|
||||||
);
|
|
||||||
const uploadUrl = await uploadUrlResponse.text();
|
|
||||||
fetch(uploadUrl, {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
invoke('open_link', { url: data.url });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getData() {
|
|
||||||
const globalCss = getCssFromSheet(
|
|
||||||
document.querySelector("link[rel=stylesheet]").sheet
|
|
||||||
);
|
|
||||||
const localCss =
|
|
||||||
getCssFromSheet(
|
|
||||||
document.querySelector(`style[data-styled][data-styled-version]`).sheet
|
|
||||||
) || "body{}";
|
|
||||||
const data = {
|
|
||||||
main: document.querySelector("main").outerHTML,
|
|
||||||
// css: `${globalCss} /* GLOBAL-LOCAL */ ${localCss}`,
|
|
||||||
globalCss,
|
|
||||||
localCss,
|
|
||||||
};
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCssFromSheet(sheet) {
|
|
||||||
return Array.from(sheet.cssRules)
|
|
||||||
.map((rule) => rule.cssText)
|
|
||||||
.join("");
|
|
||||||
}
|
|
||||||
|
|
||||||
// run init
|
|
||||||
if (
|
|
||||||
document.readyState === "complete" ||
|
|
||||||
document.readyState === "interactive"
|
|
||||||
) {
|
|
||||||
init();
|
|
||||||
} else {
|
|
||||||
document.addEventListener("DOMContentLoaded", init);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setIcon(type) {
|
|
||||||
return {
|
|
||||||
link: `<svg class="chatappico" viewBox="0 0 1024 1024"><path d="M1007.382 379.672L655.374 75.702C624.562 49.092 576 70.694 576 112.03v160.106C254.742 275.814 0 340.2 0 644.652c0 122.882 79.162 244.618 166.666 308.264 27.306 19.862 66.222-5.066 56.154-37.262C132.132 625.628 265.834 548.632 576 544.17V720c0 41.4 48.6 62.906 79.374 36.328l352.008-304c22.142-19.124 22.172-53.506 0-72.656z" p-id="8506" fill="currentColor"></path></svg>`,
|
|
||||||
png: `<svg class="chatappico" viewBox="0 0 1070 1024"><path d="M981.783273 0H85.224727C38.353455 0 0 35.374545 0 83.083636v844.893091c0 47.616 38.353455 86.574545 85.178182 86.574546h903.633454c46.917818 0 81.733818-38.958545 81.733819-86.574546V83.083636C1070.592 35.374545 1028.701091 0 981.783273 0zM335.825455 135.912727c74.193455 0 134.330182 60.974545 134.330181 136.285091 0 75.170909-60.136727 136.192-134.330181 136.192-74.286545 0-134.516364-61.021091-134.516364-136.192 0-75.264 60.229818-136.285091 134.516364-136.285091z m-161.512728 745.937455a41.890909 41.890909 0 0 1-27.648-10.379637 43.752727 43.752727 0 0 1-4.654545-61.067636l198.097454-255.162182a42.123636 42.123636 0 0 1 57.716364-6.702545l116.549818 128.139636 286.906182-352.814545c14.615273-18.711273 90.251636-106.775273 135.866182-6.935273 0.093091-0.093091 0.093091 112.965818 0.232727 247.761455 0.093091 140.8 0.093091 317.067636 0.093091 317.067636-1.024-0.093091-762.740364 0.093091-763.112727 0.093091z" fill="currentColor"></path></svg>`,
|
|
||||||
pdf: `<svg class="chatappico pdf" viewBox="0 0 1024 1024"><path d="M821.457602 118.382249H205.725895c-48.378584 0-87.959995 39.583368-87.959996 87.963909v615.731707c0 48.378584 39.581411 87.959995 87.959996 87.959996h615.733664c48.380541 0 87.961952-39.581411 87.961952-87.959996V206.346158c-0.001957-48.378584-39.583368-87.963909-87.963909-87.963909zM493.962468 457.544987c-10.112054 32.545237-21.72487 82.872662-38.806571 124.248336-8.806957 22.378397-8.380404 18.480717-15.001764 32.609808l5.71738-1.851007c58.760658-16.443827 99.901532-20.519564 138.162194-27.561607-7.67796-6.06371-14.350194-10.751884-19.631237-15.586807-26.287817-29.101504-35.464584-34.570387-70.440002-111.862636v0.003913z m288.36767 186.413594c-7.476424 8.356924-20.670227 13.191847-40.019704 13.191847-33.427694 0-63.808858-9.229597-107.79277-31.660824-75.648648 8.356924-156.097 17.214754-201.399704 31.729308-2.199293 0.876587-4.832967 1.759043-7.916674 3.077836-54.536215 93.237125-95.031389 132.767663-130.621199 131.19646-11.286054-0.49895-27.694661-7.044-32.973748-10.11988l-6.52157-6.196764-2.29517-4.353583c-3.07588-7.91863-3.954423-15.395054-2.197337-23.751977 4.838837-23.309771 29.907651-60.251638 82.686779-93.237126 8.356924-6.159587 27.430511-15.897917 45.020944-24.25484 13.311204-21.177004 19.45905-34.744531 36.341171-72.259702 19.102937-45.324228 36.505531-99.492589 47.500041-138.191543v-0.44025c-16.267727-53.219378-25.945401-89.310095-9.67376-147.80856 3.958337-16.71189 18.46702-33.864031 34.748444-33.864031h10.552304c10.115967 0 19.791684 3.520043 26.829814 10.552304 29.029107 29.031064 15.39114 103.824649 0.8805 162.323113-0.8805 2.63563-1.322707 4.832967-1.761 6.153717 17.59239 49.697378 45.400538 98.774492 73.108895 121.647926 11.436717 8.791304 22.638634 18.899444 36.71098 26.814161 19.791684-2.20125 37.517128-4.11487 55.547812-4.11487 54.540128 0 87.525615 9.67963 100.279169 30.351814 4.400543 7.034217 6.595923 15.389184 5.281043 24.1844-0.44025 10.996467-4.39663 21.112434-12.31526 29.031064z m-27.796407-36.748157c-4.394673-4.398587-17.024957-16.936907-78.601259-16.936907-3.073923 0-10.622744-0.784623-14.57521 3.612007 32.104987 14.072347 62.830525 24.757704 83.058545 24.757703 3.083707 0 5.72325-0.442207 8.356923-0.876586h1.759044c2.20125-0.8805 3.520043-1.324663 3.960293-5.71738-0.87463-1.324663-1.757087-3.083707-3.958336-4.838837z m-387.124553 63.041845c-9.237424 5.27713-16.71189 10.112054-21.112433 13.634053-31.226444 28.586901-51.018128 57.616008-53.217422 74.331812 19.789727-6.59788 45.737084-35.626987 74.329855-87.961952v-0.003913z m125.574957-297.822284l2.197336-1.761c3.079793-14.072347 5.232127-29.189554 7.87167-38.869184l1.318794-7.036174c4.39663-25.070771 2.71781-39.720334-4.76057-50.272637l-6.59788-2.20125a57.381208 57.381208 0 0 0-3.079794 5.27713c-7.474467 18.47289-7.063567 55.283661 3.0524 94.865072l-0.001956-0.001957z" fill="currentColor"></path></svg>`
|
|
||||||
}[type];
|
|
||||||
}
|
|
||||||
84
src-tauri/src/assets/popup.core.js
vendored
84
src-tauri/src/assets/popup.core.js
vendored
@@ -1,84 +0,0 @@
|
|||||||
// *** Core Script - DALL·E 2 Core ***
|
|
||||||
|
|
||||||
async function init() {
|
|
||||||
const chatConf = await invoke('get_chat_conf') || {};
|
|
||||||
if (!chatConf.popup_search) return;
|
|
||||||
if (!window.FloatingUIDOM) return;
|
|
||||||
|
|
||||||
const styleDom = document.createElement('style');
|
|
||||||
styleDom.innerHTML = `
|
|
||||||
#chagpt-selection-menu {
|
|
||||||
display: none;
|
|
||||||
width: max-content;
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
background: #4a4a4a;
|
|
||||||
color: white;
|
|
||||||
font-weight: bold;
|
|
||||||
padding: 5px 8px;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 12px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
document.head.append(styleDom);
|
|
||||||
|
|
||||||
const selectionMenu = document.createElement('div');
|
|
||||||
selectionMenu.id = 'chagpt-selection-menu';
|
|
||||||
selectionMenu.innerHTML = 'DALL·E 2';
|
|
||||||
document.body.appendChild(selectionMenu);
|
|
||||||
const { computePosition, flip, offset, shift } = window.FloatingUIDOM;
|
|
||||||
|
|
||||||
document.body.addEventListener('mousedown', async (e) => {
|
|
||||||
if (e.target.id === 'chagpt-selection-menu') {
|
|
||||||
await invoke('dalle2_window', { query: encodeURIComponent(window.__DALLE2_CONTENT__) });
|
|
||||||
} else {
|
|
||||||
delete window.__DALLE2_CONTENT__;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
document.body.addEventListener("mouseup", async (e) => {
|
|
||||||
selectionMenu.style.display = 'none';
|
|
||||||
const selection = window.getSelection();
|
|
||||||
window.__DALLE2_CONTENT__ = selection.toString().trim();
|
|
||||||
|
|
||||||
if (!window.__DALLE2_CONTENT__) return;
|
|
||||||
|
|
||||||
if (selection.rangeCount > 0) {
|
|
||||||
const range = selection.getRangeAt(0);
|
|
||||||
const rect = range.getClientRects()[0];
|
|
||||||
|
|
||||||
const rootEl = document.createElement('div');
|
|
||||||
rootEl.style.top = `${rect.top}px`;
|
|
||||||
rootEl.style.position = 'fixed';
|
|
||||||
rootEl.style.left = `${rect.left}px`;
|
|
||||||
document.body.appendChild(rootEl);
|
|
||||||
|
|
||||||
selectionMenu.style.display = 'block';
|
|
||||||
computePosition(rootEl, selectionMenu, {
|
|
||||||
placement: 'top',
|
|
||||||
middleware: [
|
|
||||||
flip(),
|
|
||||||
offset(5),
|
|
||||||
shift({ padding: 5 })
|
|
||||||
]
|
|
||||||
}).then(({x, y}) => {
|
|
||||||
Object.assign(selectionMenu.style, {
|
|
||||||
left: `${x}px`,
|
|
||||||
top: `${y}px`,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
document.readyState === "complete" ||
|
|
||||||
document.readyState === "interactive"
|
|
||||||
) {
|
|
||||||
init();
|
|
||||||
} else {
|
|
||||||
document.addEventListener("DOMContentLoaded", init);
|
|
||||||
}
|
|
||||||
2
src-tauri/src/scripts/core.js
vendored
2
src-tauri/src/scripts/core.js
vendored
@@ -71,7 +71,7 @@ $(async function () {
|
|||||||
|
|
||||||
document.addEventListener("click", (e) => {
|
document.addEventListener("click", (e) => {
|
||||||
const origin = e.target.closest("a");
|
const origin = e.target.closest("a");
|
||||||
if (!origin.target) return;
|
if (!origin || !origin.target) return;
|
||||||
if (origin && origin.href && origin.target !== '_self') {
|
if (origin && origin.href && origin.target !== '_self') {
|
||||||
invoke('open_link', { url: origin.href });
|
invoke('open_link', { url: origin.href });
|
||||||
}
|
}
|
||||||
|
|||||||
2
src-tauri/src/scripts/dalle2.js
vendored
2
src-tauri/src/scripts/dalle2.js
vendored
@@ -3,7 +3,7 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
document.addEventListener("click", (e) => {
|
document.addEventListener("click", (e) => {
|
||||||
const origin = e.target.closest("a");
|
const origin = e.target.closest("a");
|
||||||
if (!origin.target) return;
|
if (!origin || !origin.target) return;
|
||||||
if (origin && origin.href && origin.target !== '_self') {
|
if (origin && origin.href && origin.target !== '_self') {
|
||||||
if (/\/(login|signup)$/.test(window.location.href)) {
|
if (/\/(login|signup)$/.test(window.location.href)) {
|
||||||
origin.target = '_self';
|
origin.target = '_self';
|
||||||
|
|||||||
108
src-tauri/src/scripts/export.js
vendored
108
src-tauri/src/scripts/export.js
vendored
@@ -74,16 +74,16 @@ function shouldAddButtons(actionsArea) {
|
|||||||
function removeButtons() {
|
function removeButtons() {
|
||||||
const downloadButton = document.getElementById("download-png-button");
|
const downloadButton = document.getElementById("download-png-button");
|
||||||
const downloadPdfButton = document.getElementById("download-pdf-button");
|
const downloadPdfButton = document.getElementById("download-pdf-button");
|
||||||
const downloadHtmlButton = document.getElementById("download-html-button");
|
// const downloadHtmlButton = document.getElementById("download-html-button");
|
||||||
if (downloadButton) {
|
if (downloadButton) {
|
||||||
downloadButton.remove();
|
downloadButton.remove();
|
||||||
}
|
}
|
||||||
if (downloadPdfButton) {
|
if (downloadPdfButton) {
|
||||||
downloadPdfButton.remove();
|
downloadPdfButton.remove();
|
||||||
}
|
}
|
||||||
if (downloadHtmlButton) {
|
// if (downloadHtmlButton) {
|
||||||
downloadHtmlButton.remove();
|
// downloadHtmlButton.remove();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
function addActionsButtons(actionsArea, TryAgainButton) {
|
function addActionsButtons(actionsArea, TryAgainButton) {
|
||||||
@@ -107,16 +107,16 @@ function addActionsButtons(actionsArea, TryAgainButton) {
|
|||||||
downloadThread({ as: Format.PDF });
|
downloadThread({ as: Format.PDF });
|
||||||
};
|
};
|
||||||
actionsArea.appendChild(downloadPdfButton);
|
actionsArea.appendChild(downloadPdfButton);
|
||||||
const exportHtml = TryAgainButton.cloneNode(true);
|
// const exportHtml = TryAgainButton.cloneNode(true);
|
||||||
exportHtml.id = "download-html-button";
|
// exportHtml.id = "download-html-button";
|
||||||
downloadButton.setAttribute("share-ext", "true");
|
// downloadButton.setAttribute("share-ext", "true");
|
||||||
// exportHtml.innerText = "Share Link";
|
// // exportHtml.innerText = "Share Link";
|
||||||
exportHtml.title = "Share Link";
|
// exportHtml.title = "Share Link";
|
||||||
exportHtml.innerHTML = setIcon('link');
|
// exportHtml.innerHTML = setIcon('link');
|
||||||
exportHtml.onclick = () => {
|
// exportHtml.onclick = () => {
|
||||||
sendRequest();
|
// sendRequest();
|
||||||
};
|
// };
|
||||||
actionsArea.appendChild(exportHtml);
|
// actionsArea.appendChild(exportHtml);
|
||||||
}
|
}
|
||||||
|
|
||||||
function downloadThread({ as = Format.PNG } = {}) {
|
function downloadThread({ as = Format.PNG } = {}) {
|
||||||
@@ -227,51 +227,51 @@ function selectElementByClassPrefix(classPrefix) {
|
|||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendRequest() {
|
// async function sendRequest() {
|
||||||
const data = getData();
|
// const data = getData();
|
||||||
const uploadUrlResponse = await fetch(
|
// const uploadUrlResponse = await fetch(
|
||||||
"https://chatgpt-static.s3.amazonaws.com/url.txt"
|
// "https://chatgpt-static.s3.amazonaws.com/url.txt"
|
||||||
);
|
// );
|
||||||
const uploadUrl = await uploadUrlResponse.text();
|
// const uploadUrl = await uploadUrlResponse.text();
|
||||||
fetch(uploadUrl, {
|
// fetch(uploadUrl, {
|
||||||
method: "POST",
|
// method: "POST",
|
||||||
headers: {
|
// headers: {
|
||||||
"Content-Type": "application/json",
|
// "Content-Type": "application/json",
|
||||||
},
|
// },
|
||||||
body: JSON.stringify(data),
|
// body: JSON.stringify(data),
|
||||||
})
|
// })
|
||||||
.then((response) => response.json())
|
// .then((response) => response.json())
|
||||||
.then((data) => {
|
// .then((data) => {
|
||||||
invoke('open_link', { url: data.url });
|
// invoke('open_link', { url: data.url });
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
function getData() {
|
// function getData() {
|
||||||
const globalCss = getCssFromSheet(
|
// const globalCss = getCssFromSheet(
|
||||||
document.querySelector("link[rel=stylesheet]").sheet
|
// document.querySelector("link[rel=stylesheet]").sheet
|
||||||
);
|
// );
|
||||||
const localCss =
|
// const localCss =
|
||||||
getCssFromSheet(
|
// getCssFromSheet(
|
||||||
document.querySelector(`style[data-styled][data-styled-version]`).sheet
|
// document.querySelector(`style[data-styled][data-styled-version]`).sheet
|
||||||
) || "body{}";
|
// ) || "body{}";
|
||||||
const data = {
|
// const data = {
|
||||||
main: document.querySelector("main").outerHTML,
|
// main: document.querySelector("main").outerHTML,
|
||||||
// css: `${globalCss} /* GLOBAL-LOCAL */ ${localCss}`,
|
// // css: `${globalCss} /* GLOBAL-LOCAL */ ${localCss}`,
|
||||||
globalCss,
|
// globalCss,
|
||||||
localCss,
|
// localCss,
|
||||||
};
|
// };
|
||||||
return data;
|
// return data;
|
||||||
}
|
// }
|
||||||
|
|
||||||
function getCssFromSheet(sheet) {
|
// function getCssFromSheet(sheet) {
|
||||||
return Array.from(sheet.cssRules)
|
// return Array.from(sheet.cssRules)
|
||||||
.map((rule) => rule.cssText)
|
// .map((rule) => rule.cssText)
|
||||||
.join("");
|
// .join("");
|
||||||
}
|
// }
|
||||||
|
|
||||||
function setIcon(type) {
|
function setIcon(type) {
|
||||||
return {
|
return {
|
||||||
link: `<svg class="chatappico" viewBox="0 0 1024 1024"><path d="M1007.382 379.672L655.374 75.702C624.562 49.092 576 70.694 576 112.03v160.106C254.742 275.814 0 340.2 0 644.652c0 122.882 79.162 244.618 166.666 308.264 27.306 19.862 66.222-5.066 56.154-37.262C132.132 625.628 265.834 548.632 576 544.17V720c0 41.4 48.6 62.906 79.374 36.328l352.008-304c22.142-19.124 22.172-53.506 0-72.656z" p-id="8506" fill="currentColor"></path></svg>`,
|
// link: `<svg class="chatappico" viewBox="0 0 1024 1024"><path d="M1007.382 379.672L655.374 75.702C624.562 49.092 576 70.694 576 112.03v160.106C254.742 275.814 0 340.2 0 644.652c0 122.882 79.162 244.618 166.666 308.264 27.306 19.862 66.222-5.066 56.154-37.262C132.132 625.628 265.834 548.632 576 544.17V720c0 41.4 48.6 62.906 79.374 36.328l352.008-304c22.142-19.124 22.172-53.506 0-72.656z" p-id="8506" fill="currentColor"></path></svg>`,
|
||||||
png: `<svg class="chatappico" viewBox="0 0 1070 1024"><path d="M981.783273 0H85.224727C38.353455 0 0 35.374545 0 83.083636v844.893091c0 47.616 38.353455 86.574545 85.178182 86.574546h903.633454c46.917818 0 81.733818-38.958545 81.733819-86.574546V83.083636C1070.592 35.374545 1028.701091 0 981.783273 0zM335.825455 135.912727c74.193455 0 134.330182 60.974545 134.330181 136.285091 0 75.170909-60.136727 136.192-134.330181 136.192-74.286545 0-134.516364-61.021091-134.516364-136.192 0-75.264 60.229818-136.285091 134.516364-136.285091z m-161.512728 745.937455a41.890909 41.890909 0 0 1-27.648-10.379637 43.752727 43.752727 0 0 1-4.654545-61.067636l198.097454-255.162182a42.123636 42.123636 0 0 1 57.716364-6.702545l116.549818 128.139636 286.906182-352.814545c14.615273-18.711273 90.251636-106.775273 135.866182-6.935273 0.093091-0.093091 0.093091 112.965818 0.232727 247.761455 0.093091 140.8 0.093091 317.067636 0.093091 317.067636-1.024-0.093091-762.740364 0.093091-763.112727 0.093091z" fill="currentColor"></path></svg>`,
|
png: `<svg class="chatappico" viewBox="0 0 1070 1024"><path d="M981.783273 0H85.224727C38.353455 0 0 35.374545 0 83.083636v844.893091c0 47.616 38.353455 86.574545 85.178182 86.574546h903.633454c46.917818 0 81.733818-38.958545 81.733819-86.574546V83.083636C1070.592 35.374545 1028.701091 0 981.783273 0zM335.825455 135.912727c74.193455 0 134.330182 60.974545 134.330181 136.285091 0 75.170909-60.136727 136.192-134.330181 136.192-74.286545 0-134.516364-61.021091-134.516364-136.192 0-75.264 60.229818-136.285091 134.516364-136.285091z m-161.512728 745.937455a41.890909 41.890909 0 0 1-27.648-10.379637 43.752727 43.752727 0 0 1-4.654545-61.067636l198.097454-255.162182a42.123636 42.123636 0 0 1 57.716364-6.702545l116.549818 128.139636 286.906182-352.814545c14.615273-18.711273 90.251636-106.775273 135.866182-6.935273 0.093091-0.093091 0.093091 112.965818 0.232727 247.761455 0.093091 140.8 0.093091 317.067636 0.093091 317.067636-1.024-0.093091-762.740364 0.093091-763.112727 0.093091z" fill="currentColor"></path></svg>`,
|
||||||
pdf: `<svg class="chatappico pdf" viewBox="0 0 1024 1024"><path d="M821.457602 118.382249H205.725895c-48.378584 0-87.959995 39.583368-87.959996 87.963909v615.731707c0 48.378584 39.581411 87.959995 87.959996 87.959996h615.733664c48.380541 0 87.961952-39.581411 87.961952-87.959996V206.346158c-0.001957-48.378584-39.583368-87.963909-87.963909-87.963909zM493.962468 457.544987c-10.112054 32.545237-21.72487 82.872662-38.806571 124.248336-8.806957 22.378397-8.380404 18.480717-15.001764 32.609808l5.71738-1.851007c58.760658-16.443827 99.901532-20.519564 138.162194-27.561607-7.67796-6.06371-14.350194-10.751884-19.631237-15.586807-26.287817-29.101504-35.464584-34.570387-70.440002-111.862636v0.003913z m288.36767 186.413594c-7.476424 8.356924-20.670227 13.191847-40.019704 13.191847-33.427694 0-63.808858-9.229597-107.79277-31.660824-75.648648 8.356924-156.097 17.214754-201.399704 31.729308-2.199293 0.876587-4.832967 1.759043-7.916674 3.077836-54.536215 93.237125-95.031389 132.767663-130.621199 131.19646-11.286054-0.49895-27.694661-7.044-32.973748-10.11988l-6.52157-6.196764-2.29517-4.353583c-3.07588-7.91863-3.954423-15.395054-2.197337-23.751977 4.838837-23.309771 29.907651-60.251638 82.686779-93.237126 8.356924-6.159587 27.430511-15.897917 45.020944-24.25484 13.311204-21.177004 19.45905-34.744531 36.341171-72.259702 19.102937-45.324228 36.505531-99.492589 47.500041-138.191543v-0.44025c-16.267727-53.219378-25.945401-89.310095-9.67376-147.80856 3.958337-16.71189 18.46702-33.864031 34.748444-33.864031h10.552304c10.115967 0 19.791684 3.520043 26.829814 10.552304 29.029107 29.031064 15.39114 103.824649 0.8805 162.323113-0.8805 2.63563-1.322707 4.832967-1.761 6.153717 17.59239 49.697378 45.400538 98.774492 73.108895 121.647926 11.436717 8.791304 22.638634 18.899444 36.71098 26.814161 19.791684-2.20125 37.517128-4.11487 55.547812-4.11487 54.540128 0 87.525615 9.67963 100.279169 30.351814 4.400543 7.034217 6.595923 15.389184 5.281043 24.1844-0.44025 10.996467-4.39663 21.112434-12.31526 29.031064z m-27.796407-36.748157c-4.394673-4.398587-17.024957-16.936907-78.601259-16.936907-3.073923 0-10.622744-0.784623-14.57521 3.612007 32.104987 14.072347 62.830525 24.757704 83.058545 24.757703 3.083707 0 5.72325-0.442207 8.356923-0.876586h1.759044c2.20125-0.8805 3.520043-1.324663 3.960293-5.71738-0.87463-1.324663-1.757087-3.083707-3.958336-4.838837z m-387.124553 63.041845c-9.237424 5.27713-16.71189 10.112054-21.112433 13.634053-31.226444 28.586901-51.018128 57.616008-53.217422 74.331812 19.789727-6.59788 45.737084-35.626987 74.329855-87.961952v-0.003913z m125.574957-297.822284l2.197336-1.761c3.079793-14.072347 5.232127-29.189554 7.87167-38.869184l1.318794-7.036174c4.39663-25.070771 2.71781-39.720334-4.76057-50.272637l-6.59788-2.20125a57.381208 57.381208 0 0 0-3.079794 5.27713c-7.474467 18.47289-7.063567 55.283661 3.0524 94.865072l-0.001956-0.001957z" fill="currentColor"></path></svg>`
|
pdf: `<svg class="chatappico pdf" viewBox="0 0 1024 1024"><path d="M821.457602 118.382249H205.725895c-48.378584 0-87.959995 39.583368-87.959996 87.963909v615.731707c0 48.378584 39.581411 87.959995 87.959996 87.959996h615.733664c48.380541 0 87.961952-39.581411 87.961952-87.959996V206.346158c-0.001957-48.378584-39.583368-87.963909-87.963909-87.963909zM493.962468 457.544987c-10.112054 32.545237-21.72487 82.872662-38.806571 124.248336-8.806957 22.378397-8.380404 18.480717-15.001764 32.609808l5.71738-1.851007c58.760658-16.443827 99.901532-20.519564 138.162194-27.561607-7.67796-6.06371-14.350194-10.751884-19.631237-15.586807-26.287817-29.101504-35.464584-34.570387-70.440002-111.862636v0.003913z m288.36767 186.413594c-7.476424 8.356924-20.670227 13.191847-40.019704 13.191847-33.427694 0-63.808858-9.229597-107.79277-31.660824-75.648648 8.356924-156.097 17.214754-201.399704 31.729308-2.199293 0.876587-4.832967 1.759043-7.916674 3.077836-54.536215 93.237125-95.031389 132.767663-130.621199 131.19646-11.286054-0.49895-27.694661-7.044-32.973748-10.11988l-6.52157-6.196764-2.29517-4.353583c-3.07588-7.91863-3.954423-15.395054-2.197337-23.751977 4.838837-23.309771 29.907651-60.251638 82.686779-93.237126 8.356924-6.159587 27.430511-15.897917 45.020944-24.25484 13.311204-21.177004 19.45905-34.744531 36.341171-72.259702 19.102937-45.324228 36.505531-99.492589 47.500041-138.191543v-0.44025c-16.267727-53.219378-25.945401-89.310095-9.67376-147.80856 3.958337-16.71189 18.46702-33.864031 34.748444-33.864031h10.552304c10.115967 0 19.791684 3.520043 26.829814 10.552304 29.029107 29.031064 15.39114 103.824649 0.8805 162.323113-0.8805 2.63563-1.322707 4.832967-1.761 6.153717 17.59239 49.697378 45.400538 98.774492 73.108895 121.647926 11.436717 8.791304 22.638634 18.899444 36.71098 26.814161 19.791684-2.20125 37.517128-4.11487 55.547812-4.11487 54.540128 0 87.525615 9.67963 100.279169 30.351814 4.400543 7.034217 6.595923 15.389184 5.281043 24.1844-0.44025 10.996467-4.39663 21.112434-12.31526 29.031064z m-27.796407-36.748157c-4.394673-4.398587-17.024957-16.936907-78.601259-16.936907-3.073923 0-10.622744-0.784623-14.57521 3.612007 32.104987 14.072347 62.830525 24.757704 83.058545 24.757703 3.083707 0 5.72325-0.442207 8.356923-0.876586h1.759044c2.20125-0.8805 3.520043-1.324663 3.960293-5.71738-0.87463-1.324663-1.757087-3.083707-3.958336-4.838837z m-387.124553 63.041845c-9.237424 5.27713-16.71189 10.112054-21.112433 13.634053-31.226444 28.586901-51.018128 57.616008-53.217422 74.331812 19.789727-6.59788 45.737084-35.626987 74.329855-87.961952v-0.003913z m125.574957-297.822284l2.197336-1.761c3.079793-14.072347 5.232127-29.189554 7.87167-38.869184l1.318794-7.036174c4.39663-25.070771 2.71781-39.720334-4.76057-50.272637l-6.59788-2.20125a57.381208 57.381208 0 0 0-3.079794 5.27713c-7.474467 18.47289-7.063567 55.283661 3.0524 94.865072l-0.001956-0.001957z" fill="currentColor"></path></svg>`
|
||||||
}[type];
|
}[type];
|
||||||
|
|||||||
8
src-tauri/src/scripts/markdown.export.js
vendored
8
src-tauri/src/scripts/markdown.export.js
vendored
@@ -1,5 +1,9 @@
|
|||||||
// *** Core Script - Markdown ***
|
// *** Core Script - Markdown ***
|
||||||
|
|
||||||
$(function() {
|
(function () {
|
||||||
console.log("markdown");
|
console.log("markdown");
|
||||||
});
|
const chatThread = $('main .items-center');
|
||||||
|
const chatBlocks = $(chatThread, '>div');
|
||||||
|
|
||||||
|
console.log('«8» /src/scripts/markdown.export.js ~> ', chatBlocks);
|
||||||
|
})(window);
|
||||||
1
src-tauri/src/vendors/turndown.js
vendored
Normal file
1
src-tauri/src/vendors/turndown.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user