-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
85 lines (69 loc) · 3.11 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var request = new XMLHttpRequest()
request.open('GET', 'https://statme-api.tk/v1/message/guild/507389389098188820/', true)
document.addEventListener('DOMContentLoaded', async ()=>{
request.onload = async function() {
if(request.status >= 200 && request.status < 400){
const messages = JSON.parse(this.response)
let
channels_id = new Set(),
users_id = new Set()
messages.forEach(message => {
channels_id.add(message.channel_id)
users_id.add(message.user_id)
})
channels_id = Array.from(channels_id)
users_id = Array.from(users_id)
function messageByDay(user_id){
const day = 1000*60*60*24
const userMessages = messages.filter(message => message.user_id === user_id)
if(userMessages.length < 1) return 0
const start = userMessages.sort((a,b) => a.created_timestamp - b.created_timestamp)[0].created_timestamp
const time = Date.now() - start
const days = time / day
const result = Math.min( Math.round( userMessages.length / days ), userMessages.length )
return result
}
function messageOf(user_id){
return messages.find(message => message.user_id === user_id)
}
const info = document.getElementById('info')
info.innerHTML = `
<header>
<h2> Activity by <a href="https://statme-api.tk/"> Statme </a> </h2>
</header>
<main>
<h4> STATISTICS BASED ON THE FOLLOWING </h4>
<h3> 📨Messages : ${messages.length} </h3>
<h3> 🛰️Channels : ${channels_id.length} </h3>
<h3> 👨🔬Members : ${users_id.length} </h3>
<h4> TOP 10 ACTIVITY </h4>
<ol>
${users_id
.sort((a,b) => messageByDay(b) - messageByDay(a))
.slice(0,10)
.map(user_id => `
<li>
<img src="${messageOf(user_id).user_image}" alt="" height="16">
<div>
${messageOf(user_id).user_name}
</div>
<div>
${messageByDay(user_id)} msg / day
</div>
</li>
`).join('')
}
</ol>
</main>
<footer>
</footer>
`
}else{
console.error('error', request.status)
}
}
request.send()
})
function map(value, min, max, targetMin, targetMax) {
return targetMin + (targetMax - targetMin) * ((value - min) / (max - min));
}