import { messageFormatting } from '/script.js'; function loadShowdown() { return new Promise((resolve, reject) => { if (window.showdown) { resolve(); return; } const script = document.createElement('script'); script.src = 'https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js'; script.onload = resolve; script.onerror = reject; document.head.appendChild(script); }); } export async function showContentModal(title, contentUrl) { try { await loadShowdown(); const markdownContent = await $.get(contentUrl); const converter = new showdown.Converter({ tables: true, strikethrough: true, ghCodeBlocks: true }); const htmlContent = converter.makeHtml(markdownContent); const dialogHtml = ` `; const dialogElement = $(dialogHtml).appendTo('body'); const closeDialog = () => { dialogElement[0].close(); dialogElement.remove(); }; dialogElement.find('.popup-button-ok').on('click', closeDialog); dialogElement[0].showModal(); } catch (error) { console.error(`[Amily-翰林院] 紧急报告:加载教程内容 [${title}] 时发生意外:`, error); toastr.error(`无法加载教程: ${error.message}`, "翰林院回报"); } } export function showHtmlModal(title, htmlContent, options = {}) { const { okText = '确认', cancelText = '取消', onOk, onCancel, onShow, showCancel = true, } = options; const buttonsHtml = ` ${showCancel ? `` : ''} `; const dialogHtml = ` `; const dialogElement = $(dialogHtml).appendTo('body'); const closeDialog = () => { dialogElement[0].close(); dialogElement.remove(); }; dialogElement.find('.popup-button-ok').on('click', () => { if (onOk) { const shouldClose = onOk(dialogElement); if (shouldClose !== false) { closeDialog(); } } else { closeDialog(); } }); if (showCancel) { dialogElement.find('.popup-button-cancel').on('click', () => { if (onCancel) { onCancel(); } closeDialog(); }); } dialogElement[0].showModal(); if (onShow) { onShow(dialogElement); } return dialogElement; } export function showSummaryModal(summaryText, callbacks) { const { onConfirm, onRegenerate, onCancel } = callbacks; const modalHtml = `
`; const dialogElement = showHtmlModal('预览与修订', modalHtml, { okText: '确认写入', cancelText: '取消写入', showCancel: true, onOk: (dialog) => { const editedText = dialog.find('textarea').val(); if (onConfirm) { onConfirm(editedText); } }, onCancel: () => { if (onCancel) { onCancel(); } } }); const regenerateButton = $(''); regenerateButton.on('click', () => { if (onRegenerate) { dialogElement[0].close(); onRegenerate(dialogElement); } }); dialogElement.find('.popup-controls').prepend(regenerateButton); }