-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetail.html
195 lines (183 loc) · 6.28 KB
/
detail.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
190
191
192
193
194
195
<!DOCTYPE html>
<html>
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-128183017-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-128183017-1');
</script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<title>WikiClick</title>
<style>
.algolia-autocomplete {
width: 100%;
}
.algolia-autocomplete .aa-input, .algolia-autocomplete .aa-hint {
width: 100%;
}
.algolia-autocomplete .aa-hint {
color: #999;
}
.algolia-autocomplete .aa-dropdown-menu {
width: 100%;
background-color: #fff;
border: 1px solid #999;
border-top: none;
}
.algolia-autocomplete .aa-dropdown-menu .aa-suggestion {
cursor: pointer;
padding: 5px 4px;
}
.algolia-autocomplete .aa-dropdown-menu .aa-suggestion.aa-cursor {
background-color: #B2D7FF;
}
.algolia-autocomplete .aa-dropdown-menu .aa-suggestion em {
font-weight: bold;
font-style: normal;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<br/><br/><br/>
<a href="/" style="float: left;"><h5>Home</h5></a>
<form action="#" class="form" style="float: right;" >
<input class="form-control" id="search-input" name="id" type="text" placeholder="Search Again!" />
</form>
<br/>
<h1 class="page_name">Detail Page</h1>
<div id="detail_container">
<a id="page_link" href=""><h4>Official Wikipedia Page</h4></a>
<br/>
<h4>Summary</h4>
<p id="page_summary"></p>
<br/>
<h4>Click Statistics</h4>
<p>
Below are some statistics for the wikipedia page on <span class="page_name"></span>! The numbers correspond to the number of clicks people have made over the last year (specifically, November 2017 to September 2018)
</p>
<br/>
<p>
<b>Total Search Hits In Past Year:</b> <span id="searchhits"></span>
<br/><b>Most Popular Month:</b> <span id="topmonth"></span>
<br/><br/>
<b>How do people get here?</b><p></p>
<ul id="clickedto">
</ul>
<br/>
<b>Where do people go from here?</b><p></p>
<ul id="clickedfrom">
</ul>
</p>
<br/><br/>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/autocomplete.js/0/autocomplete.min.js"></script>
<script>
var urlParams = new URLSearchParams(window.location.search);
var id = urlParams.get("id").split(' ').join('_')
var name = urlParams.get("name");
if(name == "null"){
name = id.split('_').join(' ')
}
$(".page_name").text(name)
$("#page_link").attr("href", "https://www.wikipedia.org/wiki/" + id);
document.getElementById('detail_container').style.visibility = "hidden"
var clickedToHTML = "";
var clickedFromHTML = "";
$.ajax('topClicksTo?' + $.param({id: id}), {
type: "GET",
success: function(data) {
if(data.length == 0) {
$('#detail_container').html('<h3>Hm, we couldn\'t find the page: "' + name + '"</h3><br/>It either doesn\'t exist or doesn\'t have enough click data available yet. Try searching for a different one!')
} else {
for(item in data) {
clickedToHTML += '<li><a href="' + data[item].url + '">' + data[item].title + "</a>: " + data[item].count + ' clicks';
}
$('#clickedto').html(clickedToHTML);
}
document.getElementById('detail_container').style.visibility = "visible"
},
error: function() {
console.log("Error, sad");
}
});
$.ajax('topClicksFrom?' + $.param({id: id}), {
type: "GET",
success: function(data) {
if(data.length > 0) {
for(item in data) {
clickedFromHTML += '<li><a href="' + data[item].url + '">' + data[item].title + "</a>: " + data[item].count + ' clicks';
}
$('#clickedfrom').html(clickedFromHTML);
}
},
error: function() {
console.log("Error, sad");
}
});
$.ajax('searchHits?' + $.param({id: id}), {
type: "GET",
success: function(data) {
if(data.length > 0) {
$('#searchhits').text(data[0].count)
}
},
error: function() {
console.log("Error, sad");
}
});
$.ajax('topMonth?' + $.param({id: id}), {
type: "GET",
success: function(data) {
if(data.length > 0) {
$('#topmonth').text(data[0].month.substring(0, 10) + ", Clicks: " + data[0].count)
}
},
error: function() {
console.log("Error, sad");
}
});
$.ajax('summary?' + $.param({id: id}), {
type: "GET",
success: function(summary) {
if(summary != null) {
$('#page_summary').text(summary.split('\n')[0])
}
}
})
function queryServer(query, cb) {
$.ajax('autocomplete?' + $.param({query: query}), {
type: "GET",
success: function(data) {
cb(data);
},
error: function() {
console.log("Error, sad");
}
});
}
autocomplete('#search-input', { hint: false }, [
{
source: queryServer,
displayKey: 'name',
templates: {
suggestion: function(suggestion) {
return suggestion.name;
}
}
}
]).on('autocomplete:selected', function(event, suggestion, dataset) {
window.location.href = '/detail?id=' + suggestion.id + "&name=" + suggestion.name;
});
</script>
</body>
</html>