Skip to content

Commit

Permalink
fix: 点赞每日重置,修复只能启动一次自动点赞
Browse files Browse the repository at this point in the history
  • Loading branch information
14790897 committed May 20, 2024
1 parent 22b118f commit 15529df
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ services:
# environment: # 设置环境变量(这里设置后不需要在.env文件中设置)
# USERNAMES: "用户名"
# PASSWORDS: "密码"
# WEBSITE: "https://linux.do" //目前支持 "https://meta.discourse.org","https://linux.do","https://meta.appinn.net","https://community.openai.com",
restart: unless-stopped # 容器退出时重启策略
51 changes: 48 additions & 3 deletions external.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// @author liuweiqing
// @match https://meta.discourse.org/*
// @match https://linux.do/*
// @match https://meta.appinn.net/*
// @match https://community.openai.com/
// @grant none
// @license MIT
// @icon https://www.google.com/s2/favicons?domain=linux.do
Expand All @@ -14,7 +16,12 @@
(function () {
("use strict");
// 定义可能的基本URL
const possibleBaseURLs = ["https://meta.discourse.org", "https://linux.do"];
const possibleBaseURLs = [
"https://meta.discourse.org",
"https://linux.do",
"https://meta.appinn.net",
"https://community.openai.com",
];

// 获取当前页面的URL
const currentURL = window.location.href;
Expand Down Expand Up @@ -224,13 +231,49 @@
);
}
}
// 从localStorage获取当前的点击计数,如果不存在则初始化为0
// 获取当前时间戳
const currentTime = Date.now();
// 获取存储的时间戳
const defaultTimestamp = new Date("1999-01-01T00:00:00Z").getTime(); //默认值为1999年
const storedTime = parseInt(
localStorage.getItem("clickCounterTimestamp") ||
defaultTimestamp.toString(),
10
);

// 获取当前的点击计数,如果不存在则初始化为0
let clickCounter = parseInt(localStorage.getItem("clickCounter") || "0", 10);
// 检查是否超过24小时(24小时 = 24 * 60 * 60 * 1000 毫秒)
if (currentTime - storedTime > 24 * 60 * 60 * 1000) {
// 超过24小时,清空点击计数器并更新时间戳
clickCounter = 0;
localStorage.setItem("clickCounter", "0");
localStorage.setItem("clickCounterTimestamp", currentTime.toString());
}

console.log(`Initial clickCounter: ${clickCounter}`);
function triggerClick(button) {
const event = new MouseEvent("click", {
bubbles: true,
cancelable: true,
view: window,
});
button.dispatchEvent(event);
}

function autoLike() {
console.log(`Initial clickCounter: ${clickCounter}`);
// 寻找所有的discourse-reactions-reaction-button
const buttons = document.querySelectorAll(
".discourse-reactions-reaction-button"
);
if (buttons.length === 0) {
console.error(
"No buttons found with the selector '.discourse-reactions-reaction-button'"
);
return;
}
console.log(`Found ${buttons.length} buttons.`); // 调试信息

// 逐个点击找到的按钮
buttons.forEach((button, index) => {
Expand All @@ -244,7 +287,7 @@
// 使用setTimeout来错开每次点击的时间,避免同时触发点击
autoLikeInterval = setTimeout(() => {
// 模拟点击
button.click();
triggerClick(button); // 使用自定义的触发点击方法
console.log(`Clicked like button ${index + 1}`);
clickCounter++; // 更新点击计数器
// 将新的点击计数存储到localStorage
Expand All @@ -253,6 +296,8 @@
if (clickCounter === 50) {
console.log("Reached 50 likes, setting the like variable to false.");
localStorage.setItem("autoLikeEnabled", "false"); // 使用localStorage存储点赞变量状态
} else {
console.log("clickCounter:", clickCounter);
}
}, index * 1000); // 这里的1000毫秒是两次点击之间的间隔,可以根据需要调整
});
Expand Down
42 changes: 40 additions & 2 deletions index_passage_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,49 @@
);
}
}
// 从localStorage获取当前的点击计数,如果不存在则初始化为0
// 获取当前时间戳
const currentTime = Date.now();
// 获取存储的时间戳
const defaultTimestamp = new Date("1999-01-01T00:00:00Z").getTime(); //默认值为1999年
const storedTime = parseInt(
localStorage.getItem("clickCounterTimestamp") ||
defaultTimestamp.toString(),
10
);

// 获取当前的点击计数,如果不存在则初始化为0
let clickCounter = parseInt(localStorage.getItem("clickCounter") || "0", 10);
// 检查是否超过24小时(24小时 = 24 * 60 * 60 * 1000 毫秒)
if (currentTime - storedTime > 24 * 60 * 60 * 1000) {
// 超过24小时,清空点击计数器并更新时间戳
clickCounter = 0;
localStorage.setItem("clickCounter", "0");
localStorage.setItem("clickCounterTimestamp", currentTime.toString());
}

console.log(`Initial clickCounter: ${clickCounter}`);
function triggerClick(button) {
const event = new MouseEvent("click", {
bubbles: true,
cancelable: true,
view: window,
});
button.dispatchEvent(event);
}

function autoLike() {
console.log(`Initial clickCounter: ${clickCounter}`);
// 寻找所有的discourse-reactions-reaction-button
const buttons = document.querySelectorAll(
".discourse-reactions-reaction-button"
);
if (buttons.length === 0) {
console.error(
"No buttons found with the selector '.discourse-reactions-reaction-button'"
);
return;
}
console.log(`Found ${buttons.length} buttons.`); // 调试信息

// 逐个点击找到的按钮
buttons.forEach((button, index) => {
Expand All @@ -251,7 +287,7 @@
// 使用setTimeout来错开每次点击的时间,避免同时触发点击
autoLikeInterval = setTimeout(() => {
// 模拟点击
button.click();
triggerClick(button); // 使用自定义的触发点击方法
console.log(`Clicked like button ${index + 1}`);
clickCounter++; // 更新点击计数器
// 将新的点击计数存储到localStorage
Expand All @@ -260,6 +296,8 @@
if (clickCounter === 50) {
console.log("Reached 50 likes, setting the like variable to false.");
localStorage.setItem("autoLikeEnabled", "false"); // 使用localStorage存储点赞变量状态
} else {
console.log("clickCounter:", clickCounter);
}
}, index * 1000); // 这里的1000毫秒是两次点击之间的间隔,可以根据需要调整
});
Expand Down

0 comments on commit 15529df

Please sign in to comment.