forked from bot/app
🔥 小型重构
This commit is contained in:
25
src/resources/liteyuki_statistics/templates/js/stat_rank.js
Normal file
25
src/resources/liteyuki_statistics/templates/js/stat_rank.js
Normal file
@ -0,0 +1,25 @@
|
||||
let data = JSON.parse(document.getElementById("data").innerText) // object
|
||||
|
||||
const rowDiv = document.importNode(document.getElementById("row-template").content, true)
|
||||
|
||||
function randomHideChar(str) {
|
||||
// 随机隐藏6位以上字符串的中间连续四位字符,用*代替
|
||||
if (str.length <= 6) {
|
||||
return str
|
||||
}
|
||||
let start = Math.floor(str.length / 2) - 2
|
||||
return str.slice(0, start) + "****" + str.slice(start + 4)
|
||||
}
|
||||
data["ranking"].forEach((item) => {
|
||||
let row = rowDiv.cloneNode(true)
|
||||
let rowID = item["name"]
|
||||
let rowIconSrc = item["icon"]
|
||||
let rowCount = item["count"]
|
||||
|
||||
row.querySelector(".row-name").innerText = randomHideChar(rowID)
|
||||
row.querySelector(".row-icon").src = rowIconSrc
|
||||
row.querySelector(".row-count").innerText = rowCount
|
||||
|
||||
document.body.appendChild(row)
|
||||
})
|
||||
|
Reference in New Issue
Block a user