From b9e48d9483b6ab0fe9fae19e1ca2a19f1ce404c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jim=20Liu=20=E5=AE=9D=E7=8E=89?= Date: Tue, 3 Feb 2026 11:06:41 -0600 Subject: [PATCH] fix(baoyu-post-to-wechat): fix placeholder matching to avoid WECHATIMGPH_1 matching WECHATIMGPH_10 --- .../scripts/wechat-article.ts | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/skills/baoyu-post-to-wechat/scripts/wechat-article.ts b/skills/baoyu-post-to-wechat/scripts/wechat-article.ts index 5e70825..f6f05d4 100644 --- a/skills/baoyu-post-to-wechat/scripts/wechat-article.ts +++ b/skills/baoyu-post-to-wechat/scripts/wechat-article.ts @@ -273,22 +273,31 @@ async function selectAndReplacePlaceholder(session: ChromeSession, placeholder: const editor = document.querySelector('.ProseMirror'); if (!editor) return false; + const placeholder = ${JSON.stringify(placeholder)}; const walker = document.createTreeWalker(editor, NodeFilter.SHOW_TEXT, null, false); let node; while ((node = walker.nextNode())) { const text = node.textContent || ''; - const idx = text.indexOf(${JSON.stringify(placeholder)}); - if (idx !== -1) { - node.parentElement.scrollIntoView({ behavior: 'smooth', block: 'center' }); + let searchStart = 0; + let idx; + // Search for exact match (not prefix of longer placeholder like XIMGPH_1 in XIMGPH_10) + while ((idx = text.indexOf(placeholder, searchStart)) !== -1) { + const afterIdx = idx + placeholder.length; + const charAfter = text[afterIdx]; + // Exact match if next char is not a digit + if (charAfter === undefined || !/\\d/.test(charAfter)) { + node.parentElement.scrollIntoView({ behavior: 'smooth', block: 'center' }); - const range = document.createRange(); - range.setStart(node, idx); - range.setEnd(node, idx + ${placeholder.length}); - const sel = window.getSelection(); - sel.removeAllRanges(); - sel.addRange(range); - return true; + const range = document.createRange(); + range.setStart(node, idx); + range.setEnd(node, idx + placeholder.length); + const sel = window.getSelection(); + sel.removeAllRanges(); + sel.addRange(range); + return true; + } + searchStart = afterIdx; } } return false;