3,389
个编辑
MCBBS Wiki欢迎您共同参与编辑!在参与编辑之前请先阅读Wiki方针。
如果在编辑的过程中遇到了什么问题,可以去讨论板提问。
为了您能够无阻碍地参与编辑 未验证/绑定过邮箱的用户,请尽快绑定/验证。
MCBBS Wiki GitHub群组已上线!
您可以在回声洞中发表吐槽!
服务器状态监控。点击进入
本站由MCBBS用户自行搭建,与MCBBS及东银河系漫游指南(北京)科技有限公司没有从属关系。点此了解 MCBBS Wiki 不是什么>>
Salt lovely(留言 | 贡献) (将会绘制在一个id为userpie的元素里;uid从用户模板获取,如果没有,则尝试从#userpie里获取) |
Salt lovely(留言 | 贡献) 小无编辑摘要 |
||
| 第2行: | 第2行: | ||
(function () { | (function () { | ||
// 添加highcharts开源库 | // 添加highcharts开源库 | ||
addScript('https://cdn.staticfile.org/highcharts/8.2.2/highcharts.min.js') | |||
addScript('https://cdn.staticfile.org/highcharts/8.2.2/modules/exporting.min.js') | |||
window.addEventListener('load', () => { | window.addEventListener('load', () => { | ||
let uid = getUID(); if (!uid || isNaN(uid)) { console.log('未获取到MCBBSUID'); return } | let uid = getUID(); if (!uid || isNaN(uid)) { console.log('未获取到MCBBSUID'); return } | ||
getPIE(uid) | getPIE(uid) | ||
}) | }) | ||
function getUID() { | function getUID() { | ||
let el = document.querySelector('.infolist') | let el = document.querySelector('.infolist') | ||
if (el) { | if (el) { | ||
let tr = el.querySelectorAll('tr') | let tr = el.querySelectorAll('tr') | ||
for (let i = 0; i < tr.length; i++) { | for (let i = 0; i < tr.length; i++) { | ||
if (tr[i].childElementCount < 2) { continue } | if (tr[i].childElementCount < 2) { continue } | ||
if (tr[i].textContent.replace('\n', '').indexOf('UID') == 0) { | if (tr[i].textContent.replace('\n', '').indexOf('UID') == 0) { | ||
| 第27行: | 第20行: | ||
} | } | ||
el = document.querySelector('#userpie') | el = document.querySelector('#userpie') | ||
if (el) { | if (el) { | ||
return el.textContent.match(/\d+/)[0] | return el.textContent.match(/\d+/)[0] | ||
} | } | ||
} | } | ||
let retry = 1 // 重试次数 | |||
function getPIE(uid) { | function getPIE(uid) { | ||
let $url = 'https://www.mcbbs.net/api/mobile/index.php?module=profile&uid=' + uid; console.log('正在获取用户信息: ' + $url) | let $url = 'https://www.mcbbs.net/api/mobile/index.php?module=profile&uid=' + uid; console.log('正在获取用户信息: ' + $url) | ||
fetch('https://proxy.onesrc.workers.dev/ajax/' + $url).then(response => response. | fetch('https://proxy.onesrc.workers.dev/ajax/' + $url) | ||
.then(response => { | |||
if (response.ok) { | |||
return response.json() | |||
} else { | |||
return Promise.reject(Object.assign({}, json, { | |||
status: response.status, | |||
statusText: response.statusText | |||
})) | |||
} | |||
}) | |||
.then((data) => { | |||
console.log(data); window.res = data | |||
let space = data.Variables.space | |||
let credits = space.credits; //总积分 | |||
let post = space.posts; //回帖 | |||
let thread = space.threads; //主题 | |||
let digestpost = space.digestposts; //精华 | |||
let popular = space.extcredits1; //人气 | |||
// let goldngt = space.extcredits2; //金粒 | |||
// let goldigt = space.extcredits3; //金锭 | |||
// let emerald = space.extcredits4; //绿宝石 | |||
// let nethers = space.extcredits5; //下界之星 | |||
let contrib = space.extcredits6; //贡献 | |||
let kindnes = space.extcredits7; //爱心 | |||
let diamond = space.extcredits8; //钻石 | |||
let uname = space.username || ''; //用户名 | |||
let group = space.group.grouptitle || ''; //用户组 | |||
var json = {}; | |||
json.credits = { | |||
href: 'https://mcbbs-wiki.cn/wiki/%E7%94%A8%E6%88%B7:Salt_lovely', | |||
text: '小工具由Salt_lovely制作,使用了highcharts开源库' | |||
} | |||
json.chart = { backgroundColor: '#fbf2da', plotShadow: false }; | |||
json.tooltip = { pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>' }; | |||
// 标题: <用户名>积分构成 | |||
json.title = { text: uname + ' 积分构成' }; | |||
// 副标题: UID: <UID> ; 积分: <总积分> ; 用户组: <用户组> | |||
json.subtitle = { text: 'UID: ' + uid + ' ; 积分: ' + credits + ' ; 用户组: ' + group }; | |||
json.plotOptions = { | |||
pie: { | |||
allowPointSelect: true, | |||
cursor: 'pointer', | |||
colors: ['#7ccade', '#cae07b', '#e37bf9', '#fce37c', '#ff9800', '#fd957e', '#9ba8f3'], | |||
dataLabels: { | |||
enabled: true, | |||
format: '{point.name}: {point.y}分, 占{point.percentage:.1f} %', | |||
}, | |||
showInLegend: true | |||
} | |||
}; | |||
json.series = [{ | |||
type: 'pie', | |||
name: '积分占比', | |||
data: [ | |||
{ name: '发帖数/' + post + '帖', y: Math.round(post / 3) }, | |||
{ name: '主题数/' + thread + '帖', y: thread * 2 }, | |||
{ name: '精华帖/' + digestpost + '帖', y: digestpost * 45 }, | |||
{ name: '人气/' + popular + '点', y: popular * 3 }, | |||
{ name: '贡献/' + contrib + '点', y: contrib * 10 }, | |||
{ name: '爱心/' + kindnes + '颗', y: kindnes * 4 }, | |||
{ name: '钻石/' + diamond + '颗', y: diamond * 2 }, | |||
] | |||
}]; | |||
json.navigation = { | |||
buttonOptions: { | |||
enabled: true | |||
}, | }, | ||
} | } | ||
Highcharts.setOptions({ | |||
lang: { | |||
contextButtonTitle: '图表菜单', | |||
viewFullscreen: "全屏查看", | |||
exitFullscreen: "退出全屏", | |||
printChart: "打印图表", | |||
downloadJPEG: '导出 JPEG 图片', | |||
downloadPDF: '导出 PDF 文档', | |||
downloadPNG: '导出 PNG 图片', | |||
downloadSVG: '导出 SVG 矢量图' | |||
} | |||
}) | |||
Highcharts.chart('userpie', json) | |||
} | }) | ||
.catch(error => { | |||
console.log(error) | |||
if (retry > 0) { | |||
console.log('重试...') | |||
retry-- | |||
setTimeout(getPIE, 0) | |||
} | |||
}); | |||
} | |||
function addScript(src, asynchronous = false) { | |||
let scr = document.createElement('script') | |||
scr.src = src | |||
scr.async = asynchronous | |||
document.head.appendChild(scr) | |||
} | } | ||
})() | })() | ||
</script> | </script> | ||
</includeonly> | </includeonly> | ||