-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
177 lines (151 loc) · 5.28 KB
/
main.js
File metadata and controls
177 lines (151 loc) · 5.28 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Configurable vars
const API_URL = "https://api.allorigins.win/get?url=https://kickthespy.pet"
const REPO_USER = "Nitrrine"
const REPO_NAME = "have-i-been-scraped-by-spy-pet"
// Misc
const goodResult = document.getElementById("good-result")
const badResult = document.getElementById("bad-result")
const errorResult = document.getElementById("error-result")
const infoResult = document.getElementById("info-result")
let globalData = []
// Provider's API
const ThatSINEWAVE_LIST_URL =
"https://raw.githubusercontent.com/ThatSINEWAVE/Spy.pet-Info/main/data/detailed_servers_and_ids.json"
// Functions
function showBadResult(botName, botUsername, botId, botAvatar) {
document.getElementById("botName").innerText = botName
document.getElementById("botUsername").innerText = botUsername
document.getElementById("botId").innerText = botId
document.getElementById("botAvatar").setAttribute("src", botAvatar)
goodResult.classList.add("hide")
badResult.classList.remove("hide")
errorResult.classList.add("hide")
infoResult.classList.add("hide")
}
function showGoodResult() {
goodResult.classList.remove("hide")
badResult.classList.add("hide")
errorResult.classList.add("hide")
infoResult.classList.add("hide")
}
function showError(error) {
document.getElementById("error").innerText = error
goodResult.classList.add("hide")
badResult.classList.add("hide")
errorResult.classList.remove("hide")
infoResult.classList.add("hide")
}
function showInfo(error) {
document.getElementById("info").innerText = error
goodResult.classList.add("hide")
badResult.classList.add("hide")
errorResult.classList.add("hide")
infoResult.classList.remove("hide")
}
function copyText(text) {
navigator.clipboard.writeText(text)
alert(`Copied "${text}"!`)
}
// Do something on page load
document.addEventListener("DOMContentLoaded", () => {
document
.getElementById("createIssueLink")
.setAttribute("href", `https://github.com/${REPO_USER}/${REPO_NAME}/issues`)
})
// When we click button, main process begins here
document
.getElementById("check-btn")
.addEventListener("click", function (event) {
const serverId = document.getElementById("serverId").value
const provider = document.getElementById("provider").value
// Fix sending empty serverID
if (!serverId.length) return
if (parseInt(serverId)) {
// This is minimum Discord server ID length
if (serverId.length < 18) {
showError(
"Please check Discord Server ID field, use FAQ if you don't know how to get Server ID"
)
return
}
// Checks what provider is being used, currently we have only one but maybe new in future?
if (provider == "default") {
fetch(`${API_URL}/getBot?id=${serverId}`)
.then((response) => response.json())
.then((data) => {
// If response contains bot ID == server is being tracked
if (data.id) {
showBadResult(
data.global_name,
data.username,
data.id,
data.avatarURL
)
globalData = data
} else {
showGoodResult()
}
})
.catch((error) => showError(error))
} else if (provider == "thatsinewave") {
fetch(ThatSINEWAVE_LIST_URL)
.then((response) => {
// If response contains guild ID == server is being tracked
response.text().then(function (content) {
const json = JSON.parse(content)
for (const botId in json) {
if (json.hasOwnProperty(botId)) {
const servers = json[botId]
for (const server of servers) {
if (server.serverid === serverId) {
showBadResult(
server.global_name,
server.username,
server.id,
server.avatar
)
globalData = server
return
}
showGoodResult()
}
}
}
})
})
.catch((error) => showError(error))
}
} else {
const splitInviteLink = serverId.split("/")
const inviteLink = splitInviteLink[splitInviteLink.length - 1]
fetch(`${API_URL}/byInv?code=/${inviteLink}`)
.then((response) => response.json())
.then((data) => {
// If response contains bot ID == server is being tracked
if (data.id) {
showBadResult(
data.global_name,
data.username,
data.id,
data.avatarURL
)
globalData = data
} else {
showGoodResult()
}
})
.catch((error) => showError(error))
}
})
// Functions for action buttons
document.getElementById("copy-ban-command").addEventListener("click", () => {
copyText(
`/ban user:@${globalData.username} delete_messages:Don't Delete Any reason:spy.pet bot account`
)
})
document.getElementById("copy-username").addEventListener("click", () => {
copyText(globalData.username)
})
document.getElementById("copy-id").addEventListener("click", () => {
copyText(globalData.id)
})