DLC Test (Mod 2)

GLB D-League Challenge stat gatherer

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name        DLC Test (Mod 2)
// @namespace   Gambler75
// @description GLB D-League Challenge stat gatherer
// @include     *://glb.warriorgeneral.com/game/home*
// @version     0.2.20.2026
// @grant       none
// ==/UserScript==

// This list, the season, and agents array further down will need editing each season.
var playerList = [
    4724190, 4723954, 4724203, 4722854, 4723211, 4724213, 4723458, 4724259,
    4724262, 4724221, 4724181, 4723754, 4724291
];

var season = 119;

// Variables for script
var gamelinks = [];
var outButton = null;
var netTime = null;
var showEverything = true;

var playerLinks = [];
var stats = [];
var players = {};
var teamPageName = null;
var week = null;

var statTypes = ["Defense"];
var getStats = {};
getStats["Defense"] = getDefense;

var headings = {};
headings["Defense"] = ["Ply","Tk","MsTk","Sack","Hry","TFL","FFum","FumR","RecAlw","KL","PD","Int","DefTD"];

var sortable = {};
sortable["Defense"] = 2;

var points = {};
points["Defense"] = [0,1,0,3,1,1,4,3,0,1,1,5,6];

var agents = {};
agents["4724291"]="Gambler75";
agents["4724190"]="TJ Spikes";
agents["4723954"]="briansimoneau";
agents["4724203"]="F8n4tune";
agents["4722854"]="fuzzypoopy";
agents["4723211"]="ewinter43";
agents["4724213"]="ZoSo1";
agents["4723458"]="Union Jack Jensen";
agents["4724259"]="Backes-to-Backes";
agents["4724262"]="Pena_FIN";
agents["4724221"]="Guppy, Inc";
agents["4724181"]="lexden11";
agents["4723754"]="ProfessionalKop";

window.setTimeout(function() {
    boxSetup();
}, 1000);

function promptForWeek() {
    var h = -1;
    while (h!=null && (h >= 1 || h <= 16)) {
        h = prompt("Enter the week to lookup. (1 to 16)");
        h = parseInt(h);
    }
    return h;
}

function print_r(theObj){
    console.log(theObj); // Replaced document.write to prevent DOM wiping
}

function boxSetup() {
    var scheduleContent = document.getElementsByClassName("schedule_content");
    var cboxes = document.getElementsByClassName("GScheckbox");

    if ((scheduleContent.length > 0) && (cboxes.length == 0)) {
        for (var scidx=0; scidx<scheduleContent.length; scidx++) {
            var schedules = scheduleContent[scidx];
            var rows = schedules.rows;
            rows[0].cells[1].innerHTML = "[GS] "+rows[0].cells[1].innerHTML;
            for (var i=1; i<rows.length; i++) {
                var link = rows[i].cells[2].firstChild.href;

                var oldCell = rows[i].cells[1];
                rows[i].deleteCell(1);

                var checkBox = document.createElement("input");
                checkBox.setAttribute("type","checkbox");
                checkBox.setAttribute("id",link);
                checkBox.setAttribute("class","GScheckbox");

                var div = document.createElement("span");
                div.appendChild(checkBox);
                for (var cidx=0; cidx<oldCell.childNodes.length; cidx++) {
                    var c = oldCell.childNodes[cidx];
                    if (c == null) continue;
                    var c2 = c.nextSibling;
                    div.appendChild(c);
                    if (c2 != null) {
                        div.appendChild(c2);
                    }
                }
                var newCell = rows[i].insertCell(1);
                newCell.appendChild(div);
            }
        }
    }

    div = document.createElement("div");
    div.style.clear = "both";

    var button = document.createElement("input");
    button.setAttribute("value","Collect");
    button.setAttribute("type","button");
    button.setAttribute("id","bsbutton");
    button.addEventListener("click", getData, false);
    div.appendChild(button);

    var weekText = document.createElement("span");
    weekText.innerHTML = " Enter Week: ";
    div.appendChild(weekText);

    var textbox = document.createElement("input");
    textbox.setAttribute("type","input");
    textbox.setAttribute("id","week_input");
    div.appendChild(textbox);

    var content = document.getElementById("content");
    if(content) {
        content.parentNode.insertBefore(div, content.nextSibling);
    }
}

// Converted to async to prevent browser freezing
async function getData() {
    let btn = document.getElementById("bsbutton");
    btn.disabled = true;
    outButton = btn;

    gamelinks = [];
    stats.length = 0;
    players = {};

    console.log("Getting data...");
    week = document.getElementById("week_input").value;

    for (let playerNumber of playerList){
        let page = "https://glb.warriorgeneral.com/game/player_game_log.pl?player_id="+ playerNumber + "&season="+ season +"&stat_type=raw";
        playerLinks.push(page);
        console.log(page);

        let htmlText = await getInetPage(page);
        let html = htmlText.replace(/<img/g,"<div").replace(/\/img/g,"/div>");
        let div = document.createElement("div");
        div.innerHTML = html;

        let tables = div.getElementsByTagName("table");
        if(tables.length > 1) {
            console.log("loading table...");
            let trs = tables[1].getElementsByTagName("tr");

            console.log(trs.length);
            for (let i = 0; i < trs.length; i++){
                let td = trs[i].getElementsByTagName('td')[0];
                if (!td) continue;

                let tdVal = parseInt(td.innerHTML);
                if (tdVal == parseInt(week)){
                    let td3 = trs[i].getElementsByTagName('td')[3];
                    if(td3 && td3.getElementsByTagName("a")[0]) {
                        gamelinks.push(td3.getElementsByTagName("a")[0].href);
                    }
                }
            }
        }
    }

    for (let gamelink of gamelinks){
        console.log("process gamelink: " + gamelink);
        let htmlText = await getInetPage(gamelink);
        let html = htmlText.replace(/<img/g,"<div").replace(/\/img/g,"/div>");
        let div = document.createElement("div");
        div.innerHTML = html;

        let tables = div.getElementsByTagName("table");
        for (let i = 3; i < tables.length; i = i + 3) {
            let tdEl = tables[i].getElementsByTagName("td")[0];
            if(!tdEl) continue;
            let type = tdEl.innerHTML;

            let team1 = tables[i+1];
            let name1 = team1 ? team1.getElementsByTagName("th")[0].innerHTML : "";
            let team2 = tables[i+2];
            let name2 = team2 ? team2.getElementsByTagName("th")[0].innerHTML : "";

            if (team1) loadPlayers(team1, type, name1);
            if (team2) loadPlayers(team2, type, name2);
        }
    }

    createOutputTable();
    btn.disabled = false;
}

// Upgraded to Fetch API
async function getInetPage(address) {
    address = address.replace("http://", "https://");
    let response = await fetch(address);
    let text = await response.text();
    return text;
}

function findPlayer(pid) {
    for (let player of playerList){
        if (player == pid){
            return true;
        }
    }
    return false;
}

function loadPlayers(table, heading, tname) {
    for (var i=1; i<table.rows.length; i++) {
        var r = table.rows[i];
        if(!r.cells[0].getElementsByTagName("a")[0]) continue;

        var pname = r.cells[0].getElementsByTagName("a")[0].innerHTML;
        var pid = r.cells[0].getElementsByTagName("a")[0].href.toString().split("=")[1];
        var ppos = r.cells[0].firstChild.innerHTML;
        var pteam = tname;

        if (findPlayer(pid) == true){
            if (players[pid] == null) {
                var player = new Object();
                player.name = pname.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
                player.id = pid;
                player.pos = ppos.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
                player.tname = pteam.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
                player.stats = {};

                for (let type of statTypes) {
                    player.stats[type] = [];
                }
                players[pid] = player;
            }

            var s = {};
            for (var j=1; j<r.cells.length; j++) {
                var statName = table.rows[0].cells[j].innerHTML;
                var value = r.cells[j].innerHTML.replace(",","");

                if (statName == "Yds") value = value;
                if (statName == "SackYd") value = Math.round(parseFloat(value));
                if (heading == "Kick/Punt Return") {
                    if (s["KYds"] == null && statName == "Yds") statName = "KYds";
                    else if (statName == "Yds") statName = "PYds";
                    else if (s["KTD"] == null && statName == "TD") statName = "KTD";
                    else if (statName == "TD") statName = "PTD";
                }
                if (heading == "Defense") {
                    if (s["SYds"] == null && statName == "Yds") statName = "SYds";
                    else if (statName == "Yds") statName = "IYds";
                }
                s[statName] = value;
            }
            try{
                players[pid].stats[heading].push(s);
            }
            catch(ex){
                console.log("Did not find stats for: " + pid + " error: " + ex);
            }
        }
    }
}

function spacing(w, s) {
    s = Math.min(s,12);
    if (w.length < s) {
        var output = " ";
        for (var i=w.length-1; i<(s-1); i++) {
            output += ".";
        }
        output = output.slice(0,-1)+" ";
        output += w;
        return output;
    }
    return w;
}

function createForumOutput() {
    var output = "";
    for (let type of statTypes) {
        output += "\n"+type + "\n";
        for (let h of headings[type]) {
            output += spacing(h, h.length*3)
        }
        output += " .... Pos . Name .(Team)\n";

        for (let pid in players) {
            let player = players[pid];
            if (player.stats[type] != null && player.stats[type].length > 0) {
                if (showEverything == false && teamPageName && teamPageName.indexOf(player.tname) != 0) {
                    continue;
                }
                for (let h of headings[type]) {
                    var theObj = player.stats[type][0];
                    var result = 0;
                    for(var p in theObj){
                        if (p == h){
                            result = theObj[p];
                        }
                    }
                    if (isNaN(parseFloat(result))) result=0;
                    output += spacing(result.toString(), h.length*3);
                }
                output += " ..... "+spacing(player.pos, 3)+" "+spacing(player.name,7)+" ("+player.tname+")\n";
            }
        }
        output += "\n";
    }
    console.log(output);
}

function createHTMLOutput() {
    print_r(players);
}

function createDelimitedOutput() {
    var delim = "\t";
    var output = "";
    let totalPoints = 0;

    for (let type of statTypes) {
        output += "\n"+type + "\n";
        output += "Week"+delim+"Pos"+delim+"Name"+delim+"Team"+delim;
        for (let h of headings[type]) {
            output += h+delim;
        }
        output += "\n";

        for (let pid in players) {
            let player = players[pid];
            output += agents[player.id] + delim;
            output += week + delim + " " + player.pos + delim + player.name.replace(/ /g," ").replace(/,/g,"").slice(0,25) + delim + player.tname.replace(/ /g," ").replace(/,/g,"").slice(0,25) + delim;

            if (player.stats[type] && player.stats[type].length > 0) {
                for (let h of headings[type]) {
                    var theObj = player.stats[type][0]; // Assuming taking 1st game
                    var result = 0;
                    var pointsToUse = points[type][headings[type].indexOf(h)];

                    for(var p in theObj) {
                        if (p == h) result = theObj[p];
                    }
                    if (isNaN(parseFloat(result))) result=0;

                    if (h == "Rec") var Rec = result;
                    if (h == "YAC" && typeof Rec !== 'undefined') result = result * Rec;

                    totalPoints += parseFloat(result) * parseFloat(pointsToUse || 0);
                    output += result.toString()+delim;
                }
            } else {
                for (let h of headings[type]){
                    output += "0" + delim;
                }
            }
            output += totalPoints.toString() + delim + "\n";
            totalPoints = 0;
        }
    }
    console.log(output);
    alert("Check Console for Data Output");
}

function createOutputButtons() {
    var div = document.createElement("span");

    var btn = document.createElement("input");
    btn.type = "button";
    btn.setAttribute("value","Delimited Export");
    btn.addEventListener("click", createDelimitedOutput, false); // Fixed function ref
    div.appendChild(btn);

    var btn2 = document.createElement("input");
    btn2.type = "button";
    btn2.setAttribute("value","Half-Assed Forum Export");
    btn2.addEventListener("click", createForumOutput, false);
    div.appendChild(btn2);

    var btn3 = document.createElement("input");
    btn3.type = "button";
    btn3.setAttribute("value","PrintR");
    btn3.addEventListener("click", createHTMLOutput, false);
    div.appendChild(btn3);

    return div;
}


function createOutputTable() {
    var output = document.createElement("div");
    output.appendChild(createOutputButtons());

    for (var i=0; i<statTypes.length; i++) {
        var type = statTypes[i];
        outButton.setAttribute("value","Warning: this might take a while. (creating "+type+" table)");

        var table = document.createElement("table");
        table.setAttribute("class","bscTable");
        table.cellSpacing = "0";
        table.cellPadding = "0";
        table.style.marginBottom = "0px";
        table.style.width = "1000px";
        var tbody = document.createElement("tbody");

        var tr = document.createElement("tr");
        tr.setAttribute("class","nonalternating_color");

        var td = document.createElement("td");
        td.innerHTML = type;
        td.colSpan = headings[type].length + 1;

        tr.appendChild(td);
        tbody.appendChild(tr);
        table.appendChild(tbody);

        var hrow = document.createElement("tr");
        hrow.setAttribute("class", "nonalternating_color2");
        var head = ["Name"].concat(headings[type]);

        for (let h of head) {
            var th = document.createElement("th");
            th.setAttribute("style","color: black; text-align: " + (h == "Name" ? "left" : "right"));
            th.innerHTML = h;
            hrow.appendChild(th);
        }
        table.appendChild(hrow);

        for (let pid in players) {
            let player = players[pid];
            if (showEverything == false && teamPageName && teamPageName.indexOf(player.tname) != 0) {
                continue;
            }
            if (player.stats[type] != null && player.stats[type].length > 0) {
                var pRow = getOutputRow(type, player);
                table.appendChild(pRow);
            }
        }

        for (var x=2; x<table.rows.length; x++) {
            table.rows[x].setAttribute("class","alternating_color"+(x%2+1));
        }
        output.appendChild(table);
    }
    document.body.appendChild(output);

    outButton.setAttribute("value","Warning: this might take a while. (making sortable)");
    makeSortable();
    outButton.setAttribute("value","Done.");
}

function merge(a, b, sortidx) {
    if (a.length == 0) return b;
    if (b.length == 0) return a;

    var output = [];
    var idx = 0, aidx = 0, bidx = 0;

    while ((aidx < a.length) && (bidx < b.length)) {
        if (parseFloat(a[aidx].cells[sortidx].textContent) > parseFloat(b[bidx].cells[sortidx].textContent)) {
            output.push(a[aidx++]);
        }
        else {
            output.push(b[bidx++]);
        }
    }

    for (; aidx<a.length; aidx++) output.push(a[aidx]);
    for (; bidx<b.length; bidx++) output.push(b[bidx]);

    return output;
}

function sortColumn(data, sortidx) {
    if (data.length <= 1) return data;
    var center = Math.round(data.length/2);
    var left = sortColumn(data.slice(0,center), sortidx);
    var right = sortColumn(data.slice(center), sortidx);
    return merge(left, right, sortidx);
}

function makeSortable() {
    var tables = document.getElementsByClassName("bscTable");
    for (var j=0; j<tables.length; j++) {
        var head = tables[j].getElementsByTagName("th");
        for (var i=0; i<head.length; i++) {
            head[i].addEventListener("click", sort, false);
        }
    }
}

function sort(event) {
    var tbl = event.target.parentNode.parentNode;
    var idx = event.target.cellIndex;
    if (idx == -1) return;

    tbl.style.visibility = "hidden";
    var results = sortColumn(getArray(tbl.rows), idx);

    while (tbl.rows.length > 2) {
        tbl.deleteRow(2);
    }

    for (var i=0; i<results.length; i++) {
        results[i].setAttribute("class","alternating_color"+(i%2+1));
        tbl.appendChild(results[i]);
    }
    tbl.style.visibility = "visible";
}

function getArray(list) {
    var output = [];
    for(var i=2; i < list.length; i++) {
        output.push(list[i]);
    }
    return output;
};

function getOutputRow(type, player) {
    var tr = document.createElement("tr");
    tr.innerHTML = "<td>"+
    "<span class='cpu'>"+player.pos+"</span> "+
    "<a href='/game/player.pl?player_id="+player.id+"'>"+(agents[player.id] || player.name)+"</a>"+
    "<span class='cpu'> ("+player.tname+")</span>"+
    "</td>";

    for (let s of headings[type]) {
        var td = document.createElement("td");
        td.setAttribute("style", "color: black; text-align: right;");

        var theObj = player.stats[type][0];
        var result = 0;
        for(var p in theObj){
            if (p == s) result = theObj[p];
        }
        if (isNaN(parseFloat(result))) result=0;

        td.innerHTML = result;
        tr.appendChild(td);
    }
    return tr;
}

function getDefense(stats) {
    return getGeneric(headings["Defense"], stats);
}

function getGeneric(headings, stats) {
    var val = 0;
    var total = 0;
    var output = {};
    for (let h of headings) {
        output[h] = 0;
        for (let s of stats) {
            val = parseFloat(s[h]);
            if (isNaN(val) == true) val = 0;
            output[h] += val;
            if ((h != "Name") && (h != "Plays") && (h != "Ply")) {
                total += Math.abs(parseFloat(s[h]));
            }
        }
    }
    return total != 0 ? output : null;
}