// ==UserScript==
// @name chuni-net - display chara level
// @namespace esterTion
// @license MIT
// @match https://chunithm-net-eng.com/*
// @match https://new.chunithm-net.com/*
// @match https://chunithm.wahlap.com/*
// @version 1.0.1
// @author esterTion
// @description Display character level exp on chunithm-net
// ==/UserScript==
const host = location.hostname
const server = host === 'new.chunithm-net.com' ? 'jp' : host === 'chunithm-net-eng.com' ? 'ex' : host === 'chunithm.wahlap.com' ? 'cn' : ''
if (!server) throw new Error('unknown server')
const expData = [
0,
20, 20, 20, 20, 20, 20, 20, 20, 20, 100, // 10
100, 100, 100, 100, 150, 150, 150, 150, 150, 200, // 20
200, 200, 200, 200, 300, 300, 300, 300, 300, 400, // 30
400, 400, 400, 400, 500, 500, 500, 500, 500, 600, // 40
600, 600, 600, 600, 700, 700, 700, 700, 700, 900, // 50
900, 900, 900, 900,1100, 1100,1100,1100,1100,1300, // 60
1300,1300,1300,1300,1500, 1500,1500,1500,1500,1700, // 70
1700,1700,1700,1700,1900, 1900,1900,1900,1900,2100, // 80
2100,2100,2100,2100,2300, 2300,2300,2300,2300,2500, // 90
2500,2500,2500,2500,2700, 2700,2700,2700,2700,3000, // 100
3000,3000,3000,3000,3300, 3300,3300,3300,3300,3600, // 110
3600,3600,3600,3600,3900, 3900,3900,3900,3900,4200, // 120
4200,4200,4200,4200,4500, 4500,4500,4500,4500,4800, // 130
4800,4800,4800,4800,5100, 5100,5100,5100,5100,5400, // 140
5400,5400,5400,5400,5700, 5700,5700,5700,5700,6100, // 150
6100,6100,6100,6100,6500, 6500,6500,6500,6500,6900, // 160
6900,6900,6900,6900,7300, 7300,7300,7300,7300,7700, // 170
7700,7700,7700,7700,8100, 8100,8100,8100,8100,8500, // 180
8500,8500,8500,8500,8900, 8900,8900,8900,8900,9300, // 190
9300,9300,9300,9300,9700, 9700,9700,9700,9700,Infinity, // 200
]
// createElement
function _(e,t,i){var a=null;if("text"===e)return document.createTextNode(t);a=document.createElement(e);for(var n in t)if("style"===n)for(var o in t.style)a.style[o]=t.style[o];else if("className"===n)a.className=t[n];else if("event"===n)for(var o in t.event)a.addEventListener(o,t.event[o]);else a.setAttribute(n,t[n]);if(i)if("string"==typeof i)a.innerHTML=i;else if(Array.isArray(i))for(var l=0;l<i.length;l++)null!=i[l]&&a.appendChild(i[l]);return a}
function fetchJson(url) {
return new Promise((res, rej) => {
GM.xmlHttpRequest({
url: url + '?_=' + Date.now(),
responseType: 'json',
method: 'GET',
onload: r => res(r.response),
onerror: e => rej(e),
})
})
}
function addLevelToPage() {
[...document.querySelectorAll('.character_gage_base img')].forEach(addLevelToCurrentCharacter);
[...document.querySelectorAll('.character_list_gage_base img')].forEach(addLevelToCharacterList);
addStyle()
}
function addLevelToCurrentCharacter(img) {
console.log(img)
const barContainer = img.parentNode.parentNode
const levelImgs = barContainer.parentNode.querySelectorAll('.character_lv_box_num img')
const level = levelNumImageToNum(levelImgs)
const levelExp = expData[level] / (server === 'cn' ? 10 : 1)
const currentExp = Math.round((1 - parseFloat(img.width) / 374) * levelExp)
barContainer.appendChild(_('div', { className: 'CNDCL_exp large' }, [
_('text', `${currentExp}/${levelExp} ${(currentExp / levelExp * 100).toFixed(2)}%`)
]))
}
function addLevelToCharacterList(img) {
const barContainer = img.parentNode.parentNode
const levelImgs = barContainer.parentNode.querySelectorAll('.character_list_rank_num img')
const level = levelNumImageToNum(levelImgs)
const levelExp = expData[level] / (server === 'cn' ? 10 : 1)
const currentExp = Math.round((1 - parseFloat(img.width) / 270) * levelExp)
barContainer.appendChild(_('div', { className: 'CNDCL_exp' }, [
_('text', `${currentExp}/${levelExp} ${(currentExp / levelExp * 100).toFixed(2)}%`)
]))
}
function levelNumImageToNum(imgs) {
return parseInt([...imgs].map(i => i.src.match(/(\d)\.png/)[1]).join(''))
}
function addStyle() {
document.head.appendChild(_('style', {}, [_('text', `
.CNDCL_exp {
position: absolute;
z-index: 20;
height: 100%;
font-size: 16px;
line-height: 28px;
margin-left: 0.5em;
font-weight: bold;
text-shadow: 1px 1px 2px white, 0 0 1em white, 0 0 0.2em white;
}
.CNDCL_exp.large {
line-height: 38px;
font-size: inherit;
}
`)]))
}
addLevelToPage()