Greasy Fork

glados_checkin

owned by LGY_lab

目前为 2022-10-08 提交的版本。查看 最新版本

// ==UserScript==
// @name         glados_checkin
// @namespace    http://tampermonkey.net/
// @version      0.2.0
// @description  owned by LGY_lab
// @author       mar
// @connect      https://glados.rocks/*
// @grant        GM_getValue
// @grant        GM_setValue
// @create       2021-08-29
// @run-at       document-body
// @include      https://*/*
// @license      MIT
// ==/UserScript==

;(function () {
  'use strict'

  var autoSign = true
  function onSignIn(isAuto = false) {
    return fetch('https://glados.rocks/api/user/checkin', {
      method: 'POST',
      credentials: 'include',
      headers: {
        'content-type': 'application/json',
        'user-agent': navigator.userAgent,
      },
      body: JSON.stringify({
        token: 'glados.network',
      }),
    })
      .then((res) => res.json())
      .then((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')
    if (autoSign && (!signDate || signDate < today())) {
      onSignIn(true)
    } else {
      console.log('glados checkin success, try tomorrow.')
    }
  }

  autoSignHandle()
})()