fix: 服务端返回标题+正文,修复替换后标题丢失问题
- 423down-vip.js: 改为移除已有 meta/entry 和付费墙占位,插入服务端完整 HTML - 版本号 1.0.0 → 1.1.0
This commit is contained in:
+15
-12
@@ -8,7 +8,7 @@
|
||||
// @connect *.nite07.com
|
||||
// @grant GM_xmlhttpRequest
|
||||
// @run-at document-end
|
||||
// @version 1.0.0
|
||||
// @version 1.1.0
|
||||
// @license MIT
|
||||
// ==/UserScript==
|
||||
|
||||
@@ -33,22 +33,25 @@
|
||||
function replaceArticleHTML(articleID) {
|
||||
requestArticleHTML(articleID)
|
||||
.then((html) => {
|
||||
const articleContainer = document.querySelector(
|
||||
"div.content > div:first-child",
|
||||
);
|
||||
if (!articleContainer) {
|
||||
const contentDiv = document.querySelector("div.content");
|
||||
if (!contentDiv) {
|
||||
console.warn("[423down-proxy] 未找到正文容器,无法替换 HTML");
|
||||
return;
|
||||
}
|
||||
|
||||
let newDiv = articleContainer.cloneNode(false);
|
||||
let parentElem = articleContainer.parentElement;
|
||||
articleContainer.remove();
|
||||
// 移除已有的 meta(标题)和 entry(正文),避免重复
|
||||
contentDiv
|
||||
.querySelectorAll("div.meta, div.entry")
|
||||
.forEach((el) => el.remove());
|
||||
|
||||
newDiv.className = "entry";
|
||||
newDiv.style = "";
|
||||
newDiv.innerHTML = html;
|
||||
parentElem.prepend(newDiv);
|
||||
// 移除第一个子元素(付费墙占位 div,无 class)
|
||||
const firstChild = contentDiv.firstElementChild;
|
||||
if (firstChild && firstChild.tagName === "DIV" && !firstChild.className) {
|
||||
firstChild.remove();
|
||||
}
|
||||
|
||||
// 在 content 开头插入服务端返回的完整 HTML(含标题+正文)
|
||||
contentDiv.insertAdjacentHTML("afterbegin", html);
|
||||
console.info(`[423down-proxy] 已替换文章 ${articleID} 的正文 HTML`);
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
Reference in New Issue
Block a user