-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.html
More file actions
190 lines (189 loc) · 6.14 KB
/
analytics.html
File metadata and controls
190 lines (189 loc) · 6.14 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
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>News</title>
<link rel="stylesheet" href="./custom.css" />
</head>
<body>
<div class="container">
<div class="row1">
<p style="margin-left: 40px;">
<span style="font-size: 20px;"
><strong
><a href="index.html">Hacker News</a> </strong
></span
><span class="tab"><a href="index.html">News</a> </span
><span style="font-size: 16px;"> |</span
><span class="tab"
> <a href="analytics.html">Analytics</a>
</span
><span style="font-size: 16px;">| </span
><span class="tab">
<a href="notes.html">Notes</a> </span
><span style="font-size: 16px;">|</span
><span class="tab"
> <a href="submit.html">Submit</a></span
>
</p>
</div>
<div class="row2">
<button onClick="sort_by_vote()" id="vote_show_hide">
Sort By Votes
</button>
<button onClick="sort_by_spam()" id="spam_show_hide">
Sort by Spam
</button>
<br />
<div id="vote"></div>
<div id="spam"></div>
</div>
</div>
<script src="./custom.js"></script>
<script>
var retrievedData = localStorage.getItem("n");
var n = parseInt(JSON.parse(retrievedData)[0]);
var arr = JSON.parse(localStorage.getItem("url_ls"));
for (i = 0; i < n; i++) {
var dm = extractRootDomain(arr[i]);
localStorage.removeItem(dm);
}
for (i = 0; i < n; i++) {
var vt = "vote[" + i.toString() + "]";
var val = 0;
if (localStorage.getItem(vt)) {
var dm = extractRootDomain(arr[i]);
val = parseInt(localStorage.getItem(vt));
if (localStorage.getItem(dm)) {
entries = parseInt(localStorage.getItem(dm));
var temp = entries + val;
localStorage.setItem(dm, temp);
} else {
localStorage.setItem(dm, val);
}
}
}
var a = [];
function sort_by_vote() {
var retrievedData = localStorage.getItem("n");
var n = parseInt(JSON.parse(retrievedData)[0]);
var arr = JSON.parse(localStorage.getItem("url_ls"));
var h = "";
for (i = 0; i < n; i++) {
var dm = extractRootDomain(arr[i]);
if (a.includes(dm)) {
continue;
} else {
for (j = 0; j < n; j++) {
var tem = extractRootDomain(arr[j]);
if (a.includes(tem)) {
continue;
} else {
if (
parseInt(localStorage.getItem(tem)) >
parseInt(localStorage.getItem(dm))
) {
dm = tem;
}
}
}
a.push(dm);
if (dm) {
h += "<p>" + dm + ": " + localStorage.getItem(dm) + " votes</p>";
}
}
}
if (document.getElementById("vote")) {
document.getElementById("vote").innerHTML += h;
}
var x = document.getElementById("vote");
var y = document.getElementById("spam");
if (x.style.display === "none") {
x.style.display = "block";
y.style.display= "none"
} else {
x.style.display = "none";
x.style.display = "none";
}
}
var arr2 = JSON.parse(localStorage.getItem("url_ls"));
for (i = 0; i < n; i++) {
var temp = extractRootDomain(arr2[i]);
var dm= temp +".spam"
localStorage.removeItem(dm);
}
for (i = 0; i < n; i++) {
var fl = "flg[" + i.toString() + "]";
var val = 0;
if (localStorage.getItem(fl)) {
var temp = extractRootDomain(arr2[i]);
var dm = temp + ".spam"
val = parseInt(localStorage.getItem(fl));
if (localStorage.getItem(dm)) {
entries = parseInt(localStorage.getItem(dm));
var temp = entries + val;
localStorage.setItem(dm, temp);
} else {
localStorage.setItem(dm, val);
}
}
}
var fa = [];
function sort_by_spam() {
var retrievedData = localStorage.getItem("n");
var n = parseInt(JSON.parse(retrievedData)[0]);
var arr2 = JSON.parse(localStorage.getItem("url_ls"));
var h = "";
for (i = 0; i < n; i++) {
var temp = extractRootDomain(arr2[i]);
var dm = temp + ".spam"
if (fa.includes(dm)) {
continue;
} else {
for (j = 0; j < n; j++) {
var temporary = extractRootDomain(arr2[j])
var tem = temporary + ".spam";
if (fa.includes(tem)) {
continue;
} else {
if (
parseInt(localStorage.getItem(tem)) >
parseInt(localStorage.getItem(dm))
) {
dm = tem;
}
}
}
fa.push(dm);
if (dm) {
var p=(dm.split('.').slice(0, -1));
var name_of_domain=""
for(k=0;k<p.length;k++){
if((k+1)!=p.length){
name_of_domain+=p[k]+"."
}
else{
name_of_domain+=p[k]
}
}
h += "<p>" + name_of_domain + ": " + localStorage.getItem(dm) + " Flagged</p>";
}
}
}
if (document.getElementById("spam")) {
document.getElementById("spam").innerHTML += h;
}
var x = document.getElementById("spam");
var y = document.getElementById("vote");
if (x.style.display === "none") {
x.style.display = "block";
y.style.display= "none"
} else {
x.style.display = "none";
x.style.display = "none";
}
}
</script>
</body>
</html>