Greasy Fork is available in English.

keyjoker新任务检测

keyjoker网站新任务检测

// ==UserScript==
// @name         keyjoker新任务检测
// @namespace    https://greasyfork.org/zh-CN/scripts/383411
// @version      0.4
// @description  keyjoker网站新任务检测
// @author       HCLonely
// @include      *://www.keyjoker.com/entries
// @supportURL   https://blog.hclonely.com/posts/6a28b89f/
// @homepage     https://blog.hclonely.com/posts/6a28b89f/
// @run-at       document-end
// @grant        GM_registerMenuCommand
// @grant        GM_addStyle
// @grant        GM_xmlhttpRequest
// @grant        GM_setClipboard
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_openInTab
// @grant        GM_log
// @require      https://greasyfork.org/scripts/379868-jquery-not/code/jQuery%20not%20$.js?version=700787
// ==/UserScript==

(function() {
    'use strict';
    function reLoad(time,sum){
        let date=new Date();
        let hour=date.getHours();
        let min=date.getMinutes()<10?("0"+date.getMinutes()):date.getMinutes();
        if(GM_getValue("start")==1){
            $(".border-bottom").text(hour+":"+min+" 执行新任务检测");
            $.ajax({
                url:"/entries/load",
                type:"get",
                headers:{'x-csrf-token': $('meta[name="csrf-token"]').attr('content')},
                success:(data)=>{
                    if(data&&(data.actions&&(data.actions.length>sum))){
                        let date=new Date();
                        let hour=date.getHours();
                        let min=date.getMinutes()<10?("0"+date.getMinutes()):date.getMinutes();
                        $(".border-bottom").text(hour+":"+min+" 检测到新任务");
                        $show({
                            title:"keyjoker新任务",
                            msg:"keyjoker网站更新"+(data.actions.length-sum)+"个新任务!",
                            icon:"https://www.keyjoker.com/favicon-32x32.png",
                            time:0,
                            onclick:function(){
                                location.reload(true);
                            }
                        });
                    }else{
                        setTimeout(()=>{
                            reLoad(time,sum);
                        },time);
                    }
                },
                error:(err)=>{
                    window.location.reload(true);
                }
            });
        }
    }
    function setTime(){
        let time=prompt('请输入获取任务信息的时间间隔(单位:秒):');
        if(!isNaN(time)){
            GM_setValue("time",parseInt(time));
        }
    }
    function start(){
        $showTest();
        GM_setValue("start",1);
        let time=GM_getValue("time");
        if(!time){
            time=60;
        }
        if(confirm("是否以时间间隔"+time+"秒进行任务检测?")){
            next();
        }
    }
    function next(){
        let time=GM_getValue("time");
        if(!time){
            time=60;
        }
        let sum=$(".list-complete-item").length;
        if(sum>0){
            reLoad(time*1000,sum);
        }else{
            reLoad(time*1000,0);
        }
    }
    let isStart=setInterval(()=>{
        if(GM_getValue("start")==1){
            clearInterval(isStart);
            next();
        }
    },1000);
    GM_registerMenuCommand("设置时间间隔",setTime);
    GM_registerMenuCommand("开始检测",start);
    GM_registerMenuCommand("停止检测",()=>{
        let date=new Date();
        let hour=date.getHours();
        let min=date.getMinutes()<10?("0"+date.getMinutes()):date.getMinutes();
        GM_setValue("start",0);
        $(".border-bottom").text(hour+":"+min+" 停止执行新任务检测");
    });
})();