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