FLOJ UserName Mapper

想看到编号下的真实姓名?这个将会满足你!

当前为 2019-12-10 提交的版本,查看 最新版本

// ==UserScript==
// @name         FLOJ UserName Mapper
// @namespace    http://tampermonkey.net/
// @version      0.1.2
// @description  想看到编号下的真实姓名?这个将会满足你!
// @author       iotang
// @match        https://floj.tech/*
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

"use strict";

var gmMapperName = "mapper-sdlfjqwoihfin9q248fbh93v";
var defaultMapper = {
    "2020cj_101": "star_magic_young",
    "2020cj_102": "shuixirui",
    "2020cj_103": "czf",
    "2020cj_104": "iotang",
    "2020cj_105": "Shiina Mashiro",
    "2020cj_106": "<a style=\"color: black; text-shadow: 0 0 1em orange, 0 0 0.3em orange; \">I</a><a style=\"color: red; text-shadow: 0 0 1em orange, 0 0 0.3em orange; \">tst</a>",
    "2020cj_107": "Winlere",
    "2020cj_108": "a1b3c7d9",
    "2020cj_109": "test12345",
    "2020cj_110": "dsl2002",
    "2020cj_111": "<font color=\"red\">★ newbie314159 AK IOI ★</font>",
    "2020cj_112": "Geralt Gao",
    "2020cj_113": "zhoushuyu",
    "2020cj_120": "newbiechd",
    "2020cdqz_101": "Owen",
    "2020hzez_104": "supy",
    "2020hsefz_101": "zjc",
    "2020nfls_101": "xy",
    "2020hzez_117": "Gnar",
    "2020hzez_120": "LJC00118",
    "2020hzez_106": "Isonan",
    "2020hzez_110": "memset0",
    "2020hsefz_118": "Dilute"
};

function resetMapper()
{
    GM_setValue(gmMapperName, defaultMapper);
}

function getMapper()
{
    var temp = GM_getValue(gmMapperName);

    if(temp === undefined)
    {
        GM_setValue(gmMapperName, defaultMapper);
        temp = GM_getValue(gmMapperName);
    }

    return temp;
}

function getHashie(who)
{
    var temp = getMapper();

    if(temp[who] == undefined)
    {
        return "<a style=\"opacity: 0.5; color: inherit;\">" + who + "</a>";
    }

    return temp[who];
}

function setHashie(who, val)
{
    var temp = getMapper();
    temp[who] = val;
    GM_setValue(gmMapperName, temp);
}

function updateMapper(force)
{
    var temp = getMapper();

    for(let i in defaultMapper)
    {
        if(force || temp[i] == undefined)
        {
            temp[i] = defaultMapper[i];
        }
    }

    GM_setValue(gmMapperName, temp);
}

function cleanUp()
{
	var users = document.getElementsByClassName("uoj-username");
    var honor = document.getElementsByClassName("uoj-honor");

    for(let i = 0; i < users.length; i++)
    {
        users[i].innerHTML = getHashie(users[i].innerHTML);
    }
    for(let i = 0; i < honor.length; i++)
    {
        honor[i].innerHTML = getHashie(honor[i].innerHTML);
    }
}

function getInput(coef)
{
    var val = prompt("输入" + coef);
    if(val === null)return null;
    if(val.length <= 0)return "";

    var col = prompt("输入" + coef + "的颜色");
    if(col === null)return null;
    if(col.length <= 0)col = "inherit";

    var shadowcol = prompt("输入" + coef + "的阴影颜色");
    if(shadowcol === null)return null;
    if(shadowcol.length <= 0)shadowcol = undefined;

    var bas = "<a style=\"";
    if(col != undefined)bas = bas + "color: " + col + "; ";
    if(shadowcol != undefined)bas = bas + "text-shadow: 0 0 1em " + shadowcol + ", 0 0 0.3em " + shadowcol + "; ";
    bas = bas + "\">" + val + "</a>";

    return bas;
}

function comfirmHashie()
{
    var who = prompt("输入源 ID");
    if(who == null || who.length <= 0)return;

    var pref = getInput("前缀");
    if(pref === null)return;
    var basm = getInput("主名");
    if(basm === null)return;
    var suff = getInput("后缀");
    if(suff === null)return;
    var bas = pref + basm + suff;

    setHashie(who, bas);
    cleanUp();
}

function confirmUpdateMapper()
{
    var types = confirm("从数据库中更新配置。如果点击“是”,会重置已有的设置,用默认设置替代。");
    if(confirm("真的要这样吗?这不能被撤销!"))
    {
        updateMapper(types);
    }
}

var uojContent = document.getElementsByClassName("uoj-content")[0];

var buttonHashie = document.createElement("button");
buttonHashie.style = "background: rgb(212,255,212); border: none;";
buttonHashie.name = "hashieUser";
buttonHashie.id = "hashieUser";
buttonHashie.innerHTML = "添加规则";
buttonHashie.onclick = function(){comfirmHashie();};

var buttonUpdate = document.createElement("button");
buttonUpdate.style = "background: rgb(255,212,212); border: none;";
buttonUpdate.name = "mapperUpdate";
buttonUpdate.id = "mapperUpdate";
buttonUpdate.innerHTML = "重置";
buttonUpdate.onclick = function(){confirmUpdateMapper();};

uojContent.appendChild(buttonHashie);
uojContent.appendChild(buttonUpdate);

cleanUp();