咕咕镇数据采集

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

目前為 2020-02-21 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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

(function() {
    'use strict'
    if(window.location.pathname=='/fyg_pk.php'){
        var attribute = new Array();
        var meName = '0';
        var meSKL = '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 => {
                    var n = response.responseText.match(/>\p{Unified_Ideograph}</u)[0];
                    meName = n.substr(1,n.length-2);
                    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);
                            response.responseText.match(/>(\d+)</g).forEach(item => {
                                attribute.push(item.substr(1,item.length-2));
                            });
                            attribute.shift();
                            console.log(meName);
                            console.log(attribute);
                            if(meName!='0'&&attribute.length!=0){
                                alert('卡片读取完成');
                                console.log(localStorage.length);
                                switch(meName){
                                    case '琳':meSKL = '爆裂双刃';meName='LIN';break;
                                    case '艾':meSKL = '烈焰宝石';meName='AI';break;
                                    case '默':meSKL = '魔力压制';meName='MO';break;
                                    case '梦':meSKL = '星轮逆转';meName='MENG';break;
                                }
                                var targetNode = document.getElementById('pk_text');
                                var config = {childList: true};
                                // 当节点发生变化时的需要执行的函数
                                var callback = function(mutationsList, observer) {
                                    var isPk = 0;
                                    for(var 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 meTitle = infoList[0].getElementsByClassName('fyg_mp0 fyg_tc')[0].innerText;
                                        var npcTitle = infoList[0].getElementsByClassName('fyg_mp0 fyg_tc')[1].innerText;
                                        var npcName = '';
                                        var npcLv = '';
                                        var npcRate = 0;
                                        var npcSKL = '';
                                        var isNpc = 1;

                                        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(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(var 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 probaArray = new Array(npcName,meName,attribute[2],attribute[1],npcLv,npcRate,
                                                                       meProba.SKL,meProba.CRT,meProba.SUM,npcProba.SKL,npcProba.CRT,npcProba.SUM);

                                            localStorage.setItem(localStorage.length, probaArray.join(','));
                                            if(localStorage.length==6){
                                                var meURL = `https://notes.orga.cat/${encodeURI(meTitle).replace(/%/g, '')}`;
                                                console.log(meURL);
                                                GM_xmlhttpRequest({
                                                    method: 'GET',
                                                    url: meURL,
                                                    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);
                                                        for(var i = 0; i < localStorage.length; i++){
                                                            var a = localStorage.getItem(i).split(',');
                                                            var n = a.shift();
                                                            for(var 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);
                                                            }
                                                        }

                                                        text = JSON.stringify(json);
                                                        GM_xmlhttpRequest({
                                                            method: 'POST',
                                                            url: meURL,
                                                            headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                                                            data: `text=${text}`,
                                                            onload: response => {
                                                                localStorage.clear();
                                                                alert('数据已提交');
                                                            }
                                                        })
                                                    }
                                                })
                                            }
                                        }

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

                                // 停止观测
                                //observer.disconnect();
                            }
                            else{
                                alert('卡片读取失败');
                            }
                        }
                    })

                }
            })
        }
        catch(err){
            alert('卡片读取失败');
        }
    }
})();