This repository has been archived by the owner on May 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
121 lines (101 loc) · 3.01 KB
/
index.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
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
const Plugin = module.parent.require('../Structures/Plugin');
global.jQuery = require("jquery");
require("jquery-ui");
const request = require("request");
const $ = global.jQuery;
class DCards extends Plugin {
constructor(...args) {
super(...args);
// Create all elements
this.div = document.createElement("div");
this.div.id = "DCards-Div"
this.div.innerHTML = `
<div class="DCards-ButtonBar">
<button class="DCards-Button" onclick="openTab('profile')">Profile</button>
<button class="DCards-Button" onclick="openTab('inv')">Inventory</button>
<button class="DCards-Button" onclick="openTab('market')">Market</button>
<button class="DCards-Button" onclick="openTab('quest')">Quest</button>
</div>
<div id="profile" class="DCards-Tab">
</div>
<div id="inv" class="DCards-Tab" style="display:none">
</div>
<div id="market" class="DCards-Tab" style="display:none">
</div>
<div id="quest" class="DCards-Tab" style="display:none">
</div>
<script>
function openTab(tabName) {
var i;
var x = document.getElementsByClassName("DCards-Tab");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
document.getElementById(tabName).style.display = "block";
}
</script>`;
this.log("DCards Elements created!");
document.body.appendChild(this.div);
$(function() {
$("#DCards-Div").draggable();
});
this.user = {
id: DI.client.user.id,
badges: {},
inv: {},
balance: 0,
quest: {},
clubs: [],
offers: []
daily: {next: 0,
streak: 0}
}
this.market = []
}
loadData(){
request("https://api.discord.cards/user/${this.user.id}", (er,, res, body){
data = JSON.parse(body);
this.user.badges = data.badges;
this.user.inv = data.inv;
this.user.balance = data.money;
this.user.quest = data.quest;
this.user.daily = {streak: data.daily.streak,
next: new Date(data.daily.time + 3600*24*1000)};
});
request("https://api.discord.cards/user/${this.user.id}/clubs", (e, r, b){
this.user.clubs = JSON.parse(b);
}
request("https://api.discord.cards/user/${this.user.id}/offers", (e, r, b){
this.user.offers = JSON.parse(b);
}
request("https://api.discord.cards/list/offers", (e, r, b){
this.market = JSON.parse(b);
}
this.reloadData();
}
reloadData(){
$("#profile").innerHTML = `
<table>
<tr>
<th>Balance</th>
<th>Inventory</th>
</tr>
<tr>
<td>${this.user.balance}</td>
<td>${Object.values(this.user.inv).reduce((r,e)=>r+e)} items</td>
</tr>
</table>
<table>
<tr>
<th span=${this.user.badges.length}>
Badges
</th>
</tr>
<tr>
</tr>
</table>`;
}
unload(){
}
};
module.exports = DCards;