From e0cde606a812da7fc8e45b1376e7c233190ada88 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 22 Mar 2026 09:05:26 +0000 Subject: [PATCH 01/10] Initial plan From 0e4d8c5c5e199cf4631145b95888d13c52b3db77 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 22 Mar 2026 09:09:44 +0000 Subject: [PATCH 02/10] fix: include image links as markdown when copying solution/problem content Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com> Agent-Logs-Url: https://github.com/XMOJ-Script-dev/XMOJ-Script/sessions/dbcbbaed-e0e2-4aa7-959e-869a3b011a32 --- XMOJ.user.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/XMOJ.user.js b/XMOJ.user.js index 275ef481..1c4fda93 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -1039,6 +1039,23 @@ function replaceMarkdownImages(text, string) { return text.replace(/!\[.*?\]\(.*?\)/g, string); } +function GetMDText(element) { + let result = ''; + for (let node of element.childNodes) { + if (node.nodeType === Node.TEXT_NODE) { + result += node.textContent; + } else if (node.nodeName === 'IMG') { + let src = node.getAttribute('src'); + if (src) { + result += `![](${new URL(src, location.href).href})`; + } + } else { + result += GetMDText(node); + } + } + return result; +} + async function main() { try { if (location.href.startsWith('http://')) { @@ -2436,7 +2453,7 @@ async function main() { CopyMDButton.type = "button"; document.querySelectorAll(".cnt-row-head.title")[i].appendChild(CopyMDButton); CopyMDButton.addEventListener("click", () => { - GM_setClipboard(Temp[i].children[0].innerText.trim().replaceAll("\n\t", "\n").replaceAll("\n\n", "\n")); + GM_setClipboard(GetMDText(Temp[i].children[0]).trim().replaceAll("\n\t", "\n").replaceAll("\n\n", "\n")); CopyMDButton.innerText = "复制成功"; setTimeout(() => { CopyMDButton.innerText = "复制"; @@ -4464,7 +4481,7 @@ int main() CopyMDButton.type = "button"; document.querySelector("body > div > div.mt-3 > center > h2").appendChild(CopyMDButton); CopyMDButton.addEventListener("click", () => { - GM_setClipboard(ParsedDocument.querySelector("body > div > div > div").innerText.trim().replaceAll("\n\t", "\n").replaceAll("\n\n", "\n")); + GM_setClipboard(GetMDText(ParsedDocument.querySelector("body > div > div > div")).trim().replaceAll("\n\t", "\n").replaceAll("\n\n", "\n")); CopyMDButton.innerText = "复制成功"; setTimeout(() => { CopyMDButton.innerText = "复制"; From df7de3aea35313addf2d2b3a6702979c29bcdc3f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 22 Mar 2026 09:39:48 +0000 Subject: [PATCH 03/10] 3.3.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6c733c70..515cd2e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xmoj-script", - "version": "3.3.5", + "version": "3.3.6", "description": "an improvement script for xmoj.tech", "main": "AddonScript.js", "scripts": { From ead676a7430a17835c6bcd6f39299456692ca5d0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 22 Mar 2026 09:39:55 +0000 Subject: [PATCH 04/10] Update version info to 3.3.6 --- Update.json | 13 ++++++++++++- XMOJ.user.js | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Update.json b/Update.json index 00700095..6936997b 100644 --- a/Update.json +++ b/Update.json @@ -3477,6 +3477,17 @@ } ], "Notes": "No release notes were provided for this release." + }, + "3.3.6": { + "UpdateDate": 1774172389346, + "Prerelease": true, + "UpdateContents": [ + { + "PR": 955, + "Description": "[WIP] Fix issue where copied solutions do not include image links" + } + ], + "Notes": "No release notes were provided for this release." } } -} +} \ No newline at end of file diff --git a/XMOJ.user.js b/XMOJ.user.js index 1c4fda93..24284814 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -1,6 +1,6 @@ // ==UserScript== // @name XMOJ -// @version 3.3.5 +// @version 3.3.6 // @description XMOJ增强脚本 // @author @XMOJ-Script-dev, @langningchen and the community // @namespace https://github/langningchen From 00c3007e6d60593827d01c37b6be7d7aeabf0b6d Mon Sep 17 00:00:00 2001 From: Shan Wenxiao Date: Sun, 22 Mar 2026 17:40:36 +0800 Subject: [PATCH 05/10] Fix description for update PR 955 Signed-off-by: Shan Wenxiao --- Update.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Update.json b/Update.json index 6936997b..b15fadb0 100644 --- a/Update.json +++ b/Update.json @@ -3484,10 +3484,10 @@ "UpdateContents": [ { "PR": 955, - "Description": "[WIP] Fix issue where copied solutions do not include image links" + "Description": "Fix issue where copied solutions do not include image links" } ], "Notes": "No release notes were provided for this release." } } -} \ No newline at end of file +} From 6a88db6b178b7d1e2dd9a45cfaeab60ae9c666b7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 22 Mar 2026 09:41:00 +0000 Subject: [PATCH 06/10] Update time and description of 3.3.6 --- Update.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Update.json b/Update.json index b15fadb0..bd81ebbd 100644 --- a/Update.json +++ b/Update.json @@ -3479,15 +3479,15 @@ "Notes": "No release notes were provided for this release." }, "3.3.6": { - "UpdateDate": 1774172389346, + "UpdateDate": 1774172454729, "Prerelease": true, "UpdateContents": [ { "PR": 955, - "Description": "Fix issue where copied solutions do not include image links" + "Description": "fix: include image links as markdown when copying solution/problem content" } ], "Notes": "No release notes were provided for this release." } } -} +} \ No newline at end of file From 2e72cbfa59665802de414fb7ff3f5e86b948c165 Mon Sep 17 00:00:00 2001 From: Shan Wenxiao Date: Sun, 22 Mar 2026 17:42:10 +0800 Subject: [PATCH 07/10] fix lines Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Shan Wenxiao --- XMOJ.user.js | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/XMOJ.user.js b/XMOJ.user.js index 24284814..d66f8574 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -1041,18 +1041,56 @@ function replaceMarkdownImages(text, string) { function GetMDText(element) { let result = ''; - for (let node of element.childNodes) { + + function traverse(node) { if (node.nodeType === Node.TEXT_NODE) { result += node.textContent; - } else if (node.nodeName === 'IMG') { - let src = node.getAttribute('src'); + return; + } + + if (node.nodeType !== Node.ELEMENT_NODE) { + return; + } + + const tag = node.nodeName.toUpperCase(); + + // Preserve line breaks for
+ if (tag === 'BR') { + result += '\n'; + return; + } + + // Convert images to Markdown + if (tag === 'IMG') { + const src = node.getAttribute('src'); if (src) { result += `![](${new URL(src, location.href).href})`; } - } else { - result += GetMDText(node); + return; + } + + // Common block-level elements: add newlines around their content + const blockTags = new Set([ + 'P', 'DIV', 'SECTION', 'ARTICLE', 'HEADER', 'FOOTER', 'NAV', + 'UL', 'OL', 'LI', 'PRE', 'BLOCKQUOTE', + 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' + ]); + const isBlock = blockTags.has(tag); + + if (isBlock && !result.endsWith('\n')) { + result += '\n'; + } + + for (let child of node.childNodes) { + traverse(child); + } + + if (isBlock && !result.endsWith('\n')) { + result += '\n'; } } + + traverse(element); return result; } From 3b978d8f5c574857a651efb8a5cb02e3a98d302c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 22 Mar 2026 09:42:36 +0000 Subject: [PATCH 08/10] Update time and description of 3.3.6 --- Update.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Update.json b/Update.json index bd81ebbd..6b32e5e9 100644 --- a/Update.json +++ b/Update.json @@ -3479,7 +3479,7 @@ "Notes": "No release notes were provided for this release." }, "3.3.6": { - "UpdateDate": 1774172454729, + "UpdateDate": 1774172550170, "Prerelease": true, "UpdateContents": [ { From 294c920ed2356c6a272acad2fa1ae171e5264f32 Mon Sep 17 00:00:00 2001 From: Shan Wenxiao Date: Sun, 22 Mar 2026 17:43:32 +0800 Subject: [PATCH 09/10] fix src Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Shan Wenxiao --- XMOJ.user.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/XMOJ.user.js b/XMOJ.user.js index d66f8574..daa9a554 100644 --- a/XMOJ.user.js +++ b/XMOJ.user.js @@ -1064,7 +1064,13 @@ function GetMDText(element) { if (tag === 'IMG') { const src = node.getAttribute('src'); if (src) { - result += `![](${new URL(src, location.href).href})`; + let resolvedSrc = src; + try { + resolvedSrc = new URL(src, location.href).href; + } catch (e) { + // Fallback to the raw src if URL construction fails + } + result += `![](${resolvedSrc})`; } return; } From 7f71fa1525280309623863f3f72a0deb7b6c3c6c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 22 Mar 2026 09:44:00 +0000 Subject: [PATCH 10/10] Update time and description of 3.3.6 --- Update.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Update.json b/Update.json index 6b32e5e9..da8cdebc 100644 --- a/Update.json +++ b/Update.json @@ -3479,7 +3479,7 @@ "Notes": "No release notes were provided for this release." }, "3.3.6": { - "UpdateDate": 1774172550170, + "UpdateDate": 1774172635638, "Prerelease": true, "UpdateContents": [ {