`);
content = content.replace(/\r\n/g, "
\r\n");
if (content.includes("http")) {
content = content.replace(/(http[\w:/.?@#&=%]+)/g, (match, p1) => `
`);
}
content += `
`;
combinedVolumeText += content;
}
const pseudoVolumeXhr = {
bookInfo,
VolumeIndex: bookInfo.Text.findIndex((t) => t.vid === data.vid),
// 找到对应的卷索引
data: { ...data, Text: bookInfo.Text.find((t) => t.vid === data.vid) }
// 传递卷的Text对象
};
xhrChapterRequest.dealVolume(pseudoVolumeXhr, combinedVolumeText);
}
bookInfo.XHRManager.taskFinished(xhrChapterRequest, false);
} else {
throw new Error(`Status ${response.status}`);
}
} catch (error) {
bookInfo.logger.logError(`${failureMessage} 错误: ${error.message}`);
bookInfo.XHRManager.retryTask(xhrChapterRequest, failureMessage);
}
},
/**
* 对外暴露的接口,用于从App接口加载章节内容(通常用于版权受限页面)
* @param {object} bookInfo - 包含 aid, logger, refreshProgress 的对象
* @param {string} chapterId - 章节ID
* @param {HTMLElement} contentElement - 显示内容的DOM元素
* @param {Function} translateBodyFunc - 页面提供的翻译函数
*/
async fetchChapterForReading(bookInfo, chapterId, contentElement, translateBodyFunc) {
const langParam = this._getApiLanguageParam({ targetEncoding: _unsafeWindow.targetEncoding });
const requestBody = this._encryptRequestBody(`action=book&do=text&aid=${bookInfo.aid}&cid=${chapterId}&t=${langParam}`);
const url = `http://${APP_API_DOMAIN}${APP_API_PATH}`;
contentElement.innerHTML = "正在通过App接口加载内容,请稍候...";
try {
const response = await gmXmlHttpRequestAsync({
method: "POST",
url,
headers: { "content-type": "application/x-www-form-urlencoded;charset=utf-8" },
data: requestBody,
timeout: XHR_TIMEOUT_MS
});
if (response.status === 200) {
let rawText = response.responseText;
rawText = rawText.replace(/ {2}\S.*/, "");
rawText = rawText.replace(/\r\n/g, "