js脚本实现自动签到功能
1.首先在谷歌浏览器安装Tampermonkey插件
2.写入脚本
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http://*/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function() {
'use strict';
// user setting
const SIGN_IN_TIME = "09:00:00";
const SIGN_OUT_TIME = "18:00:00";
// code implementation
logTime("code start running");
const now = new Date();
const today = now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate();
var signInTime = +new Date(`${today} ${SIGN_IN_TIME}`);
logTime("signInTime", new Date(signInTime));
var signOutTime = +new Date(`${today} ${SIGN_OUT_TIME}`);
logTime("signOutTime", new Date(signOutTime));
// diff in or out
if(now > signInTime && now < signOutTime) {
// ready to sign out for today
console.log("Seconds to sign out for today: " + (signOutTime - now)/1000);
setTimeout(signInorSignOut, signOutTime - now);
} else {
// ready to sign in for tomorrow
signInTime = +signInTime + 60 * 60 * 24 * 1000;
console.log("Seconds to sign in for tomorrow: " + (signInTime - now)/1000);
setTimeout(signInorSignOut, signInTime - now);
}
// signInorSignOut
function signInorSignOut(){
logTime(`signInButton clicked!`);
// 重点就在这儿了,找到网站的签到按钮#signInButton,并触发他的点击事件
document.querySelector("#checkout_btn").click();
setTimeout(() => {
document.querySelector(".btn-primary").click();
},1000)
}
function logTime(str, time=new Date()){
console.log(`${str} -> ${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}`);
}
})();