-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
103 lines (77 loc) · 2.79 KB
/
Copy pathindex.js
File metadata and controls
103 lines (77 loc) · 2.79 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
const guildId = -1;
var maxPage = 9999999999999;
const apiUrl = `https://www.boardgamegeek.com/xmlapi2/guild?id=${guildId}&members=1&page=`;
async function next() {
if (+document.querySelector("#pageNumber").textContent == maxPage) {
document.getElementById("namesList").value = "No more members";
return;
}
let pageNum = document.querySelector("#pageNumber").textContent;
if (pageNum === '') {
document.querySelector("#pageNumber").textContent = '1';
await getValues();
return;
}
document.querySelector("#pageNumber").textContent = +pageNum + 1;
await getValues();
}
async function prev() {
let pageNum = document.querySelector("#pageNumber").textContent;
if (pageNum === '') {
document.querySelector("#pageNumber").textContent = '1';
await getValues();
return;
} else if (pageNum === '1') {
// await getValues();
return;
}
document.querySelector("#pageNumber").textContent = +pageNum - 1;
await getValues();
}
async function getValues() {
let names = "";
let URL = apiUrl + document.querySelector("#pageNumber").textContent;
try {
const response = await fetch(URL);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const xmlText = await response.text();
if (xmlText === "<?xml version=\"1.0\" encoding=\"utf-8\"?><error message='Not Found' />") {
document.getElementById("namesList").value = "Invalid GuildID!";
return;
}
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlText, "application/xml");
const membersTag = xmlDoc.querySelector('members');
if (membersTag) {
const memberElements = membersTag.querySelectorAll('member');
memberElements.forEach(member => {
names += member.getAttribute("name") + ", ";
});
} else {
console.log('No members tag found in the response.');
names = "No more members ";
maxPage = +document.querySelector("#pageNumber").textContent;
}
} catch (error) {
console.error('Error fetching data:', error);
}
names = names.slice(0, -2);
document.getElementById("namesList").value = names;
}
function toClipboard() {
let txt = document.getElementById("namesList");
txt.select();
txt.setSelectionRange(0, 99999);
navigator.clipboard.writeText(txt.value);
}
function toggleTheme() {
document.body.classList.toggle("dark");
let themeButton = document.querySelector("#themeButton");
if(themeButton.textContent === "Dark Theme") {
themeButton.textContent = "Light Theme";
} else {
themeButton.textContent = "Dark Theme";
}
}