自动任务

自动完成marvelousga,dupedornot,gamecode等网站访问网页任务,自动验证所有任务

Versione datata 28/11/2018. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         自动任务
// @namespace    http://tampermonkey.net/
// @version      0.8.1
// @description  自动完成marvelousga,dupedornot,gamecode等网站访问网页任务,自动验证所有任务
// @author       HCLonely
// @include      *://www.grabfreegame.com/giveaway/*
// @include      *://gamecode.win/giveaway/*
// @include      *://whosgamingnow.net/giveaway/*
// @include      *://marvelousga.com*
// @include      *://dupedornot.com*
// @include      *://gamezito.com*
// @include      *://www.grabfreegame.com/login*
// @include      *://www.bananagiveaway.com/login*
// @include      *://www.bananagiveaway.com/giveaway/*
// @include      *://gamecode.win/login*
// @include      *://whosgamingnow.net/login*
// @run-at       document-end
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    //var autoRedeem=1;//1为自动激活;改为0则不自动激活//此功能已不可用
    var autoOpen=1;//1为自动打开任务页面;改为0则不打开任务页面

    if(/You need to be logged in to perform all tasks|Please login to see the tasks/gim.test(document.getElementsByTagName("body")[0].innerText)){
        window.location.href="/login";
        return 0;
    }
    var url=window.location.href;
    var t=0;
    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:10)));
    var game=url.replace(/https?:\/\/(www)?(marvelousga|dupedornot|gamezito|gamecode).(com|win)\/giveaway\/|/,"");

    GM_addStyle(`
#doTaskDiv{position:fixed;right:80px;top:${height}px;width:85px;z-index: 99999999999;}
#info{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}
#doTask{width:145px;height:40px;${bg}}
#Verify{width:145px;height:40px;${bg}}
`);

    var div=document.createElement("div");
    div.setAttribute("id", "doTaskDiv");
    div.setAttribute("class", "card-content");
    div.innerHTML=`<button id="doTask" class="btn btn-round auto-task btn-theme btn-outline-dark btn-min-width mr-1 mb-1">FuckTask</button>
<button id="Verify" class="btn btn-round auto-task btn-theme btn-outline-dark btn-min-width mr-1 mb-1">Verify</button>`;
    var div3=document.createElement("div");
    div3.setAttribute("id", "exInfo");
    var div2=document.createElement("div");
    div2.setAttribute("id", "info");
    div2.setAttribute("class", "card-body card");
    //div2.setAttribute("style", "position:fixed;right:50px;bottom:10px;max-width:600px;max-height:400px;overflow-y:auto;z-index: 99999999999;display:none");
    div3.innerHTML=`<span class="infos"><a id="shouqi" class="zhankai" href="javascript:;"" title="收起">↘</a></span>`;
    document.getElementsByTagName("body")[0].appendChild(div);
    div3.appendChild(div2);
    document.getElementsByTagName("body")[0].appendChild(div3);
    document.getElementById("shouqi").onclick=function(e){
        e=document.getElementById("shouqi").className=="zhankai"?["20px","↖","展开","shouqi"]:["","↘","收起","zhankai"];
        div3.style.width=e[0];
        div3.style.height=e[0];
        document.getElementById("shouqi").innerText=e[1];
        document.getElementById("shouqi").setAttribute("title", e[2]);
        document.getElementById("shouqi").setAttribute("class", e[3]);
    }


    //防止弹出新窗口
    window.onload=function(){
        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=/";
    }

    //防止419
    function token(){
        var btn=document.getElementsByTagName("button");
        for(var j=0;j<btn.length;j++){
            if(/task/gim.test(btn[j].id)&&btn[j].id!="doTask"){
                btn[j].click();
                return 1;
            }
        }
    }

    //显示信息
    function info(cText,sText,iText){
        var p=document.createElement("p");
        p.setAttribute("class", cText);
        p.setAttribute("style", sText);
        p.innerHTML=iText;
        div2.appendChild(p);
        p.scrollIntoView();
        return p;
    }

    //浏览页面任务
    function webpage(taskId,e,text){
        var p=info("card-text monospace","",`开始任务${taskId}:${text}...`);
        $.ajax({
            type: "post",
            url: "/ajax/verifyTasks/webpage/clickedLink",
            datatype: "json",
            data:{
                giveaway_slug: game,
                giveaway_task_id: taskId
            },
            crossDomain:true,
            xhrFields: {
                withCredentials: true
            },
            success: function (data) {
                if(data.status==1){
                    document.getElementById("task_webpage_visit_"+taskId).innerText="OK";
                    p.innerHTML+="<font style='color:green'>OK!</font>";
                }else{
                    var msg=data.message||"ERROR";
                    p.innerHTML+=`<font style='color:red'>${msg}!</font>`;
                }
                e===t&&(getId());
            },
            error:function(jqXHR, textStatus, errorThrown){
                p.innerHTML+=`<font style='color:red'>${textStatus}:${jqXHR.status}-${errorThrown}</font>`;
                e===t&&(getId());
            }
        });
    }

    var task_id=[];
    var api_id=[];
    var btn_id=[];
    var p_id=[];

    //获取任务id
    function getId(){
        var btn=document.getElementsByTagName("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(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();
        }
    }

    //验证任务
    function verify(e,v=0){
        if(/visit[\w\W]*?webpage/gim.test(p_id[e])&&v==1){
            e++;
            verify(e,v);
            return;
        }else if(/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)){
            document.getElementById(btn_id[e]).removeAttribute("disabled");
            document.getElementById(btn_id[e]).click();
        }
        if(/visit[\w\W]*?webpage/.test(p_id[e])&&v==1){
        }else{
            $.ajax({
                type: "post",
                url: "/ajax/verifyTasks/"+api_id[e],
                datatype: "json",
                data:{
                    giveaway_slug: game,
                    giveaway_task_id: task_id[e]
                },
                crossDomain:true,
                xhrFields: {
                    withCredentials: true
                },
                success: function (data) {
                    if(data.status==1){
                        document.getElementById(btn_id[e]).innerText="VERIFIED";
                        p.innerHTML+="<font style='color:green'>OK!</font>--<font style='color:blue'>"+data.percentageNanoBar+"%</font>";
                    }else{
                        document.getElementById(btn_id[e]).innerText="ERROR!";
                        document.getElementById(btn_id[e]).style.color="red";
                        /gamezito/gim.test(url)?document.getElementById(btn_id[e]).parentNode.parentNode.getElementsByTagName("a")[0].click():document.getElementById(btn_id[e]).parentNode.getElementsByTagName("a")[0].click();
                        var msg=data.message||"ERROR";
                        p.innerHTML+=`<font style='color:red'>${msg}!</font>`;
                    }
                    e++;
                    if(data.percentageNanoBar==100||e>=btn_id.length){
                        info("card-text monospace","color:green",`所有任务验证完成!`);
                        getKey();
                    }else{
                        verify(e,v);
                    }
                },
                error:function(jqXHR, textStatus, errorThrown){
                    document.getElementById(btn_id[e]).innerText="ERROR!";
                    document.getElementById(btn_id[e]).style.color="red";
                    jqXHR.status!=419&&(document.getElementById(btn_id[e]).parentNode.getElementsByTagName("a")[0].click());
                    p.innerHTML+=`<font style='color:red'>${textStatus}:${jqXHR.status}-${errorThrown}</font>`;
                    e++;
                    if(e<btn_id.length){
                        verify(e);
                    }else{
                        info("card-text monospace","color:green",`所有任务验证完成!`);
                        getKey();
                    }
                }
            });
        }
    }

    //获取steamkey
    function getKey(){
        if(/your[\s]*?key[\w\W]*?[\w\d]{5}(-[\w\d]{5}){2}/gim.test(document.getElementsByTagName("body")[0].innerText)){
            info("card-text monospace","",`你已经领取过key了!`);
            return 0;
        }
        //if(/https?:\/\/(gamezito|marvelousga).com\/giveaway\/[\w\W]*/.test(url)){
        info("card-text monospace","",`请手动完成谷歌验证获取key!`);
        document.getElementById("get_key_container").style.display="block";
        document.getElementById("get_key_container").scrollIntoView();
        /*}else{
            var p=info("card-text monospace","",`获取key...`);
            $.ajax({
                type: "post",
                url: "/ajax/keys/get/key",
                datatype: "json",
                data:{
                    giveaway_slug: game,
                },
                crossDomain:true,
                xhrFields: {
                    withCredentials: true
                },
                success: function (data) {
                    var key=data.key||"";
                    if(data.status==1&&/[\d\w]{5}(\-[\d\w]{5}){2}/.test(data.key)){
                        p.innerHTML+="<font style='color:green'>OK!</font>";
                        info("card-text monospace","",`YOUR KEY : <a href="https://store.steampowered.com/account/registerkey?key=${data.key}" target="_blank">${data.key}</a>`);
                        autoRedeem==1&&(window.open("https://store.steampowered.com/account/registerkey?key="+data.key,"_blank"));
                    }else{
                        var msg=data.message||"ERROR";
                        p.innerHTML+=`<font style='color:red'>${msg}!</font>`;
                    }
                },
                error:function(jqXHR, textStatus, errorThrown){
                    p.innerHTML+=`<font style='color:red'>${textStatus}:${jqXHR.status}-${errorThrown}</font>`;
                }
            });
        }*/
    }

    if(/https?:\/\/(marvelousga|dupedornot|gamezito).com\/giveaway\/[\w\W]*/.test(url)){
        document.getElementById("doTask").onclick=function(){
            document.getElementById("exInfo").style.display="block";
            t=0;
            var crsf=token();
            if(crsf===1){
                var a=document.getElementsByTagName("a");
                for(var i=0;i<a.length;i++){
                    var parent=a[i].parentNode.parentNode;
                    if(a[i].innerText==="this"&&/task_webpage_clickedLink_[\d]*/.test(a[i].id)&&!/verified/i.test(parent.getElementsByTagName("button")[0].innerText)){
                        var taskId=a[i].id.replace("task_webpage_clickedLink_","");
                        var text=a[i].parentNode.innerHTML.replace(/id\=\"[\w\W]*?\"/i,"");
                        t++;
                        webpage(taskId,t,text);
                    }
                }
                t==0&&(getId());
            }
        };
        document.getElementById("Verify").onclick=function(){
            document.getElementById("exInfo").style.display="block";
            task_id=[];
            api_id=[];
            btn_id=[];
            p_id=[];
            var crsf=token();
            crsf===1&&(getId());
        };
    }


    var verify_btn=[];
    var do_btn=[];

    //获取任务id
    function getBtn(e){
        var btn=document.getElementsByTagName("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"&&(doTask(0));
        verify_btn.length>0&&e==="v"&&(verify_1(0));
    }

    //做任务
    function doTask(e){
        var taskId=do_btn[e].match(/\?q\=[\d]+/)[0];
        taskId=taskId.replace("?q=","");
        var p=info("code","",`执行任务:${taskId}...`);
        $.ajax({
            type: "get",
            url: do_btn[e],
            timeout:"10000",
            datatype: "json",
            crossDomain:true,
            xhrFields: {
                withCredentials: true
            },
            complete: function (data) {
                p.innerHTML+="<font style='color:green'>OK!</font>";
                e++;
                e<do_btn.length?doTask(e):(verify_btn.length>0&&(verify_1(0)));
            }
        });
    }

    //验证任务
    function verify_1(e){
        var taskId=verify_btn[e].match(/\?verify\=[\d]+/)[0];
        taskId=taskId.replace("?verify=","");
        var p=info("code","",`验证任务:${taskId}...`);
        $.ajax({
            type: "get",
            url: verify_btn[e],
            timeout:"10000",
            datatype: "json",
            crossDomain:true,
            xhrFields: {
                withCredentials: true
            },
            complete: function (data) {
                p.innerHTML+="<font style='color:green'>OK!</font>";
                e++;
                e<verify_btn.length?verify_1(e):window.location.href=url;
            }
        });
    }

    if(/https?:\/\/www.(grabfreegame|bananagiveaway).com\/giveaway\/[\w\W]*/.test(url)){
        document.getElementById("doTask").onclick=function(){
            document.getElementById("exInfo").style.display="block";
            verify_btn=[];
            do_btn=[];
            getBtn("d");
        };
        document.getElementById("Verify").onclick=function(){
            document.getElementById("exInfo").style.display="block";
            verify_btn=[];
            do_btn=[];
            getBtn("v");
        };
        div2.setAttribute("style", `position:fixed;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;`);

        var g_task_url=[];
        var g_task_id=[];
        var g_task_ok=[];
        //做&验证任务
        function g_do_task(e){
            var p=info("code","",`验证任务:${g_task_id[e]}...`);
            $.ajax({
                type: "post",
                url: g_task_url[e],
                datatype: "json",
                data:{
                    giveawayID: game,
                    taskID: g_task_id[e]
                },
                crossDomain:true,
                xhrFields: {
                    withCredentials: true
                },
                complete: function (data) {
                    var msg,task,zz;
                    var status=data.status==200?(data.responseJSON==undefined?0:(data.responseJSON.status==1?1:0)):0;
                    console.log(data);
                    if(status==1){
                        p.innerHTML+="<font style='color:green'>OK!</font>";
                        if(e==g_task_id.length-1){
                            g_task_ok[e].getElementsByTagName("button")[1].click();
                        }
                        g_task_ok[e].innerHTML=`<i class="fa fa-check checkMarkAfterCompleteTask"></i>`;
                    }else{
                        msg=data.message||"ERROR";
                        task=g_task_ok[e].getElementsByTagName("a")[0];
                        zz=document.createElement("div");
                        zz.appendChild(task);
                        task=zz.innerHTML;
                        p.innerHTML+=`<font style='color:red'>${msg}!</font>${task}`;
                    }
                    p.scrollIntoView();
                    e++;
                    e<g_task_id.length?g_do_task(e):(div2.getElementsByTagName("button").length>0?info("card-text monospace","color:red",`有任务未完成或验证失败,请手动完成任务之后在验证!`):info("card-text monospace","color:green",`所有任务验证完成,请手动完成谷歌验证获取key!`));
                }
            });
        }
    }

    //wgn领key
    if(/https?:\/\/whosgamingnow.net\/giveaway\/[\w\W]*/.test(url)){
        btn_class("btn btn-primary");
        function wsn_enter(){
            $.ajax({
                type: "post",
                url: url,
                datatype: "json",
                data:{
                    submit: "Enter",
                },
                crossDomain:true,
                xhrFields: {
                    withCredentials: true
                },
                success: function (data) {
                    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);
                },
                error:function(jqXHR, textStatus, errorThrown){
                    alert(textStatus+":"+jqXHR.status+"-"+errorThrown);
                }
            });
        }
        document.getElementById("doTask").onclick=function(){
            document.getElementById("exInfo").style.display="block";
            wsn_enter();
        };
        document.getElementById("Verify").onclick=function(){
            document.getElementById("exInfo").style.display="block";
            wsn_enter();
        };
    }

    //gamecode领key
    if(/https?:\/\/gamecode.win\/giveaway\/[\w\W]*/.test(url)){
        document.getElementById("doTask").onclick=function(){
            document.getElementById("exInfo").style.display="block";
            gamecode_task();
        };
        document.getElementById("Verify").onclick=function(){
            document.getElementById("exInfo").style.display="block";
            gamecode_task();
        };
        function gamecode_task(){
            var gamecode_btn=document.getElementsByClassName("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();
                }
            }
        }
    }

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