From ded3cc75f09fd5b3a6eb313545d87cc9887b935a Mon Sep 17 00:00:00 2001 From: YSYHZ <108722788+YSYHZ@users.noreply.github.com> Date: Mon, 10 Mar 2025 21:53:47 +0800 Subject: [PATCH] Update journal.js Add HTML tag escape --- src/chrome/content/journal.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/chrome/content/journal.js b/src/chrome/content/journal.js index e398fd9..cc2ab8d 100644 --- a/src/chrome/content/journal.js +++ b/src/chrome/content/journal.js @@ -15,6 +15,26 @@ Journal = { return newAuthorList; }, + decodeHTMLEntities(text) { + if (typeof text !== 'string' || !text) return text; + + // 实体映射表(可扩展) + const entities = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + ''': "'", + ' ': ' ', + // 添加其他常见实体... + }; + + // 一次性替换所有已知实体 + return text.replace(/&(amp|lt|gt|quot|#39|nbsp);/g, (match, entity) => { + return entities[match] || match; + }); + }, + generateDate (date) { if (!date) { return null; @@ -59,14 +79,14 @@ Journal = { } }) .then(dataJson => { - var Title = Utilities.safeGetFromJson(dataJson, ["title"]); + var Title = this.decodeHTMLEntities(Utilities.safeGetFromJson(dataJson, ["title"])); var Authors = this.generateAuthors(Utilities.safeGetFromJson(dataJson, ["author"])); - var Publication = Utilities.safeGetFromJson(dataJson, ["container-title"]); + var Publication = this.decodeHTMLEntities(Utilities.safeGetFromJson(dataJson, ["container-title"])); var Volume = Utilities.safeGetFromJson(dataJson, ["volume"]); var Issue = Utilities.safeGetFromJson(dataJson, ["issue"]); var Pages = Utilities.safeGetFromJson(dataJson, ["page"]); var PublishDate = this.generateDate(Utilities.safeGetFromJson(dataJson, ["published", "date-parts"])); - var JournalAbbr = Utilities.safeGetFromJson(dataJson, ["container-title-short"]); + var JournalAbbr = this.decodeHTMLEntities(Utilities.safeGetFromJson(dataJson, ["container-title-short"])); var Language = Utilities.safeGetFromJson(dataJson, ["language"]); return { "Title": Title ? Title : "", @@ -100,4 +120,4 @@ Journal = { await item.saveTx(); return 0; } -} \ No newline at end of file +}