パリーグ順位スレ用

スレタイを自動生成します(とりあえずパのみ対応)

As of 2018-04-26. See the latest version.

// ==UserScript==
// @name         パリーグ順位スレ用
// @namespace    http://surrogatepair.github.io/
// @version      0.1
// @description  スレタイを自動生成します(とりあえずパのみ対応)
// @author       さろげーと
// @match        https://freefielder.jp/magic/
// @match        https://freefielder.jp/magic/index.php?l=p
// @grant        none
// ==/UserScript==

(function() {
    var tr = document.getElementById('scr_i').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
    var tn = [];
    var wl = [];
    var clsname = {"F_row": "公", "E_row": "鷲", "L_row": "猫", "M_row": "鴎", "B_row": "檻", "H_row": "鷹"};
    for ( var i=0; i<6; i++ ){
        td = tr[i].getElementsByTagName('td');
        tn[i] = clsname[tr[i].getAttribute("class")];
        wl[i] = td[1].textContent - td[2].textContent;
    }

    function rep(i){
        return "=".repeat(Math.floor( i / 2 )) + "-".repeat( i % 2 );
    }
    var text = "";
    if ( 0 > wl[0] ){
        text += "//" + rep( -wl[0] );
    } else if ( wl[0] == 0 ){
        text += "/";
    }
    for ( i=0; i<5; i++ ){
        text += tn[i];
        if ( wl[i] < wl[i+1] ){
            text += "+".repeat( -wl[i] + wl[i+1] );
        } else if ( wl[i] * wl[i+1] > 0 ){
            text += rep( wl[i] - wl[i+1] );
        } else {
            if ( wl[i] > 0 ){
                text += rep( wl[i] ) + "/";
            }
            if ( 0 > wl[i+1] ){
                text += "/" + rep( -wl[i+1] );
            }
        }
    }
    text += tn[5];
    if ( wl[5] > 0 ){
        text += rep( wl[5] ) + "//";
    } else if ( wl[5] == 0 ){
        text += "/";
    }
    var date = document.getElementById("search_disp").textContent.match(/\d+年(\d+)月(\d+)日$/);
    document.getElementById("change_league").innerText = "";
    document.getElementById("search_disp").innerText = "【パ順位スレ】" + text + "【" + date[1] + "/" + date[2] + "】";
})();