glados_checkin

owned by LGY_lab

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         glados_checkin
// @namespace    http://tampermonkey.net/
// @version      0.4.0
// @description  owned by LGY_lab
// @author       mar
// @connect      *
// @grant        GM_xmlhttpRequest
// @grant        GM_getValue
// @grant        GM_setValue
// @run-at       document-body
// @match      https://*/*
// @license      MIT
// ==/UserScript==

;(function () {
  'use strict'

  var autoSign = true
function onSignIn(isAuto = false) {
  return GM_xmlhttpRequest({
    url: 'https://glados.rocks/api/user/checkin',
    method: 'POST',
    headers: {
      'content-type': 'application/json',
      'user-agent': navigator.userAgent,
    },
    data: '{"token": "glados.network"}',
    responseType: 'json',
    onload(response) {
      const data = response.response
      console.log('data', data)
      if (data.code !== 0) {
        if(data.code == 1) {
          GM_setValue('signDate', today())
          console.log('glados | try tomorrow')
        } else {
          console.log(data)
          throw new Error('new error!!!')
        }
      } else if(data.code == 0){
        GM_setValue('signDate', today())
        console.log('glados 签到成功')
      }
    }
  })
}


  //获取今天的日期
  function today() {
    var date = new Date()
    var seperator1 = '-'
    var seperator2 = ':'
    var month = date.getMonth() + 1
    var strDate = date.getDate()
    if (month >= 1 && month <= 9) {
      month = '0' + month
    }
    if (strDate >= 0 && strDate <= 9) {
      strDate = '0' + strDate
    }
    var currentdate =
      date.getFullYear() + seperator1 + month + seperator1 + strDate
    return currentdate
  }

  //自动签到
  function autoSignHandle() {
    let signDate = GM_getValue('signDate')
    console.log('signDate', signDate)
    console.log('today', today())
    if (autoSign && (!signDate || signDate < today())) {
      onSignIn(true)
    } else {
      console.log('glados checkin success, try tomorrow.')
    }
  }

  autoSignHandle()
})()