MCBBS Wiki欢迎您共同参与编辑!在参与编辑之前请先阅读Wiki方针

如果在编辑的过程中遇到了什么问题,可以去讨论板提问。

为了您能够无阻碍地参与编辑 未验证/绑定过邮箱的用户,请尽快绑定/验证

MCBBS Wiki GitHub群组已上线!

您可以在回声洞中发表吐槽!

服务器状态监控。点击进入

本站由MCBBS用户自行搭建,与MCBBS及东银河系漫游指南(北京)科技有限公司没有从属关系。点此了解 MCBBS Wiki 不是什么>>

微件:getMCBBSCredit:修订间差异

来自MCBBS Wiki
跳到导航 跳到搜索
(将会绘制在一个id为userpie的元素里;uid从用户模板获取,如果没有,则尝试从#userpie里获取)
 
无编辑摘要
第2行: 第2行:
(function () {
(function () {
// 添加highcharts开源库
// 添加highcharts开源库
addScript('https://cdn.staticfile.org/highcharts/8.2.2/highcharts.min.js')
var scr = document.createElement('script')
scr.src = 'https://cdn.staticfile.org/highcharts/8.2.2/highcharts.min.js'
addScript('https://cdn.staticfile.org/highcharts/8.2.2/modules/exporting.min.js')
document.head.appendChild(scr)
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 }
// let el = document.querySelector('#mw-content-text .mw-parser-output')
// let n = document.createElement('div'); n.id = 'userpie'; el.appendChild(n)
getPIE(uid)
getPIE(uid)
})
})
function getUID() {
function getUID() {
let el = document.querySelector('.infolist')
let el = document.querySelector('.infolist')
// console.log(el)
if (el) {
if (el) {
let tr = el.querySelectorAll('tr')
let tr = el.querySelectorAll('tr')
// console.log(tr)
for (let i = 0; i < tr.length; i++) {
for (let i = 0; i < tr.length; i++) {
// console.log(tr[i])
// console.log(tr[i].textContent.indexOf('UID'))
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')
// console.log(el)
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.text()).then((res) => {
fetch('https://proxy.onesrc.workers.dev/ajax/' + $url)
//console.log(res)
.then(response => {
let data = JSON.parse(res)
if (response.ok) {
let space = data.Variables.space
return response.json()
//let credits = space.credits; //总积分
} else {
let post = space.posts; //回帖
return Promise.reject(Object.assign({}, json, {
let thread = space.threads; //主题
status: response.status,
statusText: response.statusText
let digestpost = space.digestposts; //精华
let popular = space.extcredits1; //人气
}))
let contrib = space.extcredits6; //贡献
}
let kindnes = space.extcredits7; //爱心
})
let diamond = space.extcredits8; //钻石
.then((data) => {
let uname = space.username
console.log(data); window.res = data
var json = {};
let space = data.Variables.space
json.credits = {
let credits = space.credits; //总积分
href: 'https://mcbbs-wiki.cn/wiki/%E7%94%A8%E6%88%B7:Salt_lovely',
let post = space.posts; //回帖
text: '小工具由Salt_lovely制作,使用了highcharts开源库'
let thread = space.threads; //主题
}
let digestpost = space.digestposts; //精华
let popular = space.extcredits1; //人气
json.chart = { backgroundColor: '#fbf2da', plotShadow: false };
// let goldngt = space.extcredits2; //金粒
json.tooltip = { pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>' };
json.title = { text: uname + '积分构成' };
// let goldigt = space.extcredits3; //金锭
json.plotOptions = {
// let emerald = space.extcredits4; //绿宝石
pie: {
// let nethers = space.extcredits5; //下界之星
allowPointSelect: true,
let contrib = space.extcredits6; //贡献
cursor: 'pointer',
let kindnes = space.extcredits7; //爱心
let diamond = space.extcredits8; //钻石
colors: ['#7ccade', '#cae07b', '#e37bf9', '#fce37c', '#ff9800', '#fd957e', '#9ba8f3'],
dataLabels: {
let uname = space.username || ''; //用户名
enabled: true,
let group = space.group.grouptitle || ''; //用户组
format: '{point.name}: {point.y}分, 占{point.percentage:.1f} %',
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
},
},
showInLegend: true
}
}
};
Highcharts.setOptions({
json.series = [{
lang: {
type: 'pie',
contextButtonTitle: '图表菜单',
name: '积分占比',
viewFullscreen: "全屏查看",
data: [
exitFullscreen: "退出全屏",
{ name: '发帖数/' + post + '帖', y: Math.round(post / 3) },
printChart: "打印图表",
{ name: '主题数/' + thread + '帖', y: thread * 2 },
downloadJPEG: '导出 JPEG 图片',
{ name: '精华帖/' + digestpost + '帖', y: digestpost * 45 },
downloadPDF: '导出 PDF 文档',
{ name: '人气/' + popular + '点', y: popular * 3 },
downloadPNG: '导出 PNG 图片',
{ name: '贡献/' + contrib + '点', y: contrib * 10 },
downloadSVG: '导出 SVG 矢量图'
{ name: '爱心/' + kindnes + '颗', y: kindnes * 4 },
}
{ name: '钻石/' + diamond + '颗', y: diamond * 2 },
})
]
Highcharts.chart('userpie', json)
}];
})
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)
}
}
})()
})()

2020年11月15日 (日) 12:34的版本