Greasy Fork

Greasy Fork is available in English.

掘金自动签到

在用户打开掘金页面后, 自动签到, 每天最多签到一次. 基于iframe实现, 不用担心接口被禁. 只支持 Chrome90+ 浏览器.

目前为 2023-01-09 提交的版本,查看 最新版本

"use strict";
// ==UserScript==
// @name         掘金自动签到
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  在用户打开掘金页面后, 自动签到, 每天最多签到一次. 基于iframe实现, 不用担心接口被禁. 只支持 Chrome90+ 浏览器.
// @author       sutie
// @match        https://juejin.cn/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=juejin.cn
// @grant        none
// @run-at       document-idle
// @noframes
// @unwrap
// @license MIT
// ==/UserScript==
const NAMESPACE = "juejin-auto-check";
const LOCALSTORAGE_KEY = "tampermonkey-" + NAMESPACE;
function getDate() {
    const date = new Date();
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, "0");
    const day = String(date.getDate()).padStart(2, "0");
    return `${year}-${month}-${day}`;
}
function createIframe(id) {
    const iframe = document.createElement("iframe");
    iframe.id = id;
    iframe.style.position = "fixed";
    iframe.style.top = "120px";
    iframe.style.right = "24px";
    iframe.style.width = "375px";
    iframe.style.height = "850px";
    iframe.style.zIndex = "1000";
    iframe.src = "https://juejin.cn/user/center/signin";
    return iframe;
}
function removeIframe(id) {
    const ifrm = document.getElementById(id);
    if (ifrm) {
        document.body.removeChild(ifrm);
    }
}
function signin() {
    const id = `iframe-${Math.ceil(Math.random() * 100)}`;
    const iframe = createIframe(id);
    document.body.prepend(iframe);
    iframe.onload = () => {
        const dialog = document.getElementById(id);
        if (dialog && dialog.contentDocument) {
            const btn = dialog.contentDocument.querySelector(".signin.btn");
            if (btn) {
                btn.click();
            }
            const timer = setTimeout(() => {
                clearTimeout(timer);
                removeIframe(id);
            }, 1000);
        }
    };
}
function main() {
    const lastestDay = localStorage.getItem(LOCALSTORAGE_KEY);
    const today = getDate();
    if (!lastestDay || lastestDay !== today) {
        try {
            signin();
            localStorage.setItem(LOCALSTORAGE_KEY, today);
        }
        catch (error) {
            localStorage.removeItem(LOCALSTORAGE_KEY);
        }
    }
}
function callInChrome(fn, version) {
    const match = navigator.userAgent.match(/Chrome\/(\d+)/);
    if (match && match[1] && Number(match[1]) > version) {
        fn();
    }
}
callInChrome(main, 90);