chuni-net - display chara level

Display character level exp on chunithm-net

Από την 14/03/2024. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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()