HP-FC:Punkteabstand

ein Script zur Anzeige der Punkteabstände im Forum

当前为 2020-04-21 提交的版本,查看 最新版本

// ==UserScript==
// @name        HP-FC:Punkteabstand
// @author      Nugorra
// @namespace   hpfcpunkteabstand
// @description ein Script zur Anzeige der Punkteabstände im Forum
// @include     https://www.hp-fc.de/forum/
// @version     4.0.0
// @grant       none
// ==/UserScript==
var current,nextPoints,textSave = "";
var prefix = '.box[data-box-identifier="com.woltlab.wcf.genericBox29"] .boxContent';
var addedStyle = [];

var infoBox = document.querySelector(prefix);
var list = infoBox.querySelector('ol');
var currentPoints = list.querySelectorAll('li');
var output = document.createElement('ul');

for (var i = 0; i < currentPoints.length;i++) {
    current = currentPoints[i].dataset;
    if((currentPoints.length - 1) !=  i) {
        nextPoints = current.housePoints - currentPoints[i+1].dataset.housePoints;
    } else {
        nextPoints = false;
    }
    output.appendChild(buildReturn(i+1,current.houseColor,current.houseName,current.housePoints,nextPoints));
    addedStyle.push({ name: current.houseName.toLowerCase(), color: current.houseColor });
}

var sheet = document.createElement('style');
sheet.innerHTML = buildStyle(addedStyle);
document.body.appendChild(sheet);

list.remove();
infoBox.appendChild(output);

function buildReturn(rank,color,name,own,distance) {
    var li = document.createElement('li');
      li.classList.add(name.toLowerCase());

    var text = rank + ". " + name + ": " + addDot(own);
    if(distance) {
        text = text + " (+ " + addDot(distance) + ")";
    }

    var textNode = document.createTextNode(text);
    li.appendChild(textNode);

    return li;
}

function buildStyle(){
    var style = "";

    addedStyle.forEach(function(house){
        style = style + " " + prefix + " li." + house.name + " { color: " + house.color + "; }";
    });

    return style;
}

function addDot(x){
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
}