js脚本实现自动签到功能

该博客介绍了如何通过编写JavaScript脚本并使用Tampermonkey插件,在指定时间自动执行网页签到操作。脚本首先设定签到和签退时间,然后判断当前时间是否在签到或签退区间,触发相应的签到或签退按钮点击事件,实现无人值守的自动签到功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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()}`);
  }
})();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值