咕咕镇数据采集

咕咕镇数据采集,目前采集技能率、暴击率

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         咕咕镇数据采集
// @namespace    https://greasyfork.org/users/448113
// @version      0.3.5
// @description  咕咕镇数据采集,目前采集技能率、暴击率
// @author       paraii
// @include      https://www.lv999max.com/*
// @grant        GM_xmlhttpRequest
// @connect      notes.orga.cat
// @connect      www.lv999max.com
// @license      MIT License
// ==/UserScript==

function submitData(){
    var npc = document.getElementById('pklist').children;
    for(let i = 2;i<12;i++){
        //console.log(npc[o].innerText[0]);
        if(npc[i].innerText[0]!='已'){
            localStorage.setItem('over', 0); //未与全部npc战斗
            alert('未与全部npc战斗,请与全部npc完成战斗后提交')
            break;
        }
        else{
            localStorage.setItem('over', 1);
        }
    }
    if(localStorage.length>4&&localStorage.getItem('over')=='1'){
        var meURL = `https://notes.orga.cat/${encodeURI(localStorage.getItem('title')).replace(/%/g, '')}`;
        console.log(meURL);
        GM_xmlhttpRequest({
            method: 'GET',
            url: meURL,
            timeout: 30000,
            headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
            onload: response => {
                var text = response.responseText.match(/content">([\s\S]*)<\/text/)[1];
                if(text.length==0){
                    text='{"1-50":{"MU":[0],"ZHU":[0],"DENG":[0],"SHOU":[0]},"51-100":{"MU":[0],"ZHU":[0],"DENG":[0],"SHOU":[0]},"101-":{"MU":[0],"ZHU":[0],"DENG":[0],"SHOU":[0]}}'
                }else{
                    text=text.replace(/&quot;/g,'"');
                }

                var json = JSON.parse(text);
                var pk_i = 0;
                while(localStorage.getItem(`pk${pk_i}`)!=null){
                    var a = localStorage.getItem(`pk${pk_i}`).split(',');
                    var n = a.shift();
                    for(let j = 1; j<a.length; j++){
                        a[j] = +a[j];
                    }
                    if(a[3]<51){
                        json['1-50'][n].push(a);
                    }
                    else if(a[3]<101&&a[3]>50){
                        json['51-100'][n].push(a);
                    }
                    else{
                        json['101-'][n].push(a);
                    }
                    pk_i++;
                }

                text = JSON.stringify(json);
                GM_xmlhttpRequest({
                    method: 'POST',
                    url: meURL,
                    timeout: 30000,
                    headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                    data: `text=${text}`,
                    onload: response => {
                        localStorage.clear();
                        alert('数据已提交,第一次使用记得把用户名站内发给thewzmath');
                        return 1;
                    }
                })
            }
        })
    }else{
        return 0;
    }
}


(function() {
    'use strict'
    if(localStorage.getItem('attribute'==null)&&localStorage.getItem('cardName'==null)){
        localStorage.setItem('attribute',0);
        localStorage.setItem('cardName',0);
    }
    var attribute = new Array();

    if(window.location.pathname=='/fyg_card.php'){
        var btn2 = document.createElement('button');
        var span2 = document.createElement('span');
        var cardNameNode = 0;
        function updateCard(){
            span2.innerHTML = '读取中...';
            attribute.splice(0,attribute.length);
            for(let i=1;i<7;i++){
                attribute.push(document.getElementById(`sjj${i}`).innerText);
            }
            localStorage.setItem('attribute',attribute.join(','));
            localStorage.setItem('cardName',cardNameNode.innerText);
            if(localStorage.getItem('cardName')==''){localStorage.setItem('cardName',null);}
            span2.innerHTML = `    当前卡片:${localStorage.getItem('cardName')}(${localStorage.getItem('attribute')})`;
        }


        span2.innerHTML = `    当前卡片:${localStorage.getItem('cardName')}(${localStorage.getItem('attribute')})`;
        btn2.innerHTML = '手动读取';
        btn2.onclick = updateCard;
        let p = document.getElementsByClassName('panel panel-primary')[1];
        p.insertBefore(span2,p.children[0]);
        p.insertBefore(btn2,p.children[0]);
        var load1=0,load2=0;
        var observer1 = new MutationObserver(()=>{
            load1=1;
            document.getElementsByClassName('btn btn-block btn-lg btn-warning')[0].addEventListener('click', updateCard);
            if(load1&&load2){
                updateCard();
                load1=0;load2=0;
            }
        });
        observer1.observe(document.getElementById('mystata'), {childList: true, characterData: true});
        var observer2 = new MutationObserver(()=>{
            load2=1;
            cardNameNode = document.getElementById('carding').children[0].children[0];
            if(load1&&load2){
                updateCard();
                load1=0;load2=0;
            }
        });
        observer2.observe(document.getElementById('carding'), {childList: true});
    }
    else if(window.location.pathname=='/fyg_pk.php'){
        var btn1 = document.createElement('button');
        btn1.innerHTML = '正在读取卡片...';
        btn1.onclick = ()=>{
            try{
                if(submitData()){
                    return;
                }
            }
            catch(err){
                alert('数据提交失败,请重试');
            }
        };

        let p = document.getElementsByClassName('panel panel-primary')[0];
        p.insertBefore(btn1,p.children[0]);


        try{
            GM_xmlhttpRequest({
                method: 'POST',
                url: `https://www.lv999max.com/fyg_read.php`,
                headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                data: 'f=9',
                onload: response => {
                    try{
                        var n = response.responseText.match(/>[\u4e00-\u9fa5]</u)[0];
                        localStorage.setItem('cardName',n.substr(1,n.length-2));
                    }catch(err){localStorage.setItem('cardName','null');}
                    GM_xmlhttpRequest({
                        method: 'POST',
                        url: `https://www.lv999max.com/fyg_read.php`,
                        headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                        data: 'f=4',
                        onload: response => {
                            //console.log(response.responseText);
                            attribute.splice(0,attribute.length);
                            response.responseText.match(/>(\d+)</g).forEach(item => {
                                attribute.push(item.substr(1,item.length-2));
                            });
                            attribute.shift();
                            localStorage.setItem('attribute',attribute.join(','));
                            if(localStorage.getItem('cardName')!='0'&&localStorage.getItem('attribute')!='0'){
                                //alert('卡片读取完成');
                                btn1.innerHTML = '提交数据';

                                console.log(localStorage);

                                var targetNode = document.getElementById('pk_text');
                                var config = {childList: true};
                                // 当节点发生变化时的需要执行的函数
                                var callback = function(mutationsList, observer) {
                                    var isPk = 0;
                                    for(let mutation of mutationsList) {
                                        if (mutation.type == 'childList') {
                                            //console.log('new pk');
                                            isPk = 1;
                                            //console.log(targetNode.firstChild);

                                        }
                                    }

                                    if(isPk){
                                        var infoList = targetNode.firstChild.children;
                                        //infoList: [0]名字,[1]初始血盾,[2]第一回合{左方信息,右方信息,左方血盾,右方血盾},[3]第二回合{..} ...[end]结果
                                        var npcTitle = '';
                                        var npcName = '';
                                        var npcLv = '';
                                        var npcRate = 0;
                                        var npcSKL = '';
                                        var meName = 'null';
                                        var meSKL = 'null';
                                        var isNpc = 1;
                                        try{
                                            localStorage.setItem('title',infoList[0].getElementsByClassName('fyg_mp0 fyg_tc')[0].innerText);
                                            npcTitle = infoList[0].getElementsByClassName('fyg_mp0 fyg_tc')[1].innerText;
                                        }catch(err){return;}
                                        switch(npcTitle[npcTitle.length-1]){
                                            case '人':npcSKL = '三连击';npcName='MU';break;
                                            case '蛛':npcSKL = '剧毒蛛网';npcName='ZHU';break;
                                            case '灵':npcSKL = '灵魂爆燃';npcName='DENG';break;
                                            case '兽':npcSKL = '肉球嘲讽';npcName='SHOU';break;
                                            default: isNpc = 0; //只统计NPC
                                        }

                                        var meProba = {'CRT':0,'SKL':0,'SUM':0};
                                        var npcProba = {'CRT':0,'SKL':0,'SUM':0};


                                        if(isNpc){
                                            switch(localStorage.getItem('cardName')){
                                                case '琳':meSKL = '爆裂双刃';meName='LIN';break;
                                                case '艾':meSKL = '烈焰宝石';meName='AI';break;
                                                case '默':meSKL = '魔力压制';meName='MO';break;
                                                case '梦':meSKL = '星轮逆转';meName='MENG';break;
                                            }
                                            switch(npcTitle[0]){
                                                case '超':npcRate = 3;;break;
                                                case '大':npcRate = 2;break;
                                                case '强':npcRate = 1;break;
                                                default:npcRate = 0;
                                            }
                                            npcLv = npcTitle.match(/.?(\d+)./)[1];
                                            //console.log(npcLv);


                                            for(let i=2;i<infoList.length-1;i++){
                                                var left=infoList[i].children[0].innerText;
                                                //console.log(left);
                                                var right=infoList[i].children[1].innerText;
                                                //console.log(right);
                                                if(left.indexOf('暴击')!=-1){
                                                    meProba.CRT++;
                                                }
                                                if(right.indexOf('暴击')!=-1){
                                                    npcProba.CRT++;
                                                }
                                                if(left.indexOf(meSKL)!=-1){
                                                    meProba.SKL++;
                                                }
                                                if(right.indexOf(npcSKL)!=-1){
                                                    npcProba.SKL++;
                                                }
                                            }
                                            meProba.SUM = targetNode.firstChild.getElementsByClassName('icon icon-arrow-right text-success').length;
                                            npcProba.SUM = targetNode.firstChild.getElementsByClassName('icon icon-arrow-left text-success').length
                                            //[卡片名,智力,敏捷,NPC等级,NPC倍率,我方技能数,我方暴击数,我方攻击数,NPC技能数,NPC暴击数,NPC攻击数]
                                            var attr = localStorage.getItem('attribute').split(',');
                                            var probaArray = new Array(npcName,meName,attr[2],attr[1],npcLv,npcRate,
                                                                       meProba.SKL,meProba.CRT,meProba.SUM,npcProba.SKL,npcProba.CRT,npcProba.SUM);
                                            localStorage.setItem('over', 0);
                                            var pk_i = 0;
                                            while(localStorage.getItem(`pk${pk_i}`)!=null){
                                                pk_i++;
                                            }
                                            localStorage.setItem(`pk${pk_i}`, probaArray.join(','));
                                            console.log(`${localStorage.getItem('cardName')}(${localStorage.getItem('attribute')}) vs ${npcTitle}: 该次战斗已保存`);

                                        }

                                    }
                                };
                                // 创建一个observer示例与回调函数相关联
                                var observer = new MutationObserver(callback);
                                //使用配置文件对目标节点进行观测
                                observer.observe(targetNode, config);

                                // 停止观测
                                //observer.disconnect();
                            }
                            else{
                                alert(`卡片读取失败,请刷新重试或前往卡片页面手动读取\n当前卡片为:${localStorage.getItem('cardName')}(${localStorage.getItem('attribute')}) 若无误请忽略`);
                                btn1.innerHTML = '提交数据';
                            }
                        }
                    })

                }
            })
        }
        catch(err){
            alert(`卡片读取失败,请刷新重试或前往卡片页面手动读取\n当前卡片为:${localStorage.getItem('cardName')}(${localStorage.getItem('attribute')}) 若无误请忽略`);
            btn1.innerHTML = '提交数据';
        }
    }
})();