mirror of
https://github.com/lencx/ChatGPT.git
synced 2024-10-01 01:06:13 -04:00
fix: layout
This commit is contained in:
parent
c8a79ea0bb
commit
ca1949f502
28
scripts/cmd.js
vendored
28
scripts/cmd.js
vendored
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @name cmd.js
|
||||
* @version 0.1.1
|
||||
* @version 0.1.2
|
||||
* @url https://github.com/lencx/ChatGPT/tree/main/scripts/cmd.js
|
||||
*/
|
||||
|
||||
@ -122,6 +122,32 @@ function cmdInit() {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (mutation.type === 'childList' && mutation.removedNodes.length) {
|
||||
for (let node of mutation.removedNodes) {
|
||||
if (node.querySelector('form textarea')) {
|
||||
initDom();
|
||||
cmdTip();
|
||||
(async function () {
|
||||
async function platform() {
|
||||
return invoke('platform', {
|
||||
__tauriModule: 'Os',
|
||||
message: { cmd: 'platform' },
|
||||
});
|
||||
}
|
||||
if (__TAURI_METADATA__.__currentWindow.label !== 'tray') {
|
||||
const _platform = await platform();
|
||||
const chatConf = (await invoke('get_app_conf')) || {};
|
||||
if (/darwin/.test(_platform) && !chatConf.titlebar) {
|
||||
const nav = document.body.querySelector('nav');
|
||||
if (nav) {
|
||||
nav.style.paddingTop = '25px';
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).observe(document.body, {
|
||||
childList: true,
|
||||
|
41
scripts/core.js
vendored
41
scripts/core.js
vendored
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @name core.js
|
||||
* @version 0.1.1
|
||||
* @version 0.1.2
|
||||
* @url https://github.com/lencx/ChatGPT/tree/main/scripts/core.js
|
||||
*/
|
||||
|
||||
@ -84,40 +84,13 @@ function coreInit() {
|
||||
document.body.appendChild(topDom);
|
||||
|
||||
if (window.location.host === 'chat.openai.com') {
|
||||
const nav = document.body.querySelector('nav');
|
||||
const top = topDom.clientHeight + 5;
|
||||
if (nav) {
|
||||
const currentPaddingTop = parseInt(
|
||||
window
|
||||
.getComputedStyle(document.querySelector('nav'), null)
|
||||
.getPropertyValue('padding-top')
|
||||
.replace('px', ''),
|
||||
10,
|
||||
);
|
||||
const navStyleDom = document.createElement('style');
|
||||
navStyleDom.innerHTML = `nav{
|
||||
padding-top:${currentPaddingTop + top}px !important
|
||||
const intervalId = setInterval(function () {
|
||||
const nav = document.body.querySelector('nav');
|
||||
if (nav) {
|
||||
nav.style.paddingTop = '25px';
|
||||
clearInterval(intervalId);
|
||||
}
|
||||
button[aria-label="Show sidebar"]{
|
||||
margin-top:${top}px !important
|
||||
}
|
||||
`;
|
||||
document.head.appendChild(navStyleDom);
|
||||
} else {
|
||||
const navStyleDom = document.createElement('style');
|
||||
navStyleDom.innerHTML = `nav{
|
||||
padding-top:${top}px !important
|
||||
}
|
||||
button[aria-label="Show sidebar"]{
|
||||
margin-top:${top}px !important
|
||||
}
|
||||
`;
|
||||
document.head.appendChild(navStyleDom);
|
||||
const main = document.querySelector('main');
|
||||
if (main && main.parentElement.children.length > 1) {
|
||||
main.parentElement.children[0].style.paddingTop = top + 'px';
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
topDom.addEventListener('mousedown', () => invoke('drag_window'));
|
||||
|
311
scripts/export.js
vendored
311
scripts/export.js
vendored
@ -1,164 +1,17 @@
|
||||
/**
|
||||
* @name export.js
|
||||
* @version 0.1.4
|
||||
* @version 0.1.5
|
||||
* @url https://github.com/lencx/ChatGPT/tree/main/scripts/export.js
|
||||
*/
|
||||
|
||||
async function exportInit() {
|
||||
if (window.location.pathname === '/auth/login') return;
|
||||
const buttonOuterHTMLFallback = `<button class="btn flex justify-center gap-2 btn-neutral">Try Again</button>`;
|
||||
removeButtons();
|
||||
if (window.buttonsInterval) {
|
||||
clearInterval(window.buttonsInterval);
|
||||
}
|
||||
if (window.innerWidth < 767) return;
|
||||
|
||||
const chatConf = (await invoke('get_app_conf')) || {};
|
||||
window.buttonsInterval = setInterval(() => {
|
||||
const formArea = document.querySelector('form>div>div');
|
||||
const textarea = formArea.querySelector('div textarea');
|
||||
const textareaDiv = formArea.querySelector('div div.absolute');
|
||||
const hasBtn = formArea.querySelector('div button');
|
||||
const actionsArea = document.querySelector('form>div>div>div');
|
||||
|
||||
if (!formArea || !actionsArea || (textarea && textareaDiv) || !hasBtn) {
|
||||
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();
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
const SELECTOR = 'main div.group';
|
||||
const USER_INPUT_SELECTOR = 'div.empty\\:hidden';
|
||||
const Format = {
|
||||
PNG: 'png',
|
||||
PDF: 'pdf',
|
||||
};
|
||||
|
||||
function shouldRemoveButtons() {
|
||||
if (document.querySelector('form .text-2xl')) {
|
||||
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 !/download-/.test(button.id);
|
||||
});
|
||||
|
||||
const stopBtn = buttons?.[0]?.innerText;
|
||||
|
||||
if (/Stop generating/gi.test(stopBtn)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
buttons.length === 2 &&
|
||||
(/Regenerate response/gi.test(stopBtn) || buttons[1].innerText === '')
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
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 downloadPngButton = document.getElementById('download-png-button');
|
||||
const downloadPdfButton = document.getElementById('download-pdf-button');
|
||||
const downloadMdButton = document.getElementById('download-markdown-button');
|
||||
const refreshButton = document.getElementById('refresh-page-button');
|
||||
if (downloadPngButton) {
|
||||
downloadPngButton.remove();
|
||||
}
|
||||
if (downloadPdfButton) {
|
||||
downloadPdfButton.remove();
|
||||
}
|
||||
if (downloadPdfButton) {
|
||||
downloadMdButton.remove();
|
||||
}
|
||||
if (refreshButton) {
|
||||
refreshButton.remove();
|
||||
}
|
||||
}
|
||||
|
||||
function addActionsButtons(actionsArea, TryAgainButton) {
|
||||
// Export markdown
|
||||
const exportMd = TryAgainButton.cloneNode(true);
|
||||
exportMd.id = 'download-markdown-button';
|
||||
exportMd.setAttribute('share-ext', 'true');
|
||||
exportMd.title = 'Export Markdown';
|
||||
|
||||
exportMd.innerHTML = setIcon('md');
|
||||
exportMd.onclick = () => {
|
||||
exportMarkdown();
|
||||
};
|
||||
actionsArea.appendChild(exportMd);
|
||||
|
||||
// Generate PNG
|
||||
const downloadPngButton = TryAgainButton.cloneNode(true);
|
||||
downloadPngButton.id = 'download-png-button';
|
||||
downloadPngButton.setAttribute('share-ext', 'true');
|
||||
downloadPngButton.title = 'Generate PNG';
|
||||
downloadPngButton.innerHTML = setIcon('png');
|
||||
downloadPngButton.onclick = () => {
|
||||
downloadThread();
|
||||
};
|
||||
actionsArea.appendChild(downloadPngButton);
|
||||
|
||||
// Generate PDF
|
||||
const downloadPdfButton = TryAgainButton.cloneNode(true);
|
||||
downloadPdfButton.id = 'download-pdf-button';
|
||||
downloadPdfButton.setAttribute('share-ext', 'true');
|
||||
downloadPdfButton.title = 'Download PDF';
|
||||
downloadPdfButton.innerHTML = setIcon('pdf');
|
||||
downloadPdfButton.onclick = () => {
|
||||
downloadThread({ as: Format.PDF });
|
||||
};
|
||||
actionsArea.appendChild(downloadPdfButton);
|
||||
|
||||
// Refresh
|
||||
const refreshButton = TryAgainButton.cloneNode(true);
|
||||
refreshButton.id = 'refresh-page-button';
|
||||
refreshButton.title = 'Refresh the Page';
|
||||
refreshButton.innerHTML = setIcon('refresh');
|
||||
refreshButton.onclick = () => {
|
||||
window.location.reload();
|
||||
};
|
||||
actionsArea.appendChild(refreshButton);
|
||||
}
|
||||
|
||||
const SELECTOR = 'main div.group';
|
||||
const USER_INPUT_SELECTOR = 'div.empty\\:hidden';
|
||||
|
||||
function processNode(node, replaceInUserInput = false) {
|
||||
let j = node.cloneNode(true);
|
||||
if (/dark\:bg-gray-800/.test(node.getAttribute('class'))) {
|
||||
@ -168,13 +21,14 @@ async function exportInit() {
|
||||
if (replaceInUserInput) {
|
||||
const userInputBlocks = j.querySelectorAll(USER_INPUT_SELECTOR);
|
||||
userInputBlocks.forEach((block) => {
|
||||
|
||||
//For quicker testing use js fiddle: https://jsfiddle.net/xtraeme/x34ao9jp/13/
|
||||
block.innerHTML = block.innerHTML
|
||||
.replace(/ |\u00A0/g, ' ') //Replace =C2=A0 (nbsp non-breaking space) /w breaking-space
|
||||
.replace(/\t/g, ' ') // Replace tab with 4 non-breaking spaces
|
||||
.replace(/^ +/gm, function(match) { return ' '.repeat(match.length); }) //Add =C2=A0
|
||||
.replace(/\n/g, '<br/>');
|
||||
//For quicker testing use js fiddle: https://jsfiddle.net/xtraeme/x34ao9jp/13/
|
||||
block.innerHTML = block.innerHTML
|
||||
.replace(/ |\u00A0/g, ' ') //Replace =C2=A0 (nbsp non-breaking space) /w breaking-space
|
||||
.replace(/\t/g, ' ') // Replace tab with 4 non-breaking spaces
|
||||
.replace(/^ +/gm, function (match) {
|
||||
return ' '.repeat(match.length);
|
||||
}) //Add =C2=A0
|
||||
.replace(/\n/g, '<br/>');
|
||||
});
|
||||
}
|
||||
|
||||
@ -191,24 +45,17 @@ async function exportInit() {
|
||||
// '''Python import package
|
||||
//so we remove whitespace after <code> tags and add <br/> and/or \n
|
||||
allBlocks.forEach((block) => {
|
||||
block.innerHTML = block.innerHTML
|
||||
.replace(/(<code[^>]*>)\s*/g, '$1<br\\/>\n'); // Add \n or <br/> after opening code tag
|
||||
block.innerHTML = block.innerHTML.replace(/(<code[^>]*>)\s*/g, '$1<br\\/>\n'); // Add \n or <br/> after opening code tag
|
||||
});
|
||||
|
||||
const content = nodes.map(i => processNode(i)).join('');
|
||||
const updatedContent = nodes.map(i => processNode(i, true)).join('');
|
||||
const updatedContent = nodes.map((i) => processNode(i, true)).join('');
|
||||
|
||||
const data = ExportMD.turndown(updatedContent);
|
||||
const { id, filename } = getName();
|
||||
final_filename = `${filename}`; //`${filename}_${id}`;
|
||||
|
||||
//await invoke('save_file', { name: `notes/${final_filename}_raw.txt`, content: content });
|
||||
await invoke('save_file', { name: `notes/${id}.md`, content: data });
|
||||
await invoke('download_list', { pathname: 'chat.notes.json', final_filename, id, dir: 'notes' });
|
||||
//await invoke('download_list', { pathname: 'chat.notes.json', final_filename, final_filename, dir: 'notes' });
|
||||
await invoke('download_list', { pathname: 'chat.notes.json', filename, id, dir: 'notes' });
|
||||
}
|
||||
|
||||
|
||||
async function downloadThread({ as = Format.PNG } = {}) {
|
||||
const { startLoading, stopLoading } = new window.__LoadingMask('Exporting in progress...');
|
||||
startLoading();
|
||||
@ -329,15 +176,6 @@ async function exportInit() {
|
||||
}
|
||||
}
|
||||
|
||||
function setIcon(type) {
|
||||
return {
|
||||
png: `<svg class="chatappico png" viewBox="0 0 1024 1024"><path d="M264.258065 338.580645c16.780387 0 31.281548-6.144 43.536516-18.398968 12.254968-12.221935 18.398968-26.756129 18.398967-43.536516s-6.144-31.281548-18.398967-43.536516A59.524129 59.524129 0 0 0 264.258065 214.709677c-16.780387 0-31.281548 6.144-43.536517 18.398968-12.254968 12.221935-18.398968 26.756129-18.398967 43.536516s6.144 31.281548 18.398967 43.536516c12.221935 12.254968 26.756129 18.398968 43.536517 18.398968zM883.612903 28.903226H140.387097a119.345548 119.345548 0 0 0-87.568516 36.302451A119.345548 119.345548 0 0 0 16.516129 152.774194v743.225806c0 34.188387 12.089806 63.388903 36.302452 87.568516a119.345548 119.345548 0 0 0 87.568516 36.302452h743.225806a119.345548 119.345548 0 0 0 87.568516-36.302452A119.345548 119.345548 0 0 0 1007.483871 896v-743.225806a119.345548 119.345548 0 0 0-36.302452-87.568517A119.345548 119.345548 0 0 0 883.612903 28.903226zM264.258065 152.774194c34.188387 0 63.388903 12.089806 87.568516 36.302451a119.345548 119.345548 0 0 1 36.302451 87.568516 119.345548 119.345548 0 0 1-36.302451 87.568516A119.345548 119.345548 0 0 1 264.258065 400.516129a119.345548 119.345548 0 0 1-87.568517-36.302452A119.345548 119.345548 0 0 1 140.387097 276.645161c0-34.188387 12.089806-63.388903 36.302451-87.568516A119.345548 119.345548 0 0 1 264.258065 152.774194zM140.387097 957.935484c-16.780387 0-31.281548-6.144-43.536516-18.398968a59.524129 59.524129 0 0 1-18.398968-43.536516v-29.035355l245.793032-220.655484L635.870968 957.935484h-495.483871z m805.16129-61.935484c0 16.780387-6.144 31.281548-18.398968 43.536516-12.221935 12.254968-26.756129 18.398968-43.536516 18.398968h-159.677935l-228.385033-231.291871L759.741935 462.451613l185.806452 185.806452v247.741935z" 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>`,
|
||||
md: `<svg class="chatappico md" viewBox="0 0 1024 1024"><path d="M128 128h768a42.666667 42.666667 0 0 1 42.666667 42.666667v682.666666a42.666667 42.666667 0 0 1-42.666667 42.666667H128a42.666667 42.666667 0 0 1-42.666667-42.666667V170.666667a42.666667 42.666667 0 0 1 42.666667-42.666667z m170.666667 533.333333v-170.666666l85.333333 85.333333 85.333333-85.333333v170.666666h85.333334v-298.666666h-85.333334l-85.333333 85.333333-85.333333-85.333333H213.333333v298.666666h85.333334z m469.333333-128v-170.666666h-85.333333v170.666666h-85.333334l128 128 128-128h-85.333333z" fill="currentColor"></path></svg>`,
|
||||
refresh: `<svg class="chatappico refresh" viewBox="0 0 1024 1024"><path d="M512 63.5C264.3 63.5 63.5 264.3 63.5 512S264.3 960.5 512 960.5 960.5 759.7 960.5 512 759.7 63.5 512 63.5zM198 509.6h87.6c0-136.3 102.3-243.4 233.7-238.5 43.8 0 82.8 14.6 121.7 34.1L597.2 349c-24.4-9.8-53.6-19.5-82.8-19.5-92.5 0-170.4 77.9-170.4 180.1h87.6L314.8 631.3 198 509.6z m540.3-0.1c0 131.4-102.2 243.4-228.8 243.4-43.8 0-82.8-19.4-121.7-38.9l43.8-43.8c24.4 9.8 53.6 19.5 82.8 19.5 92.5 0 170.4-77.9 170.4-180.1h-92.5l116.9-121.7L826 509.5h-87.7z" fill="currentColor"></path></svg>`,
|
||||
}[type];
|
||||
}
|
||||
|
||||
function formatDateTime() {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
@ -350,36 +188,119 @@ async function exportInit() {
|
||||
return formattedDateTime;
|
||||
}
|
||||
|
||||
function sanitizeFilename(filename) {
|
||||
if (!filename || filename === '') return '';
|
||||
// function sanitizeFilename(filename) {
|
||||
// if (!filename || filename === '') return '';
|
||||
|
||||
// Replace whitespaces with underscores
|
||||
let sanitizedFilename = filename.replace(/\s/g, '_');
|
||||
// // Replace whitespaces with underscores
|
||||
// let sanitizedFilename = filename.replace(/\s/g, '_');
|
||||
|
||||
// Replace invalid filename characters with #
|
||||
const invalidCharsRegex = /[<>:"/\\|?*\x00-\x1F]/g;
|
||||
sanitizedFilename = sanitizedFilename.replace(invalidCharsRegex, '#');
|
||||
// // Replace invalid filename characters with #
|
||||
// const invalidCharsRegex = /[<>:"/\\|?*\x00-\x1F]/g;
|
||||
// sanitizedFilename = sanitizedFilename.replace(invalidCharsRegex, '#');
|
||||
|
||||
// Check for filenames ending with period or space (Windows)
|
||||
if (sanitizedFilename && /[\s.]$/.test(sanitizedFilename)) {
|
||||
sanitizedFilename = sanitizedFilename.slice(0, -1) + '#';
|
||||
}
|
||||
//console.log(sanitizedFilename);
|
||||
return sanitizedFilename;
|
||||
// // Check for filenames ending with period or space (Windows)
|
||||
// if (sanitizedFilename && /[\s.]$/.test(sanitizedFilename)) {
|
||||
// sanitizedFilename = sanitizedFilename.slice(0, -1) + '#';
|
||||
// }
|
||||
// //console.log(sanitizedFilename);
|
||||
// return sanitizedFilename;
|
||||
// }
|
||||
|
||||
function btnInit() {
|
||||
const intervalId = setInterval(function () {
|
||||
const navActionArea = document.querySelector('nav .border-t > div');
|
||||
const addArea = document.querySelector('#chatgpt-nav-action-area');
|
||||
if (!navActionArea || addArea) return;
|
||||
const cloneNode = document.createElement('div');
|
||||
cloneNode.id = 'chatgpt-nav-action-area';
|
||||
cloneNode.classList = `${navActionArea.className} border-b border-white/20 mb-2 pb-2`;
|
||||
cloneNode.appendChild(addBtn('png'));
|
||||
cloneNode.appendChild(addBtn('pdf'));
|
||||
cloneNode.appendChild(addBtn('md'));
|
||||
cloneNode.appendChild(addBtn('refresh'));
|
||||
navActionArea.parentNode.insertBefore(cloneNode, navActionArea);
|
||||
clearInterval(intervalId);
|
||||
|
||||
function debounce(func, wait) {
|
||||
let timeout;
|
||||
return function () {
|
||||
const context = this;
|
||||
const args = arguments;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
func.apply(context, args);
|
||||
}, wait);
|
||||
};
|
||||
}
|
||||
const target = document.querySelector('nav');
|
||||
const debouncedFunction = debounce(function () {
|
||||
btnInit();
|
||||
}, 300);
|
||||
const observer = new MutationObserver(debouncedFunction);
|
||||
const config = { attributes: true, childList: true, characterData: true, subtree: true };
|
||||
observer.observe(target, config);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function addBtn(type) {
|
||||
const btn = document.createElement('button');
|
||||
btn.className = `btn dark:text-gray-500 hover:dark:text-gray-300`;
|
||||
btn.title = {
|
||||
png: 'Export PNG',
|
||||
pdf: 'Export PDF',
|
||||
md: 'Export Markdown',
|
||||
refresh: 'Refresh the Page',
|
||||
}[type];
|
||||
btn.innerHTML = setIcon(type);
|
||||
btn.onclick = () => {
|
||||
const content = document.querySelector('main .group');
|
||||
if (!content && type !== 'refresh') {
|
||||
alert('Please open a thread first.');
|
||||
return;
|
||||
}
|
||||
switch (type) {
|
||||
case 'png':
|
||||
downloadThread();
|
||||
break;
|
||||
case 'pdf':
|
||||
downloadThread({ as: 'pdf' });
|
||||
break;
|
||||
case 'md':
|
||||
exportMarkdown();
|
||||
break;
|
||||
case 'refresh':
|
||||
window.location.reload();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
return btn;
|
||||
}
|
||||
|
||||
function setIcon(type) {
|
||||
return {
|
||||
png: `<svg class="chatappico png" viewBox="0 0 1024 1024"><path d="M264.258065 338.580645c16.780387 0 31.281548-6.144 43.536516-18.398968 12.254968-12.221935 18.398968-26.756129 18.398967-43.536516s-6.144-31.281548-18.398967-43.536516A59.524129 59.524129 0 0 0 264.258065 214.709677c-16.780387 0-31.281548 6.144-43.536517 18.398968-12.254968 12.221935-18.398968 26.756129-18.398967 43.536516s6.144 31.281548 18.398967 43.536516c12.221935 12.254968 26.756129 18.398968 43.536517 18.398968zM883.612903 28.903226H140.387097a119.345548 119.345548 0 0 0-87.568516 36.302451A119.345548 119.345548 0 0 0 16.516129 152.774194v743.225806c0 34.188387 12.089806 63.388903 36.302452 87.568516a119.345548 119.345548 0 0 0 87.568516 36.302452h743.225806a119.345548 119.345548 0 0 0 87.568516-36.302452A119.345548 119.345548 0 0 0 1007.483871 896v-743.225806a119.345548 119.345548 0 0 0-36.302452-87.568517A119.345548 119.345548 0 0 0 883.612903 28.903226zM264.258065 152.774194c34.188387 0 63.388903 12.089806 87.568516 36.302451a119.345548 119.345548 0 0 1 36.302451 87.568516 119.345548 119.345548 0 0 1-36.302451 87.568516A119.345548 119.345548 0 0 1 264.258065 400.516129a119.345548 119.345548 0 0 1-87.568517-36.302452A119.345548 119.345548 0 0 1 140.387097 276.645161c0-34.188387 12.089806-63.388903 36.302451-87.568516A119.345548 119.345548 0 0 1 264.258065 152.774194zM140.387097 957.935484c-16.780387 0-31.281548-6.144-43.536516-18.398968a59.524129 59.524129 0 0 1-18.398968-43.536516v-29.035355l245.793032-220.655484L635.870968 957.935484h-495.483871z m805.16129-61.935484c0 16.780387-6.144 31.281548-18.398968 43.536516-12.221935 12.254968-26.756129 18.398968-43.536516 18.398968h-159.677935l-228.385033-231.291871L759.741935 462.451613l185.806452 185.806452v247.741935z" 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>`,
|
||||
md: `<svg class="chatappico md" viewBox="0 0 1024 1024"><path d="M128 128h768a42.666667 42.666667 0 0 1 42.666667 42.666667v682.666666a42.666667 42.666667 0 0 1-42.666667 42.666667H128a42.666667 42.666667 0 0 1-42.666667-42.666667V170.666667a42.666667 42.666667 0 0 1 42.666667-42.666667z m170.666667 533.333333v-170.666666l85.333333 85.333333 85.333333-85.333333v170.666666h85.333334v-298.666666h-85.333334l-85.333333 85.333333-85.333333-85.333333H213.333333v298.666666h85.333334z m469.333333-128v-170.666666h-85.333333v170.666666h-85.333334l128 128 128-128h-85.333333z" fill="currentColor"></path></svg>`,
|
||||
refresh: `<svg class="chatappico refresh" viewBox="0 0 1024 1024"><path d="M512 63.5C264.3 63.5 63.5 264.3 63.5 512S264.3 960.5 512 960.5 960.5 759.7 960.5 512 759.7 63.5 512 63.5zM198 509.6h87.6c0-136.3 102.3-243.4 233.7-238.5 43.8 0 82.8 14.6 121.7 34.1L597.2 349c-24.4-9.8-53.6-19.5-82.8-19.5-92.5 0-170.4 77.9-170.4 180.1h87.6L314.8 631.3 198 509.6z m540.3-0.1c0 131.4-102.2 243.4-228.8 243.4-43.8 0-82.8-19.4-121.7-38.9l43.8-43.8c24.4 9.8 53.6 19.5 82.8 19.5 92.5 0 170.4-77.9 170.4-180.1h-92.5l116.9-121.7L826 509.5h-87.7z" fill="currentColor"></path></svg>`,
|
||||
}[type];
|
||||
}
|
||||
|
||||
function getName() {
|
||||
const id = window.crypto.getRandomValues(new Uint32Array(1))[0].toString(36);
|
||||
const name =
|
||||
document.querySelector('nav .overflow-y-auto a.hover\\:bg-gray-800')?.innerText?.trim() || '';
|
||||
clean_name = sanitizeFilename(name);
|
||||
return { filename: name ? name : id,
|
||||
id,
|
||||
pathname: 'chat.download.json' };
|
||||
// clean_name = sanitizeFilename(name);
|
||||
return {
|
||||
id,
|
||||
filename: name ? name : id,
|
||||
pathname: 'chat.download.json',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('resize', exportInit);
|
||||
btnInit();
|
||||
}
|
||||
|
||||
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
||||
exportInit();
|
||||
|
@ -10,11 +10,11 @@
|
||||
},
|
||||
{
|
||||
"name": "cmd.js",
|
||||
"version": "0.1.1"
|
||||
"version": "0.1.2"
|
||||
},
|
||||
{
|
||||
"name": "core.js",
|
||||
"version": "0.1.1"
|
||||
"version": "0.1.2"
|
||||
},
|
||||
{
|
||||
"name": "dalle2.js",
|
||||
@ -22,7 +22,7 @@
|
||||
},
|
||||
{
|
||||
"name": "export.js",
|
||||
"version": "0.1.4"
|
||||
"version": "0.1.5"
|
||||
},
|
||||
{
|
||||
"name": "markdown.export.js",
|
||||
|
@ -26,7 +26,7 @@ dark-light = "1.0.0"
|
||||
wry = "0.*"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tokio = { version = "1.23.0", features = ["macros"] }
|
||||
tauri = { version = "1.3.0", features = ["devtools", "fs-create-dir", "fs-exists", "fs-read-dir", "fs-read-file", "fs-remove-dir", "fs-remove-file", "fs-write-file", "global-shortcut", "global-shortcut-all", "os-all", "path-all", "process-all", "shell-all", "shell-open-api", "system-tray", "updater"] }
|
||||
tauri = { version = "1.3.0", features = ["devtools", "dialog-all", "fs-create-dir", "fs-exists", "fs-read-dir", "fs-read-file", "fs-remove-dir", "fs-remove-file", "fs-write-file", "global-shortcut", "global-shortcut-all", "os-all", "path-all", "process-all", "shell-all", "shell-open-api", "system-tray", "updater"] }
|
||||
tauri-plugin-positioner = { git = "https://github.com/lencx/tauri-plugins-workspace", features = ["system-tray"] }
|
||||
tauri-plugin-log = { git = "https://github.com/lencx/tauri-plugins-workspace", branch = "dev", features = ["colored"] }
|
||||
tauri-plugin-autostart = { git = "https://github.com/lencx/tauri-plugins-workspace", branch = "dev" }
|
||||
|
@ -38,6 +38,9 @@
|
||||
"os": {
|
||||
"all": true
|
||||
},
|
||||
"dialog": {
|
||||
"all": true
|
||||
},
|
||||
"process": {
|
||||
"all": true,
|
||||
"exit": true,
|
||||
|
Loading…
Reference in New Issue
Block a user