"use strict";
|
const fs = require("fs");
|
const vm = require("vm");
|
const source = fs.readFileSync(process.argv[2], "utf8");
|
const fixtureCase = process.argv[3] || "new";
|
const profileUid = fixtureCase === "identity" ? "1" : "1420210197";
|
const profile = {href:`https://space.bilibili.com/${profileUid}`, textContent:fixtureCase === "identity" ? "其他用户" : "青枫浦上Q"};
|
const link = {href:"https://www.bilibili.com/opus/456"};
|
const time = {getAttribute: () => "2026-08-13T01:55:00Z"};
|
const body = {textContent:"fixture body"};
|
const card = {
|
tagName:"DIV",
|
textContent:"fixture body",
|
getAttribute:(name) => name === "data-dynamic-id" ? "456" : null,
|
querySelector:(selector) => selector.includes("/opus/") ? link : selector === "time" ? time : selector.includes("bili-rich-text") ? body : null,
|
querySelectorAll:() => []
|
};
|
const unparsed = {
|
tagName:"DIV",
|
textContent:"unparsed fixture body",
|
getAttribute:() => null,
|
querySelector:() => null,
|
querySelectorAll:() => []
|
};
|
const fixtureNodes = fixtureCase === "empty" ? [] : fixtureCase === "unparsed" ? [unparsed] : [card];
|
const document = {
|
readyState:"complete", visibilityState:"visible",
|
body:{innerText:`fixture body ${fixtureCase === "unparsed" ? "" : "已经到底了"}`},
|
title:"青枫浦上Q个人动态-青枫浦上Q动态记录-哔哩哔哩视频",
|
querySelectorAll:() => fixtureNodes,
|
querySelector:(selector) => selector.startsWith("a[href") ? profile : null
|
};
|
const context = {document, location:{href:"https://space.bilibili.com/1420210197/dynamic"}, URL, setTimeout};
|
vm.createContext(context);
|
vm.runInContext(source + "\nthis.extractor = projectInfoCollectVisibleDynamicNodes;", context);
|
context.extractor({page_internal_settle_timeout_ms:15000}).then((value) => process.stdout.write(JSON.stringify(value)));
|