From 335d3e33ba4ed1376cefcee77aaacaa43c7825f3 Mon Sep 17 00:00:00 2001 From: lencx Date: Sun, 8 Jan 2023 12:28:54 +0800 Subject: [PATCH] chore: add jq --- src-tauri/src/app/setup.rs | 20 +- src-tauri/src/app/window.rs | 12 +- src-tauri/src/scripts/cmd.js | 271 ++++++++++++++++++++++ src-tauri/src/scripts/core.js | 94 ++++++++ src-tauri/src/scripts/dalle2.js | 31 +++ src-tauri/src/scripts/export.js | 278 +++++++++++++++++++++++ src-tauri/src/scripts/markdown.export.js | 5 + src-tauri/src/scripts/popup.core.js | 74 ++++++ src-tauri/src/vendors/jq.js | 2 + 9 files changed, 774 insertions(+), 13 deletions(-) create mode 100644 src-tauri/src/scripts/cmd.js create mode 100644 src-tauri/src/scripts/core.js create mode 100644 src-tauri/src/scripts/dalle2.js create mode 100644 src-tauri/src/scripts/export.js create mode 100644 src-tauri/src/scripts/markdown.export.js create mode 100644 src-tauri/src/scripts/popup.core.js create mode 100644 src-tauri/src/vendors/jq.js diff --git a/src-tauri/src/app/setup.rs b/src-tauri/src/app/setup.rs index ca3c0c4..3e4c8e4 100644 --- a/src-tauri/src/app/setup.rs +++ b/src-tauri/src/app/setup.rs @@ -61,14 +61,16 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box .always_on_top(chat_conf.stay_on_top) .title_bar_style(ChatConfJson::titlebar()) .initialization_script(&utils::user_script()) + .initialization_script(include_str!("../vendors/jq.js")) .initialization_script(include_str!("../vendors/floating-ui-core.js")) .initialization_script(include_str!("../vendors/floating-ui-dom.js")) .initialization_script(include_str!("../vendors/html2canvas.js")) .initialization_script(include_str!("../vendors/jspdf.js")) - .initialization_script(include_str!("../assets/core.js")) - .initialization_script(include_str!("../assets/popup.core.js")) - .initialization_script(include_str!("../assets/export.js")) - .initialization_script(include_str!("../assets/cmd.js")) + .initialization_script(include_str!("../scripts/core.js")) + .initialization_script(include_str!("../scripts/popup.core.js")) + .initialization_script(include_str!("../scripts/export.js")) + .initialization_script(include_str!("../scripts/markdown.export.js")) + .initialization_script(include_str!("../scripts/cmd.js")) .user_agent(&chat_conf.ua_window) .build() .unwrap(); @@ -82,14 +84,16 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box .theme(theme) .always_on_top(chat_conf.stay_on_top) .initialization_script(&utils::user_script()) + .initialization_script(include_str!("../vendors/jq.js")) .initialization_script(include_str!("../vendors/floating-ui-core.js")) .initialization_script(include_str!("../vendors/floating-ui-dom.js")) .initialization_script(include_str!("../vendors/html2canvas.js")) .initialization_script(include_str!("../vendors/jspdf.js")) - .initialization_script(include_str!("../assets/core.js")) - .initialization_script(include_str!("../assets/popup.core.js")) - .initialization_script(include_str!("../assets/export.js")) - .initialization_script(include_str!("../assets/cmd.js")) + .initialization_script(include_str!("../scripts/core.js")) + .initialization_script(include_str!("../scripts/popup.core.js")) + .initialization_script(include_str!("../scripts/export.js")) + .initialization_script(include_str!("../scripts/markdown.export.js")) + .initialization_script(include_str!("../scripts/cmd.js")) .user_agent(&chat_conf.ua_window) .build() .unwrap(); diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs index 58ca282..81ee7f6 100644 --- a/src-tauri/src/app/window.rs +++ b/src-tauri/src/app/window.rs @@ -18,11 +18,12 @@ pub fn tray_window(handle: &tauri::AppHandle) { .always_on_top(true) .theme(theme) .initialization_script(&utils::user_script()) + .initialization_script(include_str!("../vendors/jq.js")) .initialization_script(include_str!("../vendors/floating-ui-core.js")) .initialization_script(include_str!("../vendors/floating-ui-dom.js")) - .initialization_script(include_str!("../assets/core.js")) - .initialization_script(include_str!("../assets/cmd.js")) - .initialization_script(include_str!("../assets/popup.core.js")) + .initialization_script(include_str!("../scripts/core.js")) + .initialization_script(include_str!("../scripts/cmd.js")) + .initialization_script(include_str!("../scripts/popup.core.js")) .user_agent(&chat_conf.ua_tray) .build() .unwrap() @@ -73,9 +74,10 @@ pub fn dalle2_window( .inner_size(800.0, 600.0) .always_on_top(false) .theme(theme) - .initialization_script(include_str!("../assets/core.js")) + .initialization_script(include_str!("../vendors/jq.js")) + .initialization_script(include_str!("../scripts/core.js")) .initialization_script(&query) - .initialization_script(include_str!("../assets/dalle2.js")) + .initialization_script(include_str!("../scripts/dalle2.js")) .build() .unwrap(); }); diff --git a/src-tauri/src/scripts/cmd.js b/src-tauri/src/scripts/cmd.js new file mode 100644 index 0000000..5ddc12a --- /dev/null +++ b/src-tauri/src/scripts/cmd.js @@ -0,0 +1,271 @@ +// *** Core Script - CMD *** + +$(function() { + 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) => `
/${v.cmd}${v.act}
`; + const renderList = (v) => { + modelDom.innerHTML = `
${v.map(itemDom).join('')}
`; + 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); +} diff --git a/src-tauri/src/scripts/core.js b/src-tauri/src/scripts/core.js new file mode 100644 index 0000000..ad8ed4b --- /dev/null +++ b/src-tauri/src/scripts/core.js @@ -0,0 +1,94 @@ +// *** 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 () { + 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() }); + } +}); \ No newline at end of file diff --git a/src-tauri/src/scripts/dalle2.js b/src-tauri/src/scripts/dalle2.js new file mode 100644 index 0000000..1b77067 --- /dev/null +++ b/src-tauri/src/scripts/dalle2.js @@ -0,0 +1,31 @@ +// *** Core Script - DALL·E 2 *** + +$(function () { + 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) +}) \ No newline at end of file diff --git a/src-tauri/src/scripts/export.js b/src-tauri/src/scripts/export.js new file mode 100644 index 0000000..b6633d2 --- /dev/null +++ b/src-tauri/src/scripts/export.js @@ -0,0 +1,278 @@ +// *** Core Script - Export *** +// @ref: https://github.com/liady/ChatGPT-pdf + +const buttonOuterHTMLFallback = ``; + +$(async function () { + 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(""); +} + +function setIcon(type) { + return { + link: ``, + png: ``, + pdf: `` + }[type]; +} diff --git a/src-tauri/src/scripts/markdown.export.js b/src-tauri/src/scripts/markdown.export.js new file mode 100644 index 0000000..eb46ac2 --- /dev/null +++ b/src-tauri/src/scripts/markdown.export.js @@ -0,0 +1,5 @@ +// *** Core Script - Markdown *** + +$(function() { + console.log("markdown"); +}); \ No newline at end of file diff --git a/src-tauri/src/scripts/popup.core.js b/src-tauri/src/scripts/popup.core.js new file mode 100644 index 0000000..953420a --- /dev/null +++ b/src-tauri/src/scripts/popup.core.js @@ -0,0 +1,74 @@ +// *** Core Script - DALL·E 2 Core *** + +$(async function () { + 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`, + }); + }); + } + }); +}) \ No newline at end of file diff --git a/src-tauri/src/vendors/jq.js b/src-tauri/src/vendors/jq.js new file mode 100644 index 0000000..b04d0fc --- /dev/null +++ b/src-tauri/src/vendors/jq.js @@ -0,0 +1,2 @@ +/*! jQuery v3.6.3 | (c) OpenJS Foundation and other contributors | jquery.org/license */ +!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(C,e){"use strict";var t=[],r=Object.getPrototypeOf,s=t.slice,g=t.flat?function(e){return t.flat.call(e)}:function(e){return t.concat.apply([],e)},u=t.push,i=t.indexOf,n={},o=n.toString,y=n.hasOwnProperty,a=y.toString,l=a.call(Object),v={},m=function(e){return"function"==typeof e&&"number"!=typeof e.nodeType&&"function"!=typeof e.item},x=function(e){return null!=e&&e===e.window},S=C.document,c={type:!0,src:!0,nonce:!0,noModule:!0};function b(e,t,n){var r,i,o=(n=n||S).createElement("script");if(o.text=e,t)for(r in c)(i=t[r]||t.getAttribute&&t.getAttribute(r))&&o.setAttribute(r,i);n.head.appendChild(o).parentNode.removeChild(o)}function w(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?n[o.call(e)]||"object":typeof e}var f="3.6.3",E=function(e,t){return new E.fn.init(e,t)};function p(e){var t=!!e&&"length"in e&&e.length,n=w(e);return!m(e)&&!x(e)&&("array"===n||0===t||"number"==typeof t&&0+~]|"+M+")"+M+"*"),U=new RegExp(M+"|>"),X=new RegExp(F),V=new RegExp("^"+I+"$"),G={ID:new RegExp("^#("+I+")"),CLASS:new RegExp("^\\.("+I+")"),TAG:new RegExp("^("+I+"|[*])"),ATTR:new RegExp("^"+W),PSEUDO:new RegExp("^"+F),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+R+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/HTML$/i,Q=/^(?:input|select|textarea|button)$/i,J=/^h\d$/i,K=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ee=/[+~]/,te=new RegExp("\\\\[\\da-fA-F]{1,6}"+M+"?|\\\\([^\\r\\n\\f])","g"),ne=function(e,t){var n="0x"+e.slice(1)-65536;return t||(n<0?String.fromCharCode(n+65536):String.fromCharCode(n>>10|55296,1023&n|56320))},re=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,ie=function(e,t){return t?"\0"===e?"\ufffd":e.slice(0,-1)+"\\"+e.charCodeAt(e.length-1).toString(16)+" ":"\\"+e},oe=function(){T()},ae=be(function(e){return!0===e.disabled&&"fieldset"===e.nodeName.toLowerCase()},{dir:"parentNode",next:"legend"});try{H.apply(t=O.call(p.childNodes),p.childNodes),t[p.childNodes.length].nodeType}catch(e){H={apply:t.length?function(e,t){L.apply(e,O.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function se(t,e,n,r){var i,o,a,s,u,l,c,f=e&&e.ownerDocument,p=e?e.nodeType:9;if(n=n||[],"string"!=typeof t||!t||1!==p&&9!==p&&11!==p)return n;if(!r&&(T(e),e=e||C,S)){if(11!==p&&(u=Z.exec(t)))if(i=u[1]){if(9===p){if(!(a=e.getElementById(i)))return n;if(a.id===i)return n.push(a),n}else if(f&&(a=f.getElementById(i))&&v(e,a)&&a.id===i)return n.push(a),n}else{if(u[2])return H.apply(n,e.getElementsByTagName(t)),n;if((i=u[3])&&d.getElementsByClassName&&e.getElementsByClassName)return H.apply(n,e.getElementsByClassName(i)),n}if(d.qsa&&!N[t+" "]&&(!y||!y.test(t))&&(1!==p||"object"!==e.nodeName.toLowerCase())){if(c=t,f=e,1===p&&(U.test(t)||z.test(t))){(f=ee.test(t)&&ve(e.parentNode)||e)===e&&d.scope||((s=e.getAttribute("id"))?s=s.replace(re,ie):e.setAttribute("id",s=E)),o=(l=h(t)).length;while(o--)l[o]=(s?"#"+s:":scope")+" "+xe(l[o]);c=l.join(",")}try{if(d.cssSupportsSelector&&!CSS.supports("selector(:is("+c+"))"))throw new Error;return H.apply(n,f.querySelectorAll(c)),n}catch(e){N(t,!0)}finally{s===E&&e.removeAttribute("id")}}}return g(t.replace(B,"$1"),e,n,r)}function ue(){var r=[];return function e(t,n){return r.push(t+" ")>b.cacheLength&&delete e[r.shift()],e[t+" "]=n}}function le(e){return e[E]=!0,e}function ce(e){var t=C.createElement("fieldset");try{return!!e(t)}catch(e){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function fe(e,t){var n=e.split("|"),r=n.length;while(r--)b.attrHandle[n[r]]=t}function pe(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&e.sourceIndex-t.sourceIndex;if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function de(t){return function(e){return"input"===e.nodeName.toLowerCase()&&e.type===t}}function he(n){return function(e){var t=e.nodeName.toLowerCase();return("input"===t||"button"===t)&&e.type===n}}function ge(t){return function(e){return"form"in e?e.parentNode&&!1===e.disabled?"label"in e?"label"in e.parentNode?e.parentNode.disabled===t:e.disabled===t:e.isDisabled===t||e.isDisabled!==!t&&ae(e)===t:e.disabled===t:"label"in e&&e.disabled===t}}function ye(a){return le(function(o){return o=+o,le(function(e,t){var n,r=a([],e.length,o),i=r.length;while(i--)e[n=r[i]]&&(e[n]=!(t[n]=e[n]))})})}function ve(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}for(e in d=se.support={},i=se.isXML=function(e){var t=e&&e.namespaceURI,n=e&&(e.ownerDocument||e).documentElement;return!Y.test(t||n&&n.nodeName||"HTML")},T=se.setDocument=function(e){var t,n,r=e?e.ownerDocument||e:p;return r!=C&&9===r.nodeType&&r.documentElement&&(a=(C=r).documentElement,S=!i(C),p!=C&&(n=C.defaultView)&&n.top!==n&&(n.addEventListener?n.addEventListener("unload",oe,!1):n.attachEvent&&n.attachEvent("onunload",oe)),d.scope=ce(function(e){return a.appendChild(e).appendChild(C.createElement("div")),"undefined"!=typeof e.querySelectorAll&&!e.querySelectorAll(":scope fieldset div").length}),d.cssSupportsSelector=ce(function(){return CSS.supports("selector(*)")&&C.querySelectorAll(":is(:jqfake)")&&!CSS.supports("selector(:is(*,:jqfake))")}),d.attributes=ce(function(e){return e.className="i",!e.getAttribute("className")}),d.getElementsByTagName=ce(function(e){return e.appendChild(C.createComment("")),!e.getElementsByTagName("*").length}),d.getElementsByClassName=K.test(C.getElementsByClassName),d.getById=ce(function(e){return a.appendChild(e).id=E,!C.getElementsByName||!C.getElementsByName(E).length}),d.getById?(b.filter.ID=function(e){var t=e.replace(te,ne);return function(e){return e.getAttribute("id")===t}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&S){var n=t.getElementById(e);return n?[n]:[]}}):(b.filter.ID=function(e){var n=e.replace(te,ne);return function(e){var t="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return t&&t.value===n}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&S){var n,r,i,o=t.getElementById(e);if(o){if((n=o.getAttributeNode("id"))&&n.value===e)return[o];i=t.getElementsByName(e),r=0;while(o=i[r++])if((n=o.getAttributeNode("id"))&&n.value===e)return[o]}return[]}}),b.find.TAG=d.getElementsByTagName?function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e):d.qsa?t.querySelectorAll(e):void 0}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},b.find.CLASS=d.getElementsByClassName&&function(e,t){if("undefined"!=typeof t.getElementsByClassName&&S)return t.getElementsByClassName(e)},s=[],y=[],(d.qsa=K.test(C.querySelectorAll))&&(ce(function(e){var t;a.appendChild(e).innerHTML="",e.querySelectorAll("[msallowcapture^='']").length&&y.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll("[selected]").length||y.push("\\["+M+"*(?:value|"+R+")"),e.querySelectorAll("[id~="+E+"-]").length||y.push("~="),(t=C.createElement("input")).setAttribute("name",""),e.appendChild(t),e.querySelectorAll("[name='']").length||y.push("\\["+M+"*name"+M+"*="+M+"*(?:''|\"\")"),e.querySelectorAll(":checked").length||y.push(":checked"),e.querySelectorAll("a#"+E+"+*").length||y.push(".#.+[+~]"),e.querySelectorAll("\\\f"),y.push("[\\r\\n\\f]")}),ce(function(e){e.innerHTML="";var t=C.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("name","D"),e.querySelectorAll("[name=d]").length&&y.push("name"+M+"*[*^$|!~]?="),2!==e.querySelectorAll(":enabled").length&&y.push(":enabled",":disabled"),a.appendChild(e).disabled=!0,2!==e.querySelectorAll(":disabled").length&&y.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),y.push(",.*:")})),(d.matchesSelector=K.test(c=a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.oMatchesSelector||a.msMatchesSelector))&&ce(function(e){d.disconnectedMatch=c.call(e,"*"),c.call(e,"[s!='']:x"),s.push("!=",F)}),d.cssSupportsSelector||y.push(":has"),y=y.length&&new RegExp(y.join("|")),s=s.length&&new RegExp(s.join("|")),t=K.test(a.compareDocumentPosition),v=t||K.test(a.contains)?function(e,t){var n=9===e.nodeType&&e.documentElement||e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},j=t?function(e,t){if(e===t)return l=!0,0;var n=!e.compareDocumentPosition-!t.compareDocumentPosition;return n||(1&(n=(e.ownerDocument||e)==(t.ownerDocument||t)?e.compareDocumentPosition(t):1)||!d.sortDetached&&t.compareDocumentPosition(e)===n?e==C||e.ownerDocument==p&&v(p,e)?-1:t==C||t.ownerDocument==p&&v(p,t)?1:u?P(u,e)-P(u,t):0:4&n?-1:1)}:function(e,t){if(e===t)return l=!0,0;var n,r=0,i=e.parentNode,o=t.parentNode,a=[e],s=[t];if(!i||!o)return e==C?-1:t==C?1:i?-1:o?1:u?P(u,e)-P(u,t):0;if(i===o)return pe(e,t);n=e;while(n=n.parentNode)a.unshift(n);n=t;while(n=n.parentNode)s.unshift(n);while(a[r]===s[r])r++;return r?pe(a[r],s[r]):a[r]==p?-1:s[r]==p?1:0}),C},se.matches=function(e,t){return se(e,null,null,t)},se.matchesSelector=function(e,t){if(T(e),d.matchesSelector&&S&&!N[t+" "]&&(!s||!s.test(t))&&(!y||!y.test(t)))try{var n=c.call(e,t);if(n||d.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(e){N(t,!0)}return 0":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(te,ne),e[3]=(e[3]||e[4]||e[5]||"").replace(te,ne),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||se.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&se.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return G.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&X.test(n)&&(t=h(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(te,ne).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=m[e+" "];return t||(t=new RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&m(e,function(e){return t.test("string"==typeof e.className&&e.className||"undefined"!=typeof e.getAttribute&&e.getAttribute("class")||"")})},ATTR:function(n,r,i){return function(e){var t=se.attr(e,n);return null==t?"!="===r:!r||(t+="","="===r?t===i:"!="===r?t!==i:"^="===r?i&&0===t.indexOf(i):"*="===r?i&&-1:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;function j(e,n,r){return m(n)?E.grep(e,function(e,t){return!!n.call(e,t,e)!==r}):n.nodeType?E.grep(e,function(e){return e===n!==r}):"string"!=typeof n?E.grep(e,function(e){return-1)[^>]*|#([\w-]+))$/;(E.fn.init=function(e,t,n){var r,i;if(!e)return this;if(n=n||D,"string"==typeof e){if(!(r="<"===e[0]&&">"===e[e.length-1]&&3<=e.length?[null,e,null]:q.exec(e))||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(t=t instanceof E?t[0]:t,E.merge(this,E.parseHTML(r[1],t&&t.nodeType?t.ownerDocument||t:S,!0)),N.test(r[1])&&E.isPlainObject(t))for(r in t)m(this[r])?this[r](t[r]):this.attr(r,t[r]);return this}return(i=S.getElementById(r[2]))&&(this[0]=i,this.length=1),this}return e.nodeType?(this[0]=e,this.length=1,this):m(e)?void 0!==n.ready?n.ready(e):e(E):E.makeArray(e,this)}).prototype=E.fn,D=E(S);var L=/^(?:parents|prev(?:Until|All))/,H={children:!0,contents:!0,next:!0,prev:!0};function O(e,t){while((e=e[t])&&1!==e.nodeType);return e}E.fn.extend({has:function(e){var t=E(e,this),n=t.length;return this.filter(function(){for(var e=0;e\x20\t\r\n\f]*)/i,he=/^$|^module$|\/(?:java|ecma)script/i;ce=S.createDocumentFragment().appendChild(S.createElement("div")),(fe=S.createElement("input")).setAttribute("type","radio"),fe.setAttribute("checked","checked"),fe.setAttribute("name","t"),ce.appendChild(fe),v.checkClone=ce.cloneNode(!0).cloneNode(!0).lastChild.checked,ce.innerHTML="",v.noCloneChecked=!!ce.cloneNode(!0).lastChild.defaultValue,ce.innerHTML="",v.option=!!ce.lastChild;var ge={thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};function ye(e,t){var n;return n="undefined"!=typeof e.getElementsByTagName?e.getElementsByTagName(t||"*"):"undefined"!=typeof e.querySelectorAll?e.querySelectorAll(t||"*"):[],void 0===t||t&&A(e,t)?E.merge([e],n):n}function ve(e,t){for(var n=0,r=e.length;n",""]);var me=/<|&#?\w+;/;function xe(e,t,n,r,i){for(var o,a,s,u,l,c,f=t.createDocumentFragment(),p=[],d=0,h=e.length;d\s*$/g;function je(e,t){return A(e,"table")&&A(11!==t.nodeType?t:t.firstChild,"tr")&&E(e).children("tbody")[0]||e}function De(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function qe(e){return"true/"===(e.type||"").slice(0,5)?e.type=e.type.slice(5):e.removeAttribute("type"),e}function Le(e,t){var n,r,i,o,a,s;if(1===t.nodeType){if(Y.hasData(e)&&(s=Y.get(e).events))for(i in Y.remove(t,"handle events"),s)for(n=0,r=s[i].length;n").attr(n.scriptAttrs||{}).prop({charset:n.scriptCharset,src:n.url}).on("load error",i=function(e){r.remove(),i=null,e&&t("error"===e.type?404:200,e.type)}),S.head.appendChild(r[0])},abort:function(){i&&i()}}});var Ut,Xt=[],Vt=/(=)\?(?=&|$)|\?\?/;E.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Xt.pop()||E.expando+"_"+Ct.guid++;return this[e]=!0,e}}),E.ajaxPrefilter("json jsonp",function(e,t,n){var r,i,o,a=!1!==e.jsonp&&(Vt.test(e.url)?"url":"string"==typeof e.data&&0===(e.contentType||"").indexOf("application/x-www-form-urlencoded")&&Vt.test(e.data)&&"data");if(a||"jsonp"===e.dataTypes[0])return r=e.jsonpCallback=m(e.jsonpCallback)?e.jsonpCallback():e.jsonpCallback,a?e[a]=e[a].replace(Vt,"$1"+r):!1!==e.jsonp&&(e.url+=(St.test(e.url)?"&":"?")+e.jsonp+"="+r),e.converters["script json"]=function(){return o||E.error(r+" was not called"),o[0]},e.dataTypes[0]="json",i=C[r],C[r]=function(){o=arguments},n.always(function(){void 0===i?E(C).removeProp(r):C[r]=i,e[r]&&(e.jsonpCallback=t.jsonpCallback,Xt.push(r)),o&&m(i)&&i(o[0]),o=i=void 0}),"script"}),v.createHTMLDocument=((Ut=S.implementation.createHTMLDocument("").body).innerHTML="
",2===Ut.childNodes.length),E.parseHTML=function(e,t,n){return"string"!=typeof e?[]:("boolean"==typeof t&&(n=t,t=!1),t||(v.createHTMLDocument?((r=(t=S.implementation.createHTMLDocument("")).createElement("base")).href=S.location.href,t.head.appendChild(r)):t=S),o=!n&&[],(i=N.exec(e))?[t.createElement(i[1])]:(i=xe([e],t,o),o&&o.length&&E(o).remove(),E.merge([],i.childNodes)));var r,i,o},E.fn.load=function(e,t,n){var r,i,o,a=this,s=e.indexOf(" ");return-1").append(E.parseHTML(e)).find(r):e)}).always(n&&function(e,t){a.each(function(){n.apply(this,o||[e.responseText,t,e])})}),this},E.expr.pseudos.animated=function(t){return E.grep(E.timers,function(e){return t===e.elem}).length},E.offset={setOffset:function(e,t,n){var r,i,o,a,s,u,l=E.css(e,"position"),c=E(e),f={};"static"===l&&(e.style.position="relative"),s=c.offset(),o=E.css(e,"top"),u=E.css(e,"left"),("absolute"===l||"fixed"===l)&&-1<(o+u).indexOf("auto")?(a=(r=c.position()).top,i=r.left):(a=parseFloat(o)||0,i=parseFloat(u)||0),m(t)&&(t=t.call(e,n,E.extend({},s))),null!=t.top&&(f.top=t.top-s.top+a),null!=t.left&&(f.left=t.left-s.left+i),"using"in t?t.using.call(e,f):c.css(f)}},E.fn.extend({offset:function(t){if(arguments.length)return void 0===t?this:this.each(function(e){E.offset.setOffset(this,t,e)});var e,n,r=this[0];return r?r.getClientRects().length?(e=r.getBoundingClientRect(),n=r.ownerDocument.defaultView,{top:e.top+n.pageYOffset,left:e.left+n.pageXOffset}):{top:0,left:0}:void 0},position:function(){if(this[0]){var e,t,n,r=this[0],i={top:0,left:0};if("fixed"===E.css(r,"position"))t=r.getBoundingClientRect();else{t=this.offset(),n=r.ownerDocument,e=r.offsetParent||n.documentElement;while(e&&(e===n.body||e===n.documentElement)&&"static"===E.css(e,"position"))e=e.parentNode;e&&e!==r&&1===e.nodeType&&((i=E(e).offset()).top+=E.css(e,"borderTopWidth",!0),i.left+=E.css(e,"borderLeftWidth",!0))}return{top:t.top-i.top-E.css(r,"marginTop",!0),left:t.left-i.left-E.css(r,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var e=this.offsetParent;while(e&&"static"===E.css(e,"position"))e=e.offsetParent;return e||re})}}),E.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(t,i){var o="pageYOffset"===i;E.fn[t]=function(e){return B(this,function(e,t,n){var r;if(x(e)?r=e:9===e.nodeType&&(r=e.defaultView),void 0===n)return r?r[i]:e[t];r?r.scrollTo(o?r.pageXOffset:n,o?n:r.pageYOffset):e[t]=n},t,e,arguments.length)}}),E.each(["top","left"],function(e,n){E.cssHooks[n]=_e(v.pixelPosition,function(e,t){if(t)return t=Be(e,n),Pe.test(t)?E(e).position()[n]+"px":t})}),E.each({Height:"height",Width:"width"},function(a,s){E.each({padding:"inner"+a,content:s,"":"outer"+a},function(r,o){E.fn[o]=function(e,t){var n=arguments.length&&(r||"boolean"!=typeof e),i=r||(!0===e||!0===t?"margin":"border");return B(this,function(e,t,n){var r;return x(e)?0===o.indexOf("outer")?e["inner"+a]:e.document.documentElement["client"+a]:9===e.nodeType?(r=e.documentElement,Math.max(e.body["scroll"+a],r["scroll"+a],e.body["offset"+a],r["offset"+a],r["client"+a])):void 0===n?E.css(e,t,i):E.style(e,t,n,i)},s,n?e:void 0,n)}})}),E.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){E.fn[t]=function(e){return this.on(t,e)}}),E.fn.extend({bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)},hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)}}),E.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(e,n){E.fn[n]=function(e,t){return 0