Skip to content

Commit

Permalink
fix: 通过在主进程直接设置localstorage变量,避免单独设置
Browse files Browse the repository at this point in the history
  • Loading branch information
14790897 committed Sep 3, 2024
1 parent 5daba9d commit 99b6725
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions bypasscf.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ async function launchBrowserForUser(username, password) {

// 在每个新的文档加载时执行外部脚本
await page.evaluateOnNewDocument((...args) => {
localStorage.setItem("read", true);
localStorage.setItem("autoLikeEnabled", "true");
const [scriptToEval] = args;
eval(scriptToEval);
}, externalScript);
Expand Down
17 changes: 11 additions & 6 deletions bypasscf_likeUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,17 @@ async function launchBrowserForUser(username, password) {
const externalScript = fs.readFileSync(externalScriptPath, "utf8");

// 在每个新的文档加载时执行外部脚本
await page.evaluateOnNewDocument((...args) => {
const [specificUser, scriptToEval] = args;
localStorage.setItem("specificUser", specificUser);
console.log('当前点赞用户:', specificUser)
eval(scriptToEval);
},specificUser, externalScript);//变量必须从外部显示的传入, 因为在浏览器上下文它是读取不了的
await page.evaluateOnNewDocument(
(...args) => {
const [specificUser, scriptToEval] = args;
localStorage.setItem("read", true);
localStorage.setItem("specificUser", specificUser);
console.log("当前点赞用户:", specificUser);
eval(scriptToEval);
},
specificUser,
externalScript
); //变量必须从外部显示的传入, 因为在浏览器上下文它是读取不了的
// 添加一个监听器来监听每次页面加载完成的事件
page.on("load", async () => {
// await page.evaluate(externalScript); //因为这个是在页面加载好之后执行的,而脚本是在页面加载好时刻来判断是否要执行,由于已经加载好了,脚本就不会起作用
Expand Down

0 comments on commit 99b6725

Please sign in to comment.