午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

JS腳本實現定時到網站上簽到/簽退功能

瀏覽:206日期:2024-05-12 10:01:50

之前介紹過使用temperMonkey屏蔽CSDN廣告的方法,主要就是要針對性地分析網站結構,然后用代碼去改變或者操作DOM。今天也一樣,我們需要觀察網頁結構,找到我們要操作的按鈕,觸發他的click事件就可以了。下面以公司打卡簽到的網站為例,做一些壞壞的事情。本文讀者最好有一定的HTML和JavaScript基礎。

首先,想象一下你去簽到需要做什么:

打開網站 登陸 點擊“簽到”按鈕

然后每一步我們都可以讓代碼幫我們去做。

0. 如何定時

這段代碼是核心,就是根據當前時間和設定的時間做差值,來確定定時器的值看懂這段代碼,后面的就都容易了。都是在利用定時器觸發callback。

// user settingconst SIGN_IN_TIME = '09:30:00'; // 簽到時間const SIGN_OUT_TIME = '20:00:00'; // 簽退時間// code implementationlogTime('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 outif (now > signInTime && now < signOutTime) { // ready to sign out for today console.log('Seconds to sign out for today: ' + (signOutTime - now) / 1000); setTimeout(callback, 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(callback, signInTime - now);}function logTime(str, time = new Date()) { console.log(`${str} -> ${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}`);}

1. 定時自動打開網站

因為大多數網站都有,“長時間未操作-自動退出”的設置。所以我們要在需要打卡的時候再打開網站。在電腦本地跑一個程序,使用定時器。這里跑一個node程序:

const open = require(’open’);logTime('Start Runing');// user settingconst SIGN_IN_TIME = '09:30:00';const SIGN_OUT_TIME = '20:20:00';// code implementationconst openBrowser = async () => { await open(’http://172.10.80.42’);};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 outif (now > signInTime && now < signOutTime) { // ready to sign out for today console.log('Seconds to sign out for today: ' + (signOutTime - now) / 1000); setTimeout(openBrowser, 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(openBrowser, signInTime - now);}function logTime(str, time = new Date()) { console.log(`${str} -> ${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}`);}

2. 自動登錄

這個重點還是在于找到需要填入內容的DOM元素

(function() { ’use strict’; // login document.querySelector('#loginid').value = '用戶名'; document.querySelector('#userpassword').value = '密碼'; document.querySelector('#login').click();})();

3. 定時點擊按鈕

這一步最重要的是要準確找到按鈕,檢查元素慢慢查找吧。其次,設定好簽到和簽退的時間,只有固定時間才會自動簽到,防止每次登陸進來自動簽到或簽退,這樣太頻繁被發現。

(function() { ’use strict’; // user setting const SIGN_IN_TIME = '09:00:00'; const SIGN_OUT_TIME = '21: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('#signInButton').click(); } function logTime(str, time=new Date()){ console.log(`${str} -> ${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}`); }})();

4. 結束

一套操作,打完收工。每天下班的時候,不管是提前溜還是晚點到。記得本地開一下程序:

node timer.js

到此這篇關于JS腳本實現定時到網站上簽到/簽退功能的文章就介紹到這了,更多相關js 定時簽到簽退內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 欧美三级网站在线观看 | 国产免费网址 | 老汉色av | 在线看黄网址 | 国产一级久久久 | 精品中文字幕一区二区 | 精品91视频 | 中文字幕在线视频一区 | 欧美日韩亚洲天堂 | 国产福利免费在线观看 | 日日摸日日干 | 国产免费一区二区三区在线观看 | 欧美一二三区在线观看 | 免费在线日韩 | 男女操网站 | 国产精品一区在线观看 | 日韩三级高清 | 青青视频二区 | japanese在线视频 | 成人精品亚洲 | 精品久久久在线观看 | 日本精品一区二区三区视频 | 亚洲欧美自拍一区 | 日韩欧美国产一区二区三区 | 日韩中文在线字幕 | 亚洲综合不卡 | 最新日本中文字幕 | av在线不卡观看 | 国内精品久久久久久 | 深爱开心激情 | 久操青青 | 色av影院| 日韩高清在线一区 | 日韩高清久久 | 九九九国产视频 | 欧日韩av| 三级a视频 | 丁香婷婷亚洲 | 欲妇荡岳丰满少妇岳91白洁 | 天堂资源av| 久久成人综合 |