Greasy Fork

Greasy Fork is available in English.

Sonkwo-AutoCheckin

Auto Checkin Script for Sonkwo

当前为 2024-02-02 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Sonkwo-AutoCheckin
// @namespace    https://www.sonkwo.cn/
// @license      WTFPL
// @description  Auto Checkin Script for Sonkwo
// @version      0.0.1
// @author       Hiiro
// @match        https://www.sonkwo.cn/
// @match        https://limestart.cn/
// @icon         https://www.sonkwo.cn/favicon.ico
// @run-at       document-end
// @grant        GM_registerMenuCommand
// ==/UserScript==


(function() {
    'use strict';
    GM_registerMenuCommand('清除本地存储',removeDateStore)
    const isSonkwoPage = (window.location.href.toString().indexOf('https://www.sonkwo.cn/') != -1)
    const date = new Date().getDate()
    function SetDateStore() {
        localStorage.setItem('SONKWO-SCRIPT-LAST-RUN', date)
    }
    function CompareDateStore(){
        return localStorage.getItem('SONKWO-SCRIPT-LAST-RUN') == date
    }
    function removeDateStore(){
    localStorage.removeItem('SONKWO-SCRIPT-LAST-RUN')
    document.location.reload()
        DetectAndRun()
  }
    function DoCheckin() {
        document.getElementsByClassName('store_user_card_action_check')[0].click()
    }
    function isCookieExists(name) {
    // 获取当前页面的所有cookies组成的字符串
    var cookies = document.cookie.split('; ');

    for (var i = 0; i < cookies.length; i++) {
        // 分割每个cookie为键和值
        var cookiePair = cookies[i].split('=');

        // 清除键名前后的空白字符并转换为小写(因为cookie名称是大小写敏感的)
        var cookieName = cookiePair[0].trim().toLowerCase();

        // 如果找到匹配的cookie名称,则返回true
        if (cookieName === name.toLowerCase()) {
            return true;
        }
    }

    // 如果遍历完所有cookie都未找到匹配项,则返回false
    return false;
}

// 使用示例:
var hasMyCookie = isCookieExists('myCookieName');
    function DetectAndRun(){
        if (CompareDateStore()) {
            return
        }
        if (!isSonkwoPage) {
            SetDateStore()
            window.location.href='https://www.sonkwo.cn/'
        }
        var timer = setInterval(() => {
            if (!isCookieExists('access_token') ){
                window.location.href='https://www.sonkwo.cn/sign_in?return_addr=%2F'
                clearInterval(timer)
            } else if (document.getElementsByClassName('store_user_card_action_check').length != 0) {
                if (document.getElementsByClassName('store_user_card_action_check')[0].innerHTML == '签到赚积分') {
                    DoCheckin()
                    SetDateStore()
                    clearInterval(timer)
                } else if (document.getElementsByClassName('store_user_card_action_check')[0].innerHTML == '已签到') {
                    SetDateStore()
                    clearInterval(timer)
                }
            }
        }, 3000)
    }
    window.onload = function () {
        DetectAndRun()
    }
})();