-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
156 lines (123 loc) · 4.48 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
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
function iOS() {
return [
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod'
].includes(navigator.platform)
// iPad on iOS 13 detection
|| (navigator.userAgent.includes("Mac") && "ontouchend" in document)
}
function convertToInternationalCurrencySystem (labelValue) {
// Nine Zeroes for Billions
return Math.abs(Number(labelValue)) >= 1.0e+9
? (Math.abs(Number(labelValue)) / 1.0e+9).toFixed(2) + "B"
// Six Zeroes for Millions
: Math.abs(Number(labelValue)) >= 1.0e+6
? (Math.abs(Number(labelValue)) / 1.0e+6).toFixed(2) + "M"
// Three Zeroes for Thousands
: Math.abs(Number(labelValue)) >= 1.0e+3
? (Math.abs(Number(labelValue)) / 1.0e+3).toFixed(2) + "K"
: Math.abs(Number(labelValue));
}
async function fetchCors(url='')
{
const response = await fetch('https://api.allorigins.win/get?url=https://www.reddit.com/r/ethtrader.json');
const json = await response.json();
if(json.contents)
{
return JSON.parse(json.contents);
}
}
window.onload = function()
{
const Http = new XMLHttpRequest();
const url = 'https://api.etherscan.io/api?module=stats&action=tokensupply&contractaddress=0xc0f9bd5fa5698b6505f643900ffa515ea5df54a9&apikey=KIX2DUCUIVGT5PMEKF65TJIXMSQXTFCRYH';
Http.open('GET', url);
Http.send();
Http.onreadystatechange = function()
{
if(this.readyState == 4 && this.status == 200)
{
const obj = JSON.parse(Http.responseText);
var supply = obj.result;
document.querySelector(".total-supply").innerHTML = convertToInternationalCurrencySystem(supply.slice(0 , -18));
}
}
const Http1 = new XMLHttpRequest();
const url1 = 'https://api.coingecko.com/api/v3/simple/price?ids=donut&vs_currencies=usd&include_market_cap=true';
Http1.open('GET', url1);
Http1.send();
Http1.onreadystatechange = function()
{
if(this.readyState == 4 && this.status == 200)
{
const obj1 = JSON.parse(Http1.responseText);
var price = obj1.donut.usd;
price = price.toString().slice(0, 6);
var marketCap = Math.floor(parseFloat(obj1.donut.usd_market_cap));
marketCap = convertToInternationalCurrencySystem(obj1.donut.usd_market_cap);
document.querySelector(".price").innerHTML = '$' + price;
document.querySelector(".market-cap").innerHTML = marketCap;
}
}
fetchCors().then(function(result)
{
var members = result['data']['children'][0]['data']['subreddit_subscribers'];
members = convertToInternationalCurrencySystem(members);
document.querySelector(".members").innerHTML = members;
var top_posts = [];
var author = [];
var upvotes = [];
var flair = [];
var url = [];
for(var i = 0;i < 9;i++)
{
top_posts.push(result['data']['children'][i]['data']['title']);
author.push(result['data']['children'][i]['data']['author']);
upvotes.push(result['data']['children'][i]['data']['score']);
flair.push(result['data']['children'][i]['data']['link_flair_text']);
url.push(result['data']['children'][i]['data']['permalink']);
}
// console.log(top_posts);
var i = 0;
var selector;
var collection;
for(i = 0;i < 9;i++)
{
var row, post;
if (i >=0 && i<=2)
{
row = 1;
post = (i % 3) + 1;
}
if (i >=3 && i<=5)
{
row = 2;
post = (i % 3) + 1;
}
if (i >=6 && i<=8)
{
row = 3;
post = (i % 3) + 1;
}
selector = `.r${row}p${post}`;
collection = document.querySelectorAll(selector);
for(item of collection)
{
item.innerHTML = top_posts[i];
item.innerHTML += ` by user ${author[i]}, flaired ${flair[i]} with ${upvotes[i]} upvotes`;
item.href = "https://www.reddit.com" + url[i];
}
}
});
if(iOS())
{
console.log("Device is iOS");
var collection = document.getElementsByTagName("picture");
collection.item(0).innerHTML = '<source type="image/gif" srcset="donut1.gif">' + collection.item(0).innerHTML;
console.log("iOS fix applied");
}
}