-
Notifications
You must be signed in to change notification settings - Fork 0
/
stockexchange.html
189 lines (178 loc) · 6.76 KB
/
stockexchange.html
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
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="style.css" />
</head>
<nav>
<button id="backbtn" onclick="window.location.href = 'menu.html' ">
<svg class="svg-icon" viewBox="0 0 20 20">
<path
fill="none"
d="M8.388,10.049l4.76-4.873c0.303-0.31,0.297-0.804-0.012-1.105c-0.309-0.304-0.803-0.293-1.105,0.012L6.726,9.516c-0.303,0.31-0.296,0.805,0.012,1.105l5.433,5.307c0.152,0.148,0.35,0.223,0.547,0.223c0.203,0,0.406-0.08,0.559-0.236c0.303-0.309,0.295-0.803-0.012-1.104L8.388,10.049z"
></path>
</svg>
</button>
<div class="ye">
<p>Stocks</p>
<p id="count" style="font-size: x-small; color: gray">10.000.000.000</p>
</div>
</nav>
<body>
<p style="height: 10vh"></p>
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<p id="totalInfo" style="display: inline">
Total value of stock: value
</p>
<p id="pps">Price per share: pps</p>
<h3>How many shares to buy?</h3>
<div class="slidecontainer">
<input
type="range"
min="1"
max="100"
value="1"
class="slider"
id="myRange"
/>
<p id="output">ammount</p>
<svg class="svg-icon uwu" viewBox="0 0 20 20">
<path
fill="none"
d="M11.611,10.049l-4.76-4.873c-0.303-0.31-0.297-0.804,0.012-1.105c0.309-0.304,0.803-0.293,1.105,0.012l5.306,5.433c0.304,0.31,0.296,0.805-0.012,1.105L7.83,15.928c-0.152,0.148-0.35,0.223-0.547,0.223c-0.203,0-0.406-0.08-0.559-0.236c-0.303-0.309-0.295-0.803,0.012-1.104L11.611,10.049z"
></path>
</svg>
</div>
<button onclick="buyShares()" id="buybtn">Buy</button>
<button onclick="lastStock('-1')">cancel</button>
</div>
</div>
</body>
<script>
let lastCurr = 0;
let lastTotal = 0;
document.getElementById("count").innerHTML =
parseInt(localStorage.getItem("money")).toLocaleString() + "$";
function lastStock(id) {
console.log(id);
console.log(JSON.parse(localStorage.getItem("stocks"))[0]);
//window.location.href = "currstock.html";
if (document.getElementById("myModal").style.display == "block") {
document.getElementById("myModal").style.display = "none";
var output = document.getElementById("output");
output.innerHTML = "1 share for";
document.getElementById("myRange").value = 1;
} else {
document.getElementById("myModal").style.display = "block";
estates = JSON.parse(localStorage.getItem("stocks"));
lastCurr = estates[id].currValue;
lastTotal = estates[id].totalValue;
document.getElementById("myRange").setAttribute(
"max",
parseInt(localStorage.getItem("money")) / lastCurr
);
document.getElementById("totalInfo").innerHTML = `Total value of ${
estates[id].Name
}: ${estates[id].totalValue.toLocaleString()}$`;
document.getElementById("pps").innerHTML = `Price per share: ${parseInt(
estates[id].currValue
)}$`;
}
localStorage.setItem("lastStock", id);
}
function buyShares() {
if (
parseInt(localStorage.getItem("money")) >=
lastCurr * document.getElementById("myRange").value
) {
last = localStorage.getItem("lastStock");
all = JSON.parse(localStorage.getItem("stocks"));
mystock = JSON.parse(localStorage.getItem("ownedStocks"));
let match = false;
let heh = 0;
for (var i = 0; i < mystock.length; i++) {
if (all[last].Name == mystock[i].Name) {
match = true;
heh = i;
}
//Do something
}
if (match) {
mystock[heh].owned =
parseInt(mystock[heh].owned) +
parseInt(document.getElementById("myRange").value);
mystock[heh].pVal = all[last].currValue;
sum =
parseInt(localStorage.getItem("money")) -
all[last].currValue * document.getElementById("myRange").value;
console.log(sum);
localStorage.setItem("money", sum);
sendmsg("Someone just purchased " + sum + "$ of " + all[last].Name);
} else {
mystock.push({
Name: all[last].Name,
owned: document.getElementById("myRange").value,
pVal: all[last].currValue,
});
sum =
parseInt(localStorage.getItem("money")) -
all[last].currValue * document.getElementById("myRange").value;
console.log(sum);
localStorage.setItem("money", sum);
}
localStorage.setItem("ownedStocks", JSON.stringify(mystock));
console.log(localStorage.getItem("ownedStocks"));
document.getElementById("myModal").style.display = "none";
sendmsg("Someone just purchased " + sum + "$ of " + all[last].Name);
} else {
alert("insufficient funds!");
}
}
refresh();
function refresh() {
let stocks;
stocks = JSON.parse(localStorage.getItem("stocks"));
for (let i = 0; i < stocks.length; i++) {
btn = document.createElement("div");
btn.innerHTML = `<button id="${i}" onclick="lastStock(this.id)">
<p style="float: left;">${i}</p>${stocks[i].Name}<p style="color: gray;"> Price per share: ${stocks[i].currValue}$</p></button>`;
document.body.appendChild(btn);
}
}
var slider = document.getElementById("myRange");
var output = document.getElementById("output");
output.innerHTML = slider.value; // Display the default slider value
// Update the current slider value (each time you drag the slider handle)
slider.oninput = function () {
output.innerHTML =
this.value +
" shares for " +
(lastCurr * this.value).toLocaleString() +
"$";
};
/*Name: "Borgir shop",
totalValue: "20.000.000",
currValue: "3",
owned: "0",*/
function sendmsg(msg) {
const request = new XMLHttpRequest();
request.open(
"POST",
"https://discord.com/api/webhooks/928611032451121152/f4qpvZTEIZH46pTFD1KUKUKlXKOtX31UW54jruJeAq1ydyxduZ9c3uhx0rU4Az4PKZDk"
);
request.setRequestHeader("Content-type", "application/json");
const params = {
username: "logBot",
avatar_url:
"https://cdn.discordapp.com/attachments/822543812253581422/928611564318244894/logo.png",
content: msg,
};
request.send(JSON.stringify(params));
}
</script>
</html>