From cde65352d0d7b1aad3497b80b31f32e59ffc5111 Mon Sep 17 00:00:00 2001 From: whocares <76169229+troicc@users.noreply.github.com> Date: Fri, 31 Jul 2026 22:06:50 +0800 Subject: [PATCH 1/8] Allow sending normalized documents to local X2RED --- manifest.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 64d4262..48a5f05 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "__MSG_appName__", - "version": "0.12.0", + "version": "0.13.0", "description": "__MSG_appDescription__", "minimum_chrome_version": "109", "permissions": [ @@ -17,7 +17,9 @@ "https://twitter.com/*", "https://www.twitter.com/*", "https://pbs.twimg.com/*", - "https://abs.twimg.com/*" + "https://abs.twimg.com/*", + "http://127.0.0.1:8787/*", + "http://localhost:8787/*" ], "background": { "service_worker": "background.js" From 65b88549531a429c9c50a85849aabc568cfa115c Mon Sep 17 00:00:00 2001 From: whocares <76169229+troicc@users.noreply.github.com> Date: Fri, 31 Jul 2026 22:07:29 +0800 Subject: [PATCH 2/8] Add Send to X2RED action in Article preview --- preview.html | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/preview.html b/preview.html index dc5f544..6f9b103 100644 --- a/preview.html +++ b/preview.html @@ -12,19 +12,15 @@
X
X2PDF - Structured Article preview v0.12 + Structured Article preview v0.13
- - - - - +
@@ -67,26 +60,22 @@ Direct PDF export Chrome lays out and downloads the PDF in the background. The system print dialog is not opened. + -
-
- - - + From f1c8a3e0e6b3d325d5eac211342bab2610c18c5d Mon Sep 17 00:00:00 2001 From: whocares <76169229+troicc@users.noreply.github.com> Date: Fri, 31 Jul 2026 22:08:09 +0800 Subject: [PATCH 3/8] Load X2RED bridge controller --- preview.html | 104 +++++---------------------------------------------- 1 file changed, 9 insertions(+), 95 deletions(-) diff --git a/preview.html b/preview.html index 6f9b103..a0390b2 100644 --- a/preview.html +++ b/preview.html @@ -8,44 +8,12 @@
-
-
X
-
- X2PDF - Structured Article preview v0.13 -
-
- +
X
X2PDFStructured Article preview v0.13
- - - - + + + + @@ -55,68 +23,14 @@
- - + -
- - + +
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + From af8d4158ff8c849eedb44915b9932a7ae26aa9f6 Mon Sep 17 00:00:00 2001 From: whocares <76169229+troicc@users.noreply.github.com> Date: Fri, 31 Jul 2026 22:08:33 +0800 Subject: [PATCH 4/8] Send normalized X documents to local X2RED --- x2red-bridge.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 x2red-bridge.js diff --git a/x2red-bridge.js b/x2red-bridge.js new file mode 100644 index 0000000..74d1855 --- /dev/null +++ b/x2red-bridge.js @@ -0,0 +1,52 @@ +(() => { + "use strict"; + + const ENDPOINT = "http://127.0.0.1:8787/api/integrations/x2pdf/documents"; + const button = document.getElementById("sendX2REDButton"); + const status = document.getElementById("x2redStatus"); + const title = document.getElementById("documentTitle"); + if (!button) return; + + const label = (key, fallback) => { + try { return globalThis.XPDFI18n?.t(key) || fallback; } catch { return fallback; } + }; + + button.addEventListener("click", async () => { + button.disabled = true; + const original = button.textContent; + button.textContent = label("sendingToX2RED", "Sending…"); + if (status) status.textContent = label("x2redConnecting", "Connecting to local X2RED…"); + try { + const stored = await chrome.storage.session.get("pendingXDocument"); + const documentValue = structuredClone(stored.pendingXDocument || null); + if (!documentValue || !Array.isArray(documentValue.blocks)) { + throw new Error(label("x2redNoDocument", "No normalized document is available.")); + } + if (title?.textContent?.trim()) { + documentValue.metadata = { ...(documentValue.metadata || {}), title: title.textContent.trim() }; + } + const response = await fetch(ENDPOINT, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ document: documentValue }), + }); + const payload = await response.json().catch(() => ({})); + if (!response.ok) throw new Error(payload.detail || `X2RED HTTP ${response.status}`); + if (status) { + status.textContent = label("x2redSent", "Sent to X2RED") + ` · ${payload.block_count || 0} blocks`; + } + button.textContent = label("sentToX2RED", "Sent ✓"); + setTimeout(() => { + button.textContent = original; + button.disabled = false; + }, 1800); + window.open(`http://127.0.0.1:8787/?source=${encodeURIComponent(payload.source_id)}`, "_blank", "noopener"); + return; + } catch (error) { + const message = error instanceof Error ? error.message : String(error); + if (status) status.textContent = `${label("x2redUnavailable", "X2RED unavailable")}: ${message}`; + button.textContent = label("sendToX2RED", "Send to X2RED"); + } + button.disabled = false; + }); +})(); From 9d4b7b0ffe4b06a756ca050cc3b896211f21f450 Mon Sep 17 00:00:00 2001 From: whocares <76169229+troicc@users.noreply.github.com> Date: Fri, 31 Jul 2026 22:20:04 +0800 Subject: [PATCH 5/8] Use localized fallback labels for X2RED bridge --- x2red-bridge.js | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/x2red-bridge.js b/x2red-bridge.js index 74d1855..c82c0a4 100644 --- a/x2red-bridge.js +++ b/x2red-bridge.js @@ -7,20 +7,28 @@ const title = document.getElementById("documentTitle"); if (!button) return; - const label = (key, fallback) => { - try { return globalThis.XPDFI18n?.t(key) || fallback; } catch { return fallback; } + const isZh = (globalThis.XPDFI18n?.locale || navigator.language || "en").startsWith("zh"); + const copy = { + send: isZh ? "发送到 X2RED" : "Send to X2RED", + sending: isZh ? "发送中…" : "Sending…", + connecting: isZh ? "正在连接本机 X2RED…" : "Connecting to local X2RED…", + noDocument: isZh ? "没有可发送的标准化长文。" : "No normalized document is available.", + sent: isZh ? "已发送到 X2RED" : "Sent to X2RED", + sentButton: isZh ? "已发送 ✓" : "Sent ✓", + unavailable: isZh ? "X2RED 不可用" : "X2RED unavailable", + blocks: isZh ? "个内容块" : "blocks", }; + button.textContent = copy.send; button.addEventListener("click", async () => { button.disabled = true; - const original = button.textContent; - button.textContent = label("sendingToX2RED", "Sending…"); - if (status) status.textContent = label("x2redConnecting", "Connecting to local X2RED…"); + button.textContent = copy.sending; + if (status) status.textContent = copy.connecting; try { const stored = await chrome.storage.session.get("pendingXDocument"); const documentValue = structuredClone(stored.pendingXDocument || null); if (!documentValue || !Array.isArray(documentValue.blocks)) { - throw new Error(label("x2redNoDocument", "No normalized document is available.")); + throw new Error(copy.noDocument); } if (title?.textContent?.trim()) { documentValue.metadata = { ...(documentValue.metadata || {}), title: title.textContent.trim() }; @@ -32,20 +40,22 @@ }); const payload = await response.json().catch(() => ({})); if (!response.ok) throw new Error(payload.detail || `X2RED HTTP ${response.status}`); - if (status) { - status.textContent = label("x2redSent", "Sent to X2RED") + ` · ${payload.block_count || 0} blocks`; - } - button.textContent = label("sentToX2RED", "Sent ✓"); + if (status) status.textContent = `${copy.sent} · ${payload.block_count || 0} ${copy.blocks}`; + button.textContent = copy.sentButton; setTimeout(() => { - button.textContent = original; + button.textContent = copy.send; button.disabled = false; }, 1800); - window.open(`http://127.0.0.1:8787/?source=${encodeURIComponent(payload.source_id)}`, "_blank", "noopener"); + window.open( + `http://127.0.0.1:8787/?source=${encodeURIComponent(payload.source_id)}`, + "_blank", + "noopener", + ); return; } catch (error) { const message = error instanceof Error ? error.message : String(error); - if (status) status.textContent = `${label("x2redUnavailable", "X2RED unavailable")}: ${message}`; - button.textContent = label("sendToX2RED", "Send to X2RED"); + if (status) status.textContent = `${copy.unavailable}: ${message}`; + button.textContent = copy.send; } button.disabled = false; }); From 3b54ff23f959f0542089136ec4909e3de41607d0 Mon Sep 17 00:00:00 2001 From: whocares <76169229+troicc@users.noreply.github.com> Date: Fri, 31 Jul 2026 22:24:24 +0800 Subject: [PATCH 6/8] Package X2RED bridge with extension runtime --- scripts/package_extension.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/package_extension.py b/scripts/package_extension.py index 2014689..cb318ed 100755 --- a/scripts/package_extension.py +++ b/scripts/package_extension.py @@ -11,7 +11,7 @@ runtime_files = [ "manifest.json", "background.js", "extractor.js", "structured-parser.js", - "preview.html", "preview.css", "preview.js", "i18n.js", + "preview.html", "preview.css", "preview.js", "x2red-bridge.js", "i18n.js", "code-highlighter.js", "formula-renderer.js", "mathjax-config.js", "clipboard-utils.js", "LICENSE", "THIRD_PARTY_NOTICES.md" ] From bb681b46dec06e849e227b7f67821acff85d0fcb Mon Sep 17 00:00:00 2001 From: whocares <76169229+troicc@users.noreply.github.com> Date: Fri, 31 Jul 2026 22:24:45 +0800 Subject: [PATCH 7/8] Validate X2RED bridge runtime file --- scripts/check-repository.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/check-repository.js b/scripts/check-repository.js index f5e2e85..7d69ba3 100644 --- a/scripts/check-repository.js +++ b/scripts/check-repository.js @@ -22,6 +22,7 @@ const referenced = [ "preview.html", "preview.css", "preview.js", + "x2red-bridge.js", "background.js", "extractor.js", "structured-parser.js", From 3c3d1b3b1e4fe831f38761cdb7f1dbd709d56e14 Mon Sep 17 00:00:00 2001 From: whocares <76169229+troicc@users.noreply.github.com> Date: Fri, 31 Jul 2026 22:24:59 +0800 Subject: [PATCH 8/8] Bump X2PDF bridge release to 0.13.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4458212..a62f70b 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "x2pdf", - "version": "0.12.0", + "version": "0.13.0", "private": true, - "description": "A local-first Chromium extension that exports X Articles and posts to structured, searchable PDFs.", + "description": "A local-first Chromium extension that exports X Articles and posts to structured, searchable PDFs and X2RED.", "license": "MIT", "repository": { "type": "git",