自动任务

自动完成并验证赠key网站任务

Fra 03.03.2019. Se den seneste versjonen.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         自动任务
// @namespace    https://greatest.deepsurf.us/scripts/370650
// @version      1.2.5
// @description  自动完成并验证赠key网站任务
// @author       HCLonely
// @icon         data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIfIiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/2wBDAQoLCw4NDhwQEBw7KCIoOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozv/wAARCAAgACADASIAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAABgQFBwP/xAAuEAACAQIFAgQEBwAAAAAAAAABAgMEEQAFEiExBkETUWFxFBUioTJCQ3KBsdH/xAAYAQADAQEAAAAAAAAAAAAAAAABAgMABP/EABsRAQADAAMBAAAAAAAAAAAAAAEAAgMRIkEx/9oADAMBAAIRAxEAPwDr008VPGZJpFRR3Y4GVfWclVMxpkaOmQ8rIpZh5mx29seXWUlRVV8cEV1KsRrJ2Qeg89ufXB0dPRkbamJFibnHLpp4S2eYnLEFF1nU/GM0ktoufBlUliOSR/ovhpl+YQZlSLU05JU7EHlT3B9cckqaGpoVD+I80K/lf6tH7T2Pth50RVLLTVMZkViziRADf6SAP7H3wc7q8M2tAOSVZ9kjTs1fSyKsqqS8cn4JPLfsR98ZvTUVfX0E3zaiFFNDUNGgTcSqOCL4VVc0UFMzzi8fB2vztjAzfOfgoaePLHWaonnWIRybBATY3255thr1PsGbZ6kiqMtM1LO4ppYpE/Tl0WYcE7E2Ft8U9J5RJlYeWfSjLqjVFfUCL3FvYHEcWZZnBnlQle0E8baPBpw41C97nUOOB/JwihpWcAxsEHPhcFPQ+fv3wlK+ymlU62Z//9k=
// @include      *://www.grabfreegame.com/giveaway/*
// @include      *://gamecode.win/giveaway/*
// @include      *://whosgamingnow.net/giveaway/*
// @include      *://marvelousga.com*
// @include      *://dupedornot.com*
// @include      *://gamezito.com*
// @include      *://www.bananagiveaway.com/giveaway/*
// @include      /https?:\/\/gamehag.com\/.*?giveaway\/.*/
// @include      *://giveawayhopper.com/giveaway/*
// @include      *://giveaway.su/giveaway/view/*
// @include      *://gleam.io/*
// @include      *://gamehunt.net/distribution/*
// @include      *://www.orlygift.com/giveaway*
// @include      *://www.indiedb.com/giveaways/*
// @include      *://www.spoune.com/*
// @exclude      *://www.spoune.com/werbung/*
// @exclude      /https?:\/\/www.spoune.com\/.*?verify\-api.*/
// @run-at       document-end
// @grant        GM_addStyle
// @grant        GM_xmlhttpRequest
// @grant        GM_setClipboard
// @grant        GM_setValue
// @grant        GM_getValue
// @require      https://greatest.deepsurf.us/scripts/376437-hclonely-function/code/HCLonely_function.js?version=674827
// @supportURL   https://steamcn.com/t455167-1-1
// @connect      instagram.com
// @connect      twitter.com
// @connect      facebook.com
// @connect      youtube.com
// @connect      steampowered.com
// @connect      g2a.com
// @connect      gamehunt.net
// @connect      9000.plati.market
// ==/UserScript==

(function() {
    'use strict';

    try{

        var autoOpen=isset(GM_getValue("autoTaskSetting"))?GM_getValue("autoTaskSetting"):1;//1为自动打开任务页面;改为0则不打开任务页面

        var url=window.location.href;
        var bg=/bananagiveaway/gim.test(url)?"background-color:#71c61d;":"";
        var height=/grabfreegame/gim.test(url)?96:(/bananagiveaway/gim.test(url)?110:(/gamezito/gim.test(url)?125:(/gamecode/gim.test(url)?30:40)));
        var game=url.replace(/https?:\/\/(www)?(marvelousga|dupedornot|gamezito|gamecode).(com|win)\/giveaway\/|/,"");

        HCL.css.gm(`
#doTaskDiv{position:fixed;right:80px;top:${height}px;width:85px;z-index: 99999999999;}
#info{max-height:352px;overflow-y:auto;padding:0 !important}
#exInfo{position:fixed;right:50px;bottom:10px;max-width:600px;max-height:400px;z-index: 99999999999;display:none;background-color:#fff;padding:1.5rem}
.infos{position:absolute;top:0px;left:0px;background-color:#757d81;border-radius: 3px !important;padding: 0px 2px !important;width:20px;height:20px}
#shouqi{font-weight:900;color:#00e5ff}
.auto-task{width:145px;height:40px;${bg}}
#fixed-banana,cloudflare-app{display:none !important}
.setting{width:145px;background:white;border:2px solid;border-radius:25px;}
`);

        var div=HCL.ele({ele:"div","id":"doTaskDiv","class":"card-content",parent:HCL.tag("body")[0],html:`<button id="doTask" class="btn btn-round auto-task btn-theme btn-outline-dark btn-min-width mr-1 mb-1" title="一键做任务+验证">FuckTask</button>
<button id="Verify" class="btn btn-round auto-task btn-theme btn-outline-dark btn-min-width mr-1 mb-1" title="一键验证">Verify</button>
<button id="Remove" class="btn btn-round auto-task btn-theme btn-outline-dark btn-min-width mr-1 mb-1" title="一键退组,取关">Remove</button>`});
        var div3=HCL.ele({ele:"div","id":"exInfo",parent:HCL.tag("body")[0],html:`<span class="infos"><a id="shouqi" class="zhankai" href="javascript:;"" title="收起">↘</a></span>`});
        var div2=HCL.ele({ele:"div","id":"info","class":"card-body card",parent:div3});
        HCL.id("shouqi").onclick=function(e){
            e=HCL.id("shouqi").className=="zhankai"?["20px","↖","展开","shouqi","none"]:["","↘","收起","zhankai","block"];
            div3.style.width=e[0];
            div3.style.height=e[0];
            HCL.id("shouqi").innerText=e[1];
            HCL.id("shouqi").setAttribute("title", e[2]);
            HCL.id("shouqi").setAttribute("class", e[3]);
            div2.style.display=e[4];
        }

        if(/marvelousga|dupedornot|gamezito/.test(url)){//marvelousga,dupedornot,gamezito领key

            $("body").text().match(/THIS GIVEAWAY IS CLOSED FOR THE MOMENT/gim)!=null&&(confirm("此页面已经没有key了,是否关闭?")&&(window.close()));

            /You need to be logged in to perform all tasks/gim.test(HCL.tag("body")[0].innerText)&&(window.location.href="/login");

            $('cloudflare-app[app="welcome-bar"]').remove();
            var w=0;
            banNewBlock();

            //marvelousga,dupedornot,gamezito浏览页面任务
            function finTask(taskId,e,text,task){
                var p=info("card-text monospace","",`开始任务${taskId}:${text}...`);
                httpSend({
                    type: "post",
                    url: task?"/ajax/verifyTasks/webpage/clickedLink":"/ajax/verifyTasks/video/finished",
                    headers:{'x-csrf-token': $('meta[name="csrf-token"]').attr('content')},
                    data:{
                        giveaway_slug: game,
                        giveaway_task_id: taskId
                    },
                    callback: function (data) {
                        if(data.status==200){
                            if(data.json.status==1){
                                HCL.id((task?"task_webpage_visit_":"task_video_watched_")+taskId).innerText="OK";
                                addR(p,"OK!");
                            }else{
                                var msg=data.json.message||"ERROR";
                                addR(p,msg,"err");
                            }
                        }else{
                            addR(p,`${data.statusText}:${data.status}`,"err");
                        }
                        e===w&&(getId());
                    }
                });
            }

            //marvelousga,dupedornot,gamezito获取任务id
            function getId(task_id=[],api_id=[],btn_id=[],p_id=[]){
                var btn=HCL.tag("button");
                for(var i=0;i<btn.length;i++){
                    var btnId=btn[i].id;
                    if(/task_[\w\W]*[\d]*/i.test(btnId)&&!/verified/i.test(btn[i].innerText)){
                        var tskid=btnId.replace(/task_|_[\d]+/gim,"");
                        tskid=tskid.replace("_","/");
                        api_id.push(tskid);
                        task_id.push(btn[i].id.match(/[\d]+/)[0]);
                        btn_id.push(btnId);
                        /https?:\/\/gamezito.com\/giveaway\/[\w\W]*/.test(url)?p_id.push(btn[i].parentNode.parentNode.getElementsByTagName("h3")[0].innerHTML.replace(/id\=\"[\w\W]*?\"/i,"")):p_id.push(btn[i].parentNode.getElementsByTagName("p")[0].innerHTML.replace(/id\=\"[\w\W]*?\"/i,""));
                    }
                }
                if(task_id.length>0&&api_id.length>0&&btn_id.length>0&&p_id.length>0){
                    verify(task_id,api_id,btn_id,p_id,0);
                }else if(task_id.length==0&&api_id.length==0&&btn_id.length==0&&p_id.length==0){
                    info("card-text monospace","color:green",`所有任务验证完成!`);
                    getKey();
                }
            }

            //marvelousga,dupedornot,gamezito验证任务
            function verify(task_id,api_id,btn_id,p_id,e,v=0){
                if(/visit[\w\W]*?webpage/gim.test(p_id[e])&&v==1){
                    e++;
                    if(e<btn_id.length){
                        verify(task_id,api_id,btn_id,p_id,e);
                    }else{
                        info("card-text monospace","color:green",`所有任务验证完成!`);
                        getKey();
                    }
                    return;
                }else{
                    /visit[\w\W]*?webpage/gim.test(p_id[e])&&v!=1&&(v=1);
                    var p=info("card-text monospace","",`验证任务${task_id[e]}:${p_id[e]}...`);
                    if(/Join[\w\W]*?in Steam/i.test(p_id[e].innerText)){
                        HCL.id(btn_id[e]).removeAttribute("disabled");
                        HCL.id(btn_id[e]).click();
                    }
                    httpSend({
                        type: "post",
                        url: "/ajax/verifyTasks/"+api_id[e],
                        headers:{'x-csrf-token': $('meta[name="csrf-token"]').attr('content')},
                        data:{
                            giveaway_slug: game,
                            giveaway_task_id: task_id[e]
                        },
                        callback: function (data) {
                            if(data.status==200){
                                if(data.json.status==1){
                                    HCL.id(btn_id[e]).innerText="VERIFIED";
                                    p.innerHTML+="<font style='color:green'>OK!</font>--<font style='color:blue'>"+data.json.percentageNanoBar+"%</font>";
                                }else{
                                    HCL.id(btn_id[e]).innerText="ERROR!";
                                    HCL.id(btn_id[e]).style.color="red";
                                    autoOpen==1&&(/gamezito/gim.test(url)?HCL.id(btn_id[e]).parentNode.parentNode.getElementsByTagName("a")[0].click():HCL.id(btn_id[e]).parentNode.getElementsByTagName("a")[0].click());
                                    var msg=data.json.message||"ERROR";
                                    addR(p,msg,"err");
                                }
                                e++;
                                if(data.json.percentageNanoBar==100||e>=btn_id.length){
                                    info("card-text monospace","color:green",`所有任务验证完成!`);
                                    getKey();
                                }else{
                                    verify(task_id,api_id,btn_id,p_id,e,v);
                                }
                            }else{
                                HCL.id(btn_id[e]).innerText="ERROR!";
                                HCL.id(btn_id[e]).style.color="red";
                                data.status!=419&&(HCL.id(btn_id[e]).parentNode.getElementsByTagName("a")[0].click());
                                addR(p,`${data.statusText}:${data.status}`,"err");
                                e++;
                                if(e<btn_id.length){
                                    verify(task_id,api_id,btn_id,p_id,e);
                                }else{
                                    info("card-text monospace","color:green",`所有任务验证完成!`);
                                    getKey();
                                }
                            }
                        },
                    });
                }
            }

            //marvelousga,dupedornot,gamezito获取steamkey
            function getKey(){
                if(/your[\s]*?key[\w\W]*?[\w\d]{5}(-[\w\d]{5}){2}/gim.test(HCL.tag("body")[0].innerText)){
                    info("card-text monospace","",`你已经领取过key了!`);
                    return 0;
                }
                info("card-text monospace","",`请手动完成<a id="google" href="javascript:void(0)">谷歌验证</a>获取key!`);
                HCL.id("google").onclick=function(){
                    HCL.id("get_key_container").scrollIntoView();
                    HCL.id("get_key_container").getElementsByClassName("card-body")[0].style.backgroundColor="red";
                    setTimeout(function(){HCL.id("get_key_container").getElementsByClassName("card-body")[0].style.backgroundColor=""},600);
                };
                HCL.id("get_key_container").style.display="block";
                HCL.id("get_key_container").scrollIntoView();
                HCL.id("get_key_container").getElementsByClassName("card-body")[0].style.backgroundColor="red";
                setTimeout(function(){HCL.id("get_key_container").getElementsByClassName("card-body")[0].style.backgroundColor=""},600);
            }

            //marvelousga,dupedornot,gamezito按钮定义
            HCL.id("doTask").onclick=function(){
                HCL.id("exInfo").style.display="block";
                $('button>span:contains("Join ")').click();
                $('button>span:contains("Follow ")').click();
                info("card-text monospace","",`正在做加组、关注等任务(此功能需要<a href="https://greatest.deepsurf.us/zh-CN/scripts/34764-giveaway-helper" target="_blank">Giveaway Helper脚本</a>,没有则自动跳过此步骤),请稍候!`);
                doTask(function(){
                    w=0;
                    if($("video").length>0){
                        var videoDiv=$("video").parent().parent().parent().parent();
                        videoDiv.find("button.btn-dark")[0].id.replace(/task_video_watched_/,"");
                        w++;
                        finTask(videoDiv.find("button.btn-dark")[0].id.replace(/task_video_watched_/,""),"","Watch this video",0);
                    }
                    var a=HCL.tag("a");
                    var taskId,text;
                    for(var i=0;i<a.length;i++){
                        var parent=a[i].parentNode.parentNode;
                        if(a[i].innerText==="this"&&/task_(webpage_clickedLink|video_watched)_[\d]*/.test(a[i].id)&&!/verified/i.test(parent.getElementsByTagName("button")[0].innerText)){
                            taskId=a[i].id.replace(/task_webpage_clickedLink_|task_video_watched_/,"");
                            text=a[i].parentNode.innerHTML.replace(/id\=\"[\w\W]*?\"/i,"");
                            w++;
                            finTask(taskId,w,text,1);
                        }
                    }
                    w==0&&(getId());
                },new Date().getTime(),($('button>span:contains("Join ")').length+$('button>span:contains("Follow ")').length)*3);
            };
            HCL.id("Verify").onclick=function(){
                HCL.id("exInfo").style.display="block";
                getId();
            };

        }

        //gamecode领key
        if(/gamecode/.test(url)){

            $("body").text().match(/THIS GIVEAWAY IS CLOSED FOR THE MOMENT/gim)!=null&&(confirm("此页面已经没有key了,是否关闭?")&&(window.close()));

            /Please login to see the tasks/gim.test(HCL.tag("body")[0].innerText)&&(window.location.href="/login");

            banNewBlock();

            //gamecode按钮定义
            HCL.id("doTask").onclick=function(){
                HCL.id("exInfo").style.display="block";
                $('button>span:contains("Join ")').click();
                $('button>span:contains("Follow ")').click();
                info("card-text monospace","",`正在做加组、关注等任务(此功能需要<a href="https://greatest.deepsurf.us/zh-CN/scripts/34764-giveaway-helper" target="_blank">Giveaway Helper脚本</a>,没有则自动跳过此步骤),请稍候!`);
                doTask(gamecode_task,new Date().getTime(),($('button>span:contains("Join ")').length+$('button>span:contains("Follow ")').length)*3);
            };
            HCL.id("Verify").onclick=function(){
                HCL.id("exInfo").style.display="block";
                gamecode_task();
            };

            //gamecode做任务
            function gamecode_task(){
                var gamecode_btn=HCL.class("btn btn-theme");
                info("card-title","color: #f38288",`正在自动做任务,任务完成后请手动完成谷歌验证领取key!`);
                for(var i=0;i<gamecode_btn.length;i++){
                    if(!/auto-task/gim.test(gamecode_btn[i].className)&&!/verified/gim.test(gamecode_btn[i].innerText)){
                        gamecode_btn[i].removeAttribute("disabled");
                        gamecode_btn[i].click();
                    }
                }
            }

        }


        if(/grabfreegame|bananagiveaway/.test(url)){//grabfreegame,bananagiveaway领key

            $("div.left").text().match(/[\d]+/gim)[0]==0&&(confirm("此页面已经没有key了,是否关闭?")&&(window.close()));

            //自动登录
            /log.*?in/gim.test($(".user").text())&&(location.href=$(".user").children("a.steam")[0].href);

            //grabfreegame,bananagiveaway按钮定义
            HCL.id("doTask").onclick=function(){
                isBanana();
                HCL.id("exInfo").style.display="block";
                $('button>span:contains("Join ")').click();
                $('button>span:contains("Follow ")').click();
                info("card-text monospace","",`正在做加组、关注等任务(此功能需要<a href="https://greatest.deepsurf.us/zh-CN/scripts/34764-giveaway-helper" target="_blank">Giveaway Helper脚本</a>),请稍候!`);
                doTask(getBtn("d"),new Date().getTime(),($('button>span:contains("Join ")').length+$('button>span:contains("Follow ")').length)*3);
            };
            HCL.id("Verify").onclick=function(){
                HCL.id("exInfo").style.display="block";
                getBtn("v");
            };
            div2.setAttribute("style", `right:50px;bottom:10px;z-index: 99999999999;font-family: Menlo,Monaco,Consolas,"Courier New",monospace;font-size: 20px;background: #fff;color: #f05f00;border: 3px solid #ababab;order-radius: 8px;display: inline-block;`);

            //grabfreegame,bananagiveaway检测是否需要香蕉
            function isBanana(){
                var p=HCL.tag("p");
                for (var i=0;i<p.length;i++){
                    if(/Collect.*?[\d]+? banana/gim.test(p[i].innerText)){
                        alert("此key需要收集"+p[i].innerText.match(/[\d]+/gim)[0]+"个香蕉!");
                        return 0;
                    }
                }
            }

            //grabfreegame,bananagiveaway获取任务id
            function getBtn(e,verify_btn=[],do_btn=[]){
                var btn=HCL.tag("button");
                for(var i=0;i<btn.length;i++){
                    /verify/i.test(btn[i].innerHTML)&&btn[i].id!="Verify"&&(verify_btn.push(btn[i].onclick.toString().match(/\/\/www.(grabfreegame|bananagiveaway).com\/giveaway\/[\w\W]*?\?verify\=[\d]+/)[0]));
                    /to[\w\W]*?do[\w\W]*/i.test(btn[i].innerHTML)&&btn[i].onclick&&(do_btn.push(btn[i].onclick.toString().match(/\/\/www.(grabfreegame|bananagiveaway).com\/giveaway\/[\w\W]*?\?q\=[\d]+/)[0]));
                }
                do_btn.length>0&&e==="d"&&(gbDoTask(0,verify_btn,do_btn));
                verify_btn.length>0&&e==="v"&&(bananaVerify(0,verify_btn));
            }

            //grabfreegame,bananagiveaway做任务
            function gbDoTask(e,verify_btn,do_btn){
                var taskId=do_btn[e].match(/\?q\=[\d]+/)[0];
                taskId=taskId.replace("?q=","");
                var p=info("code","",`执行任务:${taskId}...`);
                httpSend({
                    type: "get",
                    url: do_btn[e],
                    timeout:"10000",
                    callback: function (data) {
                        addR(p,"OK");
                        e++;
                        e<do_btn.length?gbDoTask(e,verify_btn,do_btn):(verify_btn.length>0&&(bananaVerify(0,verify_btn)));
                    }
                });
            }

            //grabfreegame,bananagiveaway验证任务
            function bananaVerify(e,verify_btn){
                var taskId=verify_btn[e].match(/\?verify\=[\d]+/)[0];
                taskId=taskId.replace("?verify=","");
                var p=info("code","",`验证任务:${taskId}...`);
                httpSend({
                    type: "get",
                    url: verify_btn[e],
                    timeout:"10000",
                    callback: function (data) {
                        addR(p,"OK");
                        e++;
                        e<verify_btn.length?bananaVerify(e,verify_btn):bananaRe();
                    }
                });
            }

            //grabfreegame,bananagiveaway刷新网页
            function bananaRe(){
                var button;
                var li=HCL.class("tasks")[0].getElementsByTagName("li");
                for(var i=0;i<li.length;i++){
                    if(/Subscribe.*?our.*?channel/gim.test(li[i].innerText)&&!/Completed/gim.test(li[i].innerText)){
                        button=li[i].getElementsByTagName("button");
                        button[1].removeAttribute("disabled");
                        button[1].click();
                        return 0;
                    }else if(/Share.*?this.*?giveaway.*?on.*?Twitter/gim.test(li[i].innerText)&&!/Completed/gim.test(li[i].innerText)){
                        button=li[i].getElementsByTagName("button");
                        button[0].click();
                        button[1].removeAttribute("disabled");
                        button[1].click();
                        return 0;
                    }
                }
                window.reload(true);
            }
        }


        if(/whosgamingnow/.test(url)){//wgn领key

            $("body").text().match(/out of keys/gim)!=null&&(confirm("此页面已经没有key了,是否关闭?")&&(window.close()));

            $("div.text-center").map(function(i,e){/Please login to enter/gim.test($(e).text())&&(location.href="?login")});

            //wgn按钮定义
            HCL.id("doTask").onclick=function(){
                $('button>span:contains("Join ")').click();
                $('button>span:contains("Follow ")').click();
                doTask(wgn_enter,new Date().getTime(),($('button>span:contains("Join ")').length+$('button>span:contains("Follow ")').length)*3);
            };
            HCL.id("Verify").onclick=function(){
                alert("请手动完成加组任务!");
                HCL.id("exInfo").style.display="block";
                wgn_enter();
            };
            btn_class("btn btn-primary");

            //wgn获取key
            function wgn_enter(){
                httpSend({
                    type: "post",
                    url: url,
                    data:{submit: "Enter"},
                    callback: function (data) {
                        if(data.status==200){
                            if(/<h3>Steam key:<\/h3><p><strong class=\"SteamKey\">[\w\d]{5}(-[\w\W]{5}){2}<\/strong><\/p>/i.test(data)){
                                var key=data.match(/<h3>Steam key:<\/h3><p><strong class=\"SteamKey\">[\w\d]{5}(-[\w\W]{5}){2}<\/strong><\/p>/i)[0];
                                key=key.replace(/(<h3>Steam key:<\/h3><p><strong class="SteamKey">)|(<\/strong><\/p>)/gi,"");
                                data=data.replace(key,`<a href=https://store.steampowered.com/account/registerkey?key=${key} title="点击激活">${key}</a>`);
                            }
                            document.write(data);
                        }else{
                            info("","color:red",data.statusText+":"+data.status);
                        }
                    },
                });
            }
        }

        if(/gamehag/.test(url)){//gamehag领key

            if($("div.strong").eq(0).text()==0){
                $("div.strong").eq(0).parent()[0].style.backgroundColor="red";
                confirm("此页面已经没有key了,是否关闭?")&&(window.close());
            }else if($("div.strong").eq(1).text()==0){
                $("div.strong").eq(1).parent()[0].style.backgroundColor="red";
                confirm("此领key页面已过期,是否关闭?")&&(window.close());
            }

            var success,error,a,survey=0;;
            btn_class("btn btn-primary btn-sm box-collapse-verify");
            $("#doTaskDiv").css({"right": "340px","top": "100px"});
            $("#doTask").width("105px");
            $("#Verify").width("105px");
            $("#Remove").width("105px");
            HCL.css.gm(`.misty-notification{display:none !important}`);

            //gamehag按钮定义
            HCL.id("doTask").onclick=function(){
                HCL.id("exInfo").style.display="block";
                $('button>span:contains("Join ")').click();
                $('button>span:contains("Follow ")').click();
                info("card-text monospace","",`正在做加组、关注等任务(此功能需要<a href="https://greatest.deepsurf.us/zh-CN/scripts/34764-giveaway-helper" target="_blank">Giveaway Helper脚本</a>,没有则自动跳过此步骤),请稍候!`);
                doTask(function(){
                    success=0;
                    error=0;
                    survey=$("a.giveaway-survey").length>0&&(/\+1/gim.test($("a.giveaway-survey").parent().parent().next().text()))?1:0;
                    a=0;
                    var p=info("card-text monospace","",`正在做任务...`);
                    $("button[data-id]").length>0?gamehag_task(p):gamehag_suryey(0,p);
                },new Date().getTime(),($('button>span:contains("Join ")').length+$('button>span:contains("Follow ")').length)*3);
            };
            HCL.id("Verify").onclick=function(){
                HCL.id("exInfo").style.display="block";
                success=0;
                error=0;
                survey=$("a.giveaway-survey").length>0&&(/\+1/gim.test($("a.giveaway-survey").parent().parent().next().text()))?1:0;
                $("button[data-id]").length>0&&($("button[data-id]").map(function(i,e){gamehag_verify(e)}));
                survey==1&&(gamehag_verify($("a.giveaway-survey")[0],"data-task_id"));
            };

            !empty(HCL.id("getkey"))&&(HCL.id("getkey").onclick=function(){HCL.css.gm(`.misty-notification{display:block !important}`)});

            //gamehag做任务
            function gamehag_task(p){
                $("button[data-id]").map(function(i,e){
                    httpSend({
                        mode:"gm",
                        url:'//gamehag.com/giveaway/click/'+$(e).attr("data-id"),
                        type:'get',
                        headers:{'x-csrf-token': $('meta[name="csrf-token"]').attr('content')},
                        callback:function(data){
                            httpSend({mode:"gm",url:data.finalUrl,type:'get',headers:{'x-csrf-token': $('meta[name="csrf-token"]').attr('content')}});
                            a++;
                            if(a==$("button[data-id]").length){
                                $.ajax({url:'//gamehag.com/games',type:'get',headers:{'x-csrf-token': $('meta[name="csrf-token"]').attr('content')},complete:function(){
                                    $.ajax({url:'//gamehag.com/games/war-thunder/play',type:'get',headers:{'x-csrf-token': $('meta[name="csrf-token"]').attr('content')},complete:function(){gamehag_start(p)}});
                                }});
                            }
                        }
                    });
                });
            }

            //gamehag开始执行
            function gamehag_start(p){
                addR(p,"OK");
                gamehag_suryey();
                $("button[data-id]").map(function(i,e){gamehag_verify(e)});
            }

            //gamehag问卷调查任务
            function gamehag_suryey(e=1,p=0){
                p!=0&&(addR(p,"OK"));
                if(survey==1){
                    info("card-text monospace","",`正在做问卷调查任务,如果没有此任务请忽视!`);
                    $.ajax({url:'//gamehag.com/giveaway/click/'+$("a.giveaway-survey").attr("data-task_id"),type:'get',headers:{'x-csrf-token': $('meta[name="csrf-token"]').attr('content')}});
                    gamehag_verify($("a.giveaway-survey")[0],"data-task_id");
                }else if(e==0){
                    info("","color:green",`所有任务验证完成,请手动完成验证领取key!`);
                }
            }

            //gamehag验证任务
            function gamehag_verify(e,s="data-id"){
                if(/\+1/gim.test($(e).parent().parent().next().text())){
                    var p=info("card-text monospace","",`验证任务:${$(e).parent().parent().find("a.tooltip-trigger").clone().html()}...`);
                    $.ajax({
                        url:'//gamehag.com/api/v1/giveaway/sendtask',
                        type:'post',
                        data:'task_id='+$(e).attr(s),
                        headers:{'x-csrf-token': $('meta[name="csrf-token"]').attr('content')},
                        complete:function(XMLHttpRequest, textStatus){
                            if(XMLHttpRequest.status==429||/timeout/gim.test(textStatus)){
                                $(p).remove();
                                gamehag_verify(e);
                            }else{
                                var data=eval('('+XMLHttpRequest.responseText+')');
                                data.status=="success"?success++:error++;
                                var color=data.status=="success"?"green":"red";
                                p.innerHTML+=`<font style='color:${color}'>${data.message}!</font>`;
                                data.status=="success"&&($(e).parent().parent().parent().find("div.task-reward.tooltip-trigger").html(`<svg class="nc-icon nc-align-to-text grid-24 glyph"><use xlink:href="/icons/nci-fill.svg#nc-icon-check-simple"></use></svg>`));
                                if(/The task has not been completed/gim.test(data.message)&&autoOpen==1){
                                    window.open('https://gamehag.com/giveaway/click/'+$(e).attr("data-id"),"_blank");
                                }
                            }
                            if(success+error==$("button[data-id]").length+survey){
                                error>0?info("","color:red",`所有任务验证完成,${error}个任务验证失败!`):info("","color:green",`所有任务验证完成,请手动完成验证领取key!`);
                                btn_class("btn btn-primary btn-sm box-collapse-verify");
                            }
                        }
                    });
                }else{
                    success++;
                    if(success+error==$("button[data-id]").length+$("a.giveaway-survey").length){
                        error>0?info("","color:red",`所有任务验证完成,${error}个任务验证失败!`):info("","color:green",`所有任务验证完成,请手动完成验证领取key!`);
                        btn_class("btn btn-primary btn-sm box-collapse-verify");
                    }
                }
            }
        }

        if(/giveawayhopper/.test(url)){//giveawayhopper领key

            btn_class("btn btn-outline-primary");

            $("#info").attr("style","border-radius: 0;border-bottom-right-radius: 0;border-bottom-left-radius: 0;");

            //giveawayhopper按钮定义
            HCL.id("doTask").onclick=function(){
                HCL.id("exInfo").style.display="block";
                $('button>span:contains("Join ")').click();
                $('button>span:contains("Follow ")').click();
                doTask(function(){
                    $("button.btn-check.btn-primary").map(function(i,e){
                        var taskText=$(e).parent().prev().text().replace(/(^\s*)|(\s*$)/g, "");
                        var taskId=e.id;
                        var taskUrl=$(e).prev().html().match(/xhttp.open\([\w\W]*?\)\;/gim)[0].match(/\"[\w\W]*?\"/gim)[1].replace(/\"/g,"");;
                        hopperTask(taskText,taskUrl,taskId);
                    });
                },new Date().getTime(),($('button>span:contains("Join ")').length+$('button>span:contains("Follow ")').length)*3);
            };
            HCL.id("Verify").onclick=function(){
                HCL.id("exInfo").style.display="block";
                $("button.btn-check.btn-primary").map(function(i,e){
                    var taskText=$(e).parent().prev().text().replace(/(^\s*)|(\s*$)/g, "");
                    var taskId=e.id;
                    var taskUrl=$(e).prev().html().match(/xhttp.open\([\w\W]*?\)\;/gim)[0].match(/\"[\w\W]*?\"/gim)[1].replace(/\"/g,"");;
                    hopperTask(taskText,taskUrl,taskId);
                });
            };
            function hopperTask(taskText,taskUrl,taskId){
                var p=info("","",`正在做任务${taskText}...`);
                httpSend({
                    type:"get",
                    url:taskUrl,
                    callback:function(data){
                        var verifyTaskBtn;
                        if(data.text == 'success'){
                            verifyTaskBtn = document.getElementById(taskId);
                            verifyTaskBtn.classList.remove("btn-danger");
                            verifyTaskBtn.classList.add("btn-success");
                            verifyTaskBtn.innerHTML = '<i class="la la-check"></i>&nbsp;DONE';
                            addR(p,data.text,"success");
                        }else{
                            verifyTaskBtn = document.getElementById(taskId);
                            verifyTaskBtn.classList.remove("btn-primary");
                            verifyTaskBtn.classList.remove("btn-primary");
                            verifyTaskBtn.classList.add("btn-danger");
                            verifyTaskBtn.innerHTML = '<i class="la la-close"></i>&nbsp;ERROR';
                            addR(p,data.text,"err");
                        }
                    }
                });
            }
        }

        if(/giveaway.su/.test(url)){//giveaway.su领key

            $(".giveaway-ended").length>0&&(confirm("此页面已经没有key了,是否关闭?")&&(window.close()));

            !empty($(".steam-login"))&&(location.href="/steam/redirect");

            btn_class("btn btn-success btn-sm");

            HCL.ele({ele:"button",parent:div,class:"btn btn-round auto-task btn-theme btn-outline-dark btn-min-width mr-1 mb-1 btn-success btn-sm",title:"一键加入愿望单&关注游戏",onclick:function(){atw_fg(1)},html:"愿望单&关注"});
            HCL.ele({ele:"button",parent:div,class:"btn btn-round auto-task btn-theme btn-outline-dark btn-min-width mr-1 mb-1 btn-success btn-sm",title:"一键移除愿望单&取关游戏",onclick:function(){atw_fg(0)},html:"移除愿望单&取关"});

            var gameArray=[];
            var gameLength=0;
            var gameId=location.href.match(/[\d]+/gim)[0];
            function atw_fg(a=1){
                gameLength=0;
                HCL.id("exInfo").style.display="block";
                var p=info("","",`正在获取游戏列表`);
                //console.log(gameId);
                if(empty(getCookie("game"+gameId))){
                    $("a").map(function(i,e){
                        if(/Wishlist the game|press \"Follow\" button|Add the game to your wishlist/gim.test($(e).text())){
                            w_f(e,a);
                            gameLength++;
                        }
                    });
                    if(a==1){
                        var getGame=setInterval(function(){
                            //console.log(gameArray);
                            //console.log(gameLength);
                            if(unique(gameArray).length>=gameLength){
                                var game=gameArray.join("h");
                                document.cookie="game"+gameId+"="+game+"; path=/";
                                clearInterval(getGame);
                            }
                        },1000);
                    }
                }else{
                    //console.log(unique(getCookie("game"+gameId).split("h")));
                    unique(getCookie("game"+gameId).split("h")).map(function(i){
                        w_f({href:"https://store.steampowered.com/app/"+i},a);
                    });
                }
                addR(p,"OK","success");
            }
            function w_f(e,a){
                httpSend({
                    mode:"gm",
                    url:e.href,
                    type:"get",
                    callback:function(data){
                        var appId=data.finalUrl.match(/[\d]+/)[0];
                        console.log(appId);
                        gameArray.push(appId);
                        if(data.text.indexOf('<a class="menuitem" href="https://store.steampowered.com/login/?')<0){
                            var html=data.text.match(/var g\_sessionID \= \".*?\"\;/gim);
                            if(html.length>0){
                                var sessionID=html[0].match(/\".*?\"/gim)[0].replace(/\"/g,"");
                                a==1?wishlist(appId,sessionID,"addtowishlist"):wishlist(appId,sessionID,"removefromwishlist");
                                a==1?followGame(appId,sessionID,0):followGame(appId,sessionID,1);
                            }else{
                                info("","color:red","sessionID获取失败!");
                            }
                        }else{
                            info("","color:red","请先登录steam!");
                        }
                    }
                });
            }
            function wishlist(appId,sessionID,act){
                var p=info("","",`正在${act=="addtowishlist"?"添加":"移除"}愿望单<a href="https://store.steampowered.com/app/${appId}" target="_blank">${appId}</a>...`);
                httpSend({
                    mode:"gm",
                    url:"https://store.steampowered.com/api/"+act,
                    type:"post",
                    headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
                    data:`sessionid=${sessionID}&appid=${appId}`,
                    callback:function(data){
                        if(!empty(data.text)&&(data.json.success==true)){
                            addR(p,"OK","success");
                        }else{
                            httpSend({
                                mode:"gm",
                                url:"https://store.steampowered.com/app/"+appId,
                                type:"get",
                                callback:function(data){
                                    if(/添加至您的愿望单/.test(data.text)){
                                        /已在库中/.test(data.text)&&(addR(p,"OK","success"));
                                        act=="addtowishlist"?addR(p,"ERROR","err"):addR(p,"OK","success");
                                    }else{
                                        act=="addtowishlist"?addR(p,"OK","success"):addR(p,"ERROR","err");
                                    }
                                }
                            });
                        }
                    }
                });
            }
            function followGame(appId,sessionID,act){
                var p=info("","",`正在${act==0?"关注":"取关"}游戏<a href="https://store.steampowered.com/app/${appId}" target="_blank">${appId}</a>...`);
                httpSend({
                    mode:"gm",
                    url:"https://store.steampowered.com/explore/followgame/",
                    type:"post",
                    headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
                    data:`sessionid=${sessionID}&appid=${appId}&unfollow=${act}`,
                    callback:function(data){
                        if(!empty(data.text)&&(data.text=="true")){
                            addR(p,"OK","success");
                        }else{
                            httpSend({
                                mode:"gm",
                                url:"https://store.steampowered.com/app/"+appId,
                                type:"get",
                                callback:function(data){
                                    if(data.text.indexOf(`class="btnv6_blue_hoverfade btn_medium queue_btn_active" style="">`)>-1){
                                        act==0?addR(p,"OK","success"):addR(p,"ERROR","err");
                                    }else{
                                        act==0?addR(p,"ERROR","err"):addR(p,"OK","success");
                                    }
                                }
                            });
                        }
                    }
                });
            }

            //giveaway.su按钮定义
            HCL.id("doTask").onclick=function(){
                HCL.id("exInfo").style.display="block";
                info("","color:yellow;background-color:black",`只会自动做加steam组和关注鉴赏家任务(需要<a href="https://greatest.deepsurf.us/zh-CN/scripts/34764-giveaway-helper" target="_blank">Giveaway Helper脚本</a>,没有则自动跳过此步骤),其他任务需手动完成!`);
                if($("a.pull-right").length>0&&$("a.pull-right").parent().parent()[0].className!="hidden"){
                    $("a.pull-right")[0].click();
                    return false;
                }
                $('tr[data-action-id="adjs"]').remove();
                $('a[data-type="link"]').attr("href","javascript:void(0)");
                $('a[data-type="link"]').find("i").click();
                $("a.btn-success").removeClass("disabled");
                $('button>span:contains("Join ")').click();
                $('button>span:contains("Follow ")').click();
                doTask(function(){giveaway_su_verify($("i.glyphicon-refresh"),0)},new Date().getTime(),($('button>span:contains("Join ")').length+$('button>span:contains("Follow ")').length)*3);
            };
            HCL.id("Verify").onclick=function(){
                HCL.id("exInfo").style.display="block";
                info("","color:yellow;background-color:black",`只会循环验证任务,未完成的任务需手动完成!`);
                $('tr[data-action-id="adjs"]').remove();
                $('a[data-type="link"]').attr("href","javascript:void(0)");
                $('a[data-type="link"]').find("i").click();
                $("a.btn-success").removeClass("disabled");
                giveaway_su_verify($("i.glyphicon-refresh"),0);
            };

            //giveaway.su验证任务
            function giveaway_su_verify(vBtn,i){
                if(vBtn.length==0){
                    $("a.btn-success").click();
                }else{
                    if(!/glyphicon-ok/gim.test(vBtn[i].className)){
                        vBtn.eq(i).parent().attr("disabled");
                        vBtn.eq(i).parent().removeAttr("disabled");
                        vBtn.eq(i).parent().click();
                    }
                    i++;
                    setTimeout(function(){i<vBtn.length?giveaway_su_verify(vBtn,i):giveaway_su_verify($("i.glyphicon-refresh"),0)},2000);
                }
            }
        }


        if(/gleam/.test(url)){//gleam领key

            btn_class("btn btn-primary")

            //gleam按钮定义
            HCL.id("doTask").onclick=function(){
                HCL.id("exInfo").style.display="block";
                $('button>span:contains("Join ")').click();
                $('button>span:contains("Follow ")').click();
                doTask(function(){
                    gleam_do_task($("a.enter-link"),0);
                },new Date().getTime(),($('button>span:contains("Join ")').length+$('button>span:contains("Follow ")').length)*3);
            };
            HCL.id("Verify").onclick=function(){
                HCL.id("exInfo").style.display="block";
                gleam_do_task($("a.enter-link"),0);
            };

            //gleam做任务+验证任务
            function gleam_do_task(a,i,t=0){
                if(i<a.length){
                    if((!/check/gim.test($("a.enter-link").eq(i).children(".tally").find("i.fa")[0].className)&&(!(t==0&&/on twitter/gim.test($("a.enter-link").eq(i).text()))))){
                        a[i].click();
                        setTimeout(function(){
                            if(!/default/.test(a[i].className)){
                                var btn=a.eq(i).next().find(".btn-primary");
                                var link=a.eq(i).next().find("a.btn-info.btn-embossed");
                                var href=link.attr("href");
                                link.attr("href","javascript:void(0)");
                                link[0]!=undefined&&(link[0].click());
                                link.attr("href",href);
                                if(/[\d]/i.test(btn.text())){
                                    gleam_time(a,btn.text(),i,btn);
                                }else{
                                    btn[0].click();
                                    i++;
                                    gleam_do_task(a,i,t);
                                }
                            }else{
                                i++;
                                gleam_do_task(a,i,t);
                            }
                        },1000);
                    }else{
                        i++;
                        gleam_do_task(a,i,t);
                    }
                }else{
                    t==0?gleam_do_task($("a.enter-link"),0,1):info("","","任务验证完成,若有未完成任务请手动完成!");
                }
            }

            //gleam做有时间限制任务
            function gleam_time(a,t,i,b){
                var time=t.match(/\-?[\d]+/gim)[0];
                if(time>0){
                    window.open("https://www.hclonely.cn/time.html?time="+time,"_blank");
                    var hidden=setInterval(function(){
                        if(!document.hidden){
                            clearInterval(hidden);
                            setTimeout(function(){
                                b[0].click();
                                i++;
                                gleam_do_task(a,i);
                            },1000);
                        }
                    },1000);
                }else{
                    b[0].click();
                    i++;
                    gleam_do_task(a,i);
                }
            }
        }

        if(/gamehunt/.test(url)){//gamehunt领key

            $(".card-title").text()=="0"&&(confirm("此页面已经没有key了,是否关闭?")&&(window.close()));

            $("a.nav-link.btn-outline-secondary").length>0&&(location.href="/auth/vkontakte");

            btn_class("btn btn-outline-secondary btn-sm");

            //gamehunt按钮定义
            HCL.id("doTask").onclick=function(){
                gamehunt(1);
            };
            HCL.id("Verify").onclick=function(){
                gamehunt(0);
            };
            function gamehunt(o){
                HCL.id("exInfo").style.display="block";
                info("","color:yellow;background-color:black",'只会自动做"Go to"任务(可能需要多次点击才能完成所有此任务),其他任务请手动完成!');
                autoOpen==1&&o==1&&(info("","color:yellow;background-color:black",'请关闭弹窗拦截,否则不会自动打开任务页面!'));
                httpSend({
                    url:"https://gamehunt.net/end/distribution",
                    type:"post",
                    timeout:15000,
                    data:{id:location.href.match(/[\d]+/gim)[0]},
                    callback:function(data){
                        if(data.status==200){
                            if(data.json.err=="err"&&data.json.res.length>0){
                                $("a.btn-info[id]").css("background-color","#17a2b8");
                                data.json.res.map(function(e){
                                    $("#"+e).css("background-color","red");
                                    /Go to/gim.test($("#"+e).text())&&(visitLink(e));
                                    if(autoOpen==1&&o==1){
                                        if(!/Go to/gim.test($("#"+e).text())){
                                            window.open($("#"+e).attr("href"),"_blank");
                                        }
                                    }
                                });
                            }else if(data.json.err=="err01"){
                                info("","color:red","I thought about it and I will not give you a key, since you already received it!");
                            }else if(data.json.err=="0"){
                                info("","color:green","Steam Key:"+data.json.res);
                            }else if(data.json.err=="01"){
                                info("","color:red","你已经获取过key了!");
                            }else if(data.json.err=="02"){
                                info("","color:red","已经没有key了!");
                            }else{
                                info("","color:red","未知错误码:"+data.json.err);
                                HCL.id("go_geme").click();
                            }
                        }
                    }
                });
            }
            function visitLink(e){
                var p=info("","",`正在做浏览网页任务<a href="${$("#"+e).attr("href")}" target="_blank">${e}</a>...`);
                httpSend({
                    mode:"gm",
                    type:"get",
                    url:$("#"+e).attr("href"),
                    callback:function(data){
                        $("#"+e).css("background-color","#17a2b8");
                        addR(p,"ok","success");
                    }
                });
            }
        }

        if(/orlygift/.test(url)){//orlygift

            /login/gim.test($(".navbar-right").text())&&(location.href="https://www.orlygift.com/steam_connect");

            btn_class("btn btn-block btn-info");

            //防止广告弹窗
            var expireDate = new Date();
            expireDate.setDate(expireDate.getDate() + 7);
            document.cookie='bounceback-visited-user=1;expires='+expireDate+'path=/';

            //orlygift按钮定义
            HCL.id("doTask").onclick=function(){
                HCL.id("exInfo").style.display="block";
                info("","color:yellow;background-color:black","安装app和邀请好友任务不会自动完成!");
                var ogTaskId=og_get_id();
                og_do_task(ogTaskId,0);
            }
            HCL.id("Verify").onclick=function(){
                HCL.id("exInfo").style.display="block";
                var ogTaskId=og_get_id();
                og_verify(ogTaskId,0);
            }

            //orlygift获取任务id
            function og_get_id(){
                var ogTaskBtn=$("button.btn-block.btn-info[id]").not(".ng-hide").not(".auto-task");
                var ogTaskId=[];
                ogTaskBtn.map(function(i,e){!/(install.*?app)|(Invite your friends)/gim.test($(e).parent().parent().text())&&(ogTaskId.push($(e).attr("id").replace("task-","")))});
                return ogTaskId;
            }

            //orlygift做任务
            function og_do_task(ogTaskId,i){
                if(i<ogTaskId.length){
                    var p=info("","",`正在做任务${ogTaskId[i]}...`);
                    ga("send", "pageview", "/task/open/" + ogTaskId[i]);
                    var ogTaskType=$("#task-"+ogTaskId[i]).parent().parent().parent().attr("class").replace("item ","");
                    var handleApiCall = function(url) {httpSend({mode:"gm",type:"get",url:url})};
                    switch (ogTaskType) {
                        case "steam_curator":
                        case "steam_group":
                        case "invite":
                        case "link":
                        case "ad2games":
                        case "offertoro":
                        case "greenlight":
                        case "youtube":
                        case "steam_group_invite":
                        case "orlygift_mobile_app":
                        case "orlydealz":
                        case "orlyaccess":
                        case "newsletter":
                            handleApiCall(window.location.origin + "/api/task/open/" + ogTaskId[i]);
                            break;
                    }
                    setTimeout(function(){
                        addR(p,"finished","other");
                        i++;
                        og_do_task(ogTaskId,i);
                    },Math.floor(Math.random() * 1000));
                }else{
                    og_verify(ogTaskId,0);
                }
            }

            //orlygift验证任务
            function og_verify(ogTaskId,i){
                if(i<ogTaskId.length){
                    var p=info("","",`正在验证任务${$("#task-"+ogTaskId[i]).parent().parent().find("h4[ng-show]").text()}...`);
                    ga("send", "pageview", "/task/check/" + ogTaskId[i]);
                    setTimeout(function(){
                        httpSend({
                            url:"/api/task/check/" + ogTaskId[i],
                            type:"post",
                            callback:function(data){
                                if(data.json.result=="success"){
                                    addR(p,"success");
                                }else if(data.json.result=="pending"){
                                    addR(p,data.json.message,"info");
                                }else{
                                    addR(p,"error","err");
                                }
                                i++;
                                setTimeout(function(){og_verify(ogTaskId,i)},Math.floor(Math.random() * 1000));
                            }
                        })
                    },Math.floor(Math.random() * 1000));
                }else{
                    location.reload(true);
                }
            }
        }

        if(/indiedb/.test(url)){//indiedb领key

            empty($("a.buttonenter.buttongiveaway"))&&(location.href="/members/register");

            //indiedb按钮定义
            HCL.id("doTask").onclick=function(){
                HCL.id("exInfo").style.display="block";
                indiedb_join();
            };
            HCL.id("Verify").onclick=function(){
                HCL.id("exInfo").style.display="block";
                indiedb_do_task();
            };

            //indiedb加入赠key
            function indiedb_join(){
                if(/join giveaway/gim.test($("a.buttonenter.buttongiveaway").text())){
                    var p=info("","","正在加入赠key...");
                    httpSend({type:"post",url:$("a.buttonenter.buttongiveaway").attr("href"),data:{ajax: 't'},callback:function(data){if(data.status==200&&data.json.success==true){
                        addR(p,"ok");
                        indiedb_do_task();
                    }else{
                        addR(p,"失败!请手动加入赠key!","err");
                    }}});
                    $(".buttongiveaway").saveUpdate("auth", enterGiveaway);
                    $(".buttongiveaway").addClass("buttonentered").text("Success - Giveaway joined");
                }else if(/success/gim.test($("a.buttonenter.buttongiveaway").text())){
                    indiedb_do_task();
                }else{
                    info("","color:red","请检查是否已加入次赠key!");
                }
            }

            //indiedb做任务
            function indiedb_do_task(){
                $("#giveawaysjoined").show();
                var id=$("script").map(function(i,e){
                    if(/\$\(document\)/gim.test(e.innerHTML)){
                        var optionId=e.innerHTML.match(/\"\/newsletter\/ajax\/subscribeprofile\/optin\/[\d]+\"/gim)[0].match(/[\d]+/)[0];
                        var taskId=e.innerHTML.match(/\"\/[\d]+\"/gim)[0].match(/[\d]+/)[0];
                        return [taskId,optionId];
                    }
                });
                if(id.length==2){
                    $("#giveawaysjoined>div>p").find("a").map(function(i,e){
                        var promo=$(e);
                        if(!promo.hasClass("buttonentered")){
                            var p=info("","",`正在做任务:${$(e).parents("p").text()}...`);
                            if(/facebookpromo|twitterpromo|visitpromo/gim.test(e.className)){
                                $.ajax({
                                    type: "POST", url: urlPath("/giveaways/ajax/"+(promo.hasClass("facebookpromo") ? "facebookpromo" : (promo.hasClass("twitterpromo") ? "twitterpromo" : "visitpromo"))+"/"+id[0]), timeout: 60000, dataType: "json",
                                    data: {ajax: "t"},
                                    error: function(response, error, exception) {
                                        addR(p,"An error has occurred performing the action requested. Please try again shortly.","err");
                                    },
                                    success: function(response) {
                                        if(response["success"]) {
                                            addR(p,response["text"]);
                                            promo.addClass("buttonentered").closest("p").html(promo.closest("p").find("span").html());
                                        } else {
                                            addR(p,response["text"],"err");
                                        }
                                    }
                                });
                            }else if(promo.hasClass("emailoptinpromo")){
                                $.ajax({
                                    type: "POST", url: urlPath("/newsletter/ajax/subscribeprofile/optin/"+id[1]), timeout: 60000, dataType: "json",
                                    data: {ajax: "t",emailsystoggle: 4},
                                    error: function(response, error, exception) {
                                        addR(p,"An error has occurred performing the action requested. Please try again shortly.","err");
                                    },
                                    success: function(response) {
                                        if(response["success"]) {
                                            addR(p,response["text"]);
                                            promo.toggleClass("buttonentered").closest("p").html(promo.closest("p").find("span").html());
                                        } else {
                                            addR(p,response["text"],"err");
                                        }
                                    }
                                });
                            }else if(promo.hasClass("watchingpromo")){
                                var data=getUrlQuery($(e).attr("href"));
                                data.ajax="t";
                                $.ajax({
                                    type: "POST", url: urlPath($(e).attr("href").replace(/\?.*/,"")), timeout: 60000, dataType: "json",
                                    data: data,
                                    error: function(response, error, exception) {
                                        addR(p,"An error has occurred performing the action requested. Please try again shortly.","err");
                                    },
                                    success: function(response) {
                                        if(response["success"]) {
                                            addR(p,response["text"]);
                                            promo.toggleClass("buttonentered").closest("p").html(promo.closest("p").find("span").html());
                                            $(e).saveUpdate("watch", giveawayWatch);
                                            $(e).addClass("buttonentered");
                                        } else {
                                            addR(p,response["text"],"err");
                                        }
                                    }
                                });
                            }else if(!/the-challenge-of-adblock/gim.test($(e).attr("href"))){//watchingpromo
                                $.ajax({
                                    type: "POST", url: urlPath($(e).attr("href")), timeout: 60000, dataType: "json",
                                    data: {ajax: "t"},
                                    error: function(response, error, exception) {
                                        addR(p,"An error has occurred performing the action requested. Please try again shortly.","err");
                                    },
                                    success: function(response) {
                                        if(response["success"]) {
                                            addR(p,response["text"]);
                                            promo.toggleClass("buttonentered").closest("p").html(promo.closest("p").find("span").html());
                                        } else {
                                            addR(p,response["text"],"err");
                                        }
                                    }
                                });
                            }else{
                                addR(p,"此任务为花钱订阅任务,脚本自动跳过!","info");
                            }
                        }else{
                            info("","",`正在做任务:${$(e).parents("p").text()}...<font style="color:green">ok</font>`);
                        }
                    });
                    info("","color:yellow;background-color:black","所有任务验证完成,没有完成的任务请手动完成!");
                }else{
                    info("","color:red","获取id失败,请重试!")
                }
            }
        }

        if(/spoune/.test(url)){//spoune领key

            //$("#loginRightTop").length>0&&(window.open("https://www.spoune.com/login.php","_self"));

            //$("#keysAvailable").text()==0&&(confirm("此页面已经没有key了,是否关闭?")&&(window.close()));
            btn_class("ui big inverted download button");

            HCL.id("doTask").onclick=function(){
                HCL.id("exInfo").style.display="block";
                spoune_get_task();
            };
            HCL.id("Verify").onclick=function(){
                HCL.id("exInfo").style.display="block";
                spoune_get_task();
            };

            //spoune获取任务信息
            function spoune_get_task(){
                if($("#GiveawayTasks>button.grey").length!=$("#submain3").text()-$("#submain1").text()){
                    objFrame.objCurrentScriptObject.loadTaskOverview('GiveawayTasks');
                    var getButton=setInterval(function(){
                        if($("#GiveawayTasks>button.grey").length==$("#submain3").text()-$("#submain1").text()){
                            clearInterval(getButton);
                            show_task($("#GiveawayTasks>button.grey"),0);
                        }
                    },1000);
                }else{
                    show_task($("#GiveawayTasks>button.grey"),0);
                }
            }

            //spoune显示任务详情
            function show_task(e,i){
                if(i<e.length){
                    eval($(e).eq(i).attr("onclick"));
                    var getIframe=setInterval(function(){
                        if($("iframe").contents().find("#link").length>0){
                            clearInterval(getIframe);
                            spoune_verify(e,i);
                        }
                    },1000);
                }else{
                    info("","color:yellow;background-color:black","所有任务验证完成,没有完成的任务请手动完成!");
                    objFrame.objCurrentScriptObject.loadTaskOverview('GiveawayTasks');
                    $("#GiveawayBackButton")[0].style.visibility="hidden";
                }
            }

            //spoune验证任务
            function spoune_verify(t,i,e=0){
                var p=info("","","正在验证任务:"+$(t).eq(i).text()+"...");
                httpSend({
                    type:"get",
                    url:$("iframe").contents().find("#link").attr("href").replace("./","./werbung/"),
                    callback:function(data){
                        if(data.status==200){
                            if(/Task completed/gim.test(data.text)){
                                addR(p,"ok");
                                e=1;
                            }else{
                                $("iframe").contents().find("html").html(data.text);
                                e==0?setTimeout(function(){
                                    $(p).remove();
                                    spoune_verify(t,i,1);
                                },1500):addR(p,"error","err");
                            }
                        }else{
                            e==0?setTimeout(function(){
                                $(p).remove();
                                spoune_verify(t,i,1);
                            },1500):addR(p,`error:${data.status}`,"err");
                        }
                        e==1&&(show_task(t,++i));
                    }
                });
            }
        }


        //if(/chubbykeys/.test(url)){//chubbykeys领key
        /*
        if($("button.btn-lg.hvr-grow-rotate").length>0){
            location.href="?login";
           }

        btn_class("btn btn-outline-primary");

        //chubbykeys按钮定义
        HCL.id("doTask").onclick=function(){
                HCL.id("exInfo").style.display="block";
            $('button>span:contains("Join ")').click();
            $('button>span:contains("Follow ")').click();
            doTask(function(){
            },new Date().getTime(),($('button>span:contains("Join ")').length+$('button>span:contains("Follow ")').length)*3);
        };
        HCL.id("Verify").onclick=function(){
        };
    }
    */

        HCL.ele({ele:"button",parent:div,class:"btn btn-round auto-task btn-theme btn-outline-dark btn-min-width mr-1 mb-1 btn-success btn-sm",id:"Setting",title:"设置",onclick:setting,text:"⚙设置"});
        var settingDiv=HCL.ele({ele:"div",parent:div,class:"setting",style:"display:none",html:`<h4 align="center">全局设置</h4><p><input id="allAutoOpen" type="checkbox" ${autoOpen==1?"checked":""} />自动打开任务页面</p><button id="settingSave" style="width:48px;margin:0 33%">保存</button>`});
        HCL.id("settingSave").onclick=function(){
            HCL.id("allAutoOpen").checked?GM_setValue("autoTaskSetting",1):GM_setValue("autoTaskSetting",0);
            autoOpen=GM_getValue("autoTaskSetting");
            HCL.id("exInfo").style.display="block";
            info("","color:green","保存成功!");
        };
        function setting(){
            autoOpen=isset(GM_getValue("autoTaskSetting"))?GM_getValue("autoTaskSetting"):1;
            settingDiv.style.display=="none"?settingDiv.style.display="block":settingDiv.style.display="none";
            //console.log(autoOpen);
        }

        //做加组、关注等任务
        function doTask(callback,time,limitTime){
            $('button>span:contains("Join ")').length+$('button>span:contains("Follow ")').length==0||new Date().getTime()-time>limitTime*1000?callback():setTimeout(function(){doTask(callback,time,limitTime)},300);
        }

        //做退组、取关等任务
        HCL.id("Remove").onclick=function(){
            HCL.id("exInfo").style.display="block";
            info("","",`正在退组、取关,请稍候!`);
            $('button>span:contains("Leave ")').click();
            $('button>span:contains("Unfollow ")').click();
        };

        //显示信息
        function info(cText,sText,iText){
            var p=HCL.ele({ele:"p","class":cText,"style":sText,html:iText,parent:div2});
            p.scrollIntoView();
            return p;
        }

        //任务执行结果
        function addR(p,t,r="success"){
            switch(r){
                case "success":
                    p.innerHTML+=`<font style='color:green'>${t}</font>`;
                    break;
                case "info":
                    p.innerHTML+=`<font style='color:yellow;background-color:black'>${t}</font>`;
                    break;
                case "err":
                    p.innerHTML+=`<font style='color:red'>${t}</font>`;
                    break;
                default:
                    p.innerHTML+=`<font style='color:yellow'>${t}</font>`;
                    break;
            }
        }

        //button样式
        function btn_class(e){
            var task_btn=HCL.class("auto-task");
            for(var tb=0;tb<task_btn.length;tb++){
                task_btn[tb].setAttribute("class", e+" auto-task");
            }
        }

        //防止弹出新窗口
        function banNewBlock(){
            var d=new Date();
            var cookiename = "haveVisited1";
            //document.cookie = "haveVisited=1; path=/";
            //document.cookie = "lastVisit=" + (d.getUTCMonth()+1) +"/"+ d.getUTCDate() + "/" + d.getUTCFullYear() + "; path=/";
            document.cookie = cookiename + "=1; path=/";
            document.cookie = cookiename + "=" + (d.getUTCMonth()+1) + "/" + d.getUTCDate() + "/" + d.getUTCFullYear() + "; path=/";
        }

        //读取cookie
        function getCookie(name=""){
            var cookies=document.cookie;
            var cookieArray=cookies.split(/; ?/);
            var cookie={};
            for (var i=0;i<cookieArray.length;i++){
                var ck=cookieArray[i].split("=");
                cookie[ck[0]]=ck[1];
            }
            if(name==""){
                return cookie;
            }else{
                return cookie[name];
            }
        }
    }catch(e){
        HCL.c.l2("自动任务脚本出错: \n",e,"background: red; border-radius: 3px; color: #fff; padding: 0 8px","background: blue; border-radius: 3px; color: #fff; padding: 0 8px");
        confirm("自动任务脚本出错! \n点击确定复制错误信息,或打开控制台查看错误信息!")&&(HCL.copy(e.stack));
    }
})();