Skip to content

Instantly share code, notes, and snippets.

@hsupu
Last active December 23, 2019 06:01
Show Gist options
  • Save hsupu/48094a12c6bb8d553518542d7dd25319 to your computer and use it in GitHub Desktop.
Save hsupu/48094a12c6bb8d553518542d7dd25319 to your computer and use it in GitHub Desktop.
The missing auto check-in tempermonkey script for NFS.
// ==UserScript==
// @name nfs check-in
// @namespace https://reweb.site/
// @version 0.1
// @description check-in check-out
// @author xp
// @match http://123.57.174.192:8081/public/att/attdview*
// @grant none
// ==/UserScript==
function checkin(date, time, reason) {
let url = 'http://123.57.174.192:8081/public/sign/apply';
let token = localStorage.getItem('token');
let timestr = date + ' ' + time;
console.log([token, timestr, reason]);
$.post(url, {
signTime: timestr,
applyReason: reason,
token: token
}, function(result){
console.log(timestr);
});
}
(function() {
'use strict';
let ts = new Date().getTime();
let token = localStorage.getItem('token');
let token_ts = parseInt(localStorage.getItem('token_time')) || 0;
if (token === null || typeof token !== 'string' || (ts - token_ts > 3600)) {
let value = prompt('get token from /public/sign/toapply');
if (value.length == 0) return;
localStorage.setItem('token_time', ts);
localStorage.setItem('token', value);
}
if (typeof $ === 'undefined' || $ === null) {
console.error('page load failed');
return;
}
let items = [];
$("#func-table > tbody tr").each(function(){
let $this = $(this);
// skip weekend
if ($this.attr('class') == 'info') return;
let thedate = $this.find('td:nth-child(1)').text().trim();
if ($this.attr('class') == 'danger') {
// single check-in
let $td2 = $this.find('td:nth-child(2)');
if (parseInt($td2.text().split(':')[0]) < 12) {
// no end
items.push([thedate, '21:00', '忘记打卡了']);
} else {
// no start
items.push([thedate, '09:00', '忘记打卡了']);
}
} else if ($(this).find("td:last-child").text().trim() == '不正常') {
items.push([thedate, '09:00', '忘记打卡了']);
items.push([thedate, '21:00', '忘记打卡了']);
}
});
if (!confirm(items.join('\n'))) {
console.log(items);
return;
}
items.forEach(item => checkin(item[0], item[1], item[2]));
})();
@hsupu
Copy link
Author

hsupu commented Dec 23, 2019

view-source:http://123.57.174.192:8081/public/sign/toapply

<input type="hidden" name="token" value="_____________" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment