-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
221 lines (208 loc) · 7.71 KB
/
index.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<html>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.0/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<style type="text/css">
h1,h2,h3{line-height:1.6; font-size: 25px !important;}
header{line-height: 1.6}
body{margin:40px auto;max-width:650px;color:#444;padding:0 10px}}
</style>
<link rel="stylesheet" type="text/css" href="reddit.css">
<script type="text/babel">
Date.prototype.toRelativeString = function() {
// approximates this time relative to now as a human-readable string
var msPerMin = 60 * 1000;
var msPerHr = msPerMin * 60;
var msPerDay = msPerHr * 24;
var msPerMonth = msPerDay * 30;
var msPerYear = msPerMonth * 12;
var elapsed = new Date().getTime() - this.getTime()
if (elapsed < msPerMin) {
return 'just now';
} else if (elapsed < msPerHr) {
var result = Math.floor(elapsed / msPerMin)
return (result == 1) ? 'a minute ago' : result + ' minutes ago';
} else if (elapsed < msPerDay) {
var result = Math.floor(elapsed / msPerHr)
return (result == 1) ? 'an hour ago' : result + ' hours ago';
} else if (elapsed < msPerMonth) {
var result = Math.floor(elapsed / msPerDay)
return result + ' day' + (result == 1 ? '' : 's') + ' ago';
} else if (elapsed < msPerYear) {
var result = Math.floor(elapsed / msPerMonth)
return result + ' month' + (result == 1 ? '' : 's') + ' ago';
} else {
var result = Math.round(elapsed / msPerYear)
return result + ' year' + (result == 1 ? '' : 's') + ' ago';
}
}
var Thumbnail = React.createClass({
render: function(){
if (this.props.thumbnail==="self" || this.props.thumbnail==="default"){
return (
<a className="thumbnail may-blank self"></a>
)
} else if(this.props.thumbnail===""){
return (
<a></a>
)
} else{
return (
<a className="thumbnail may-blank outbound">
<img src={this.props.thumbnail} width="70" height="36" alt></img>
</a>
)
}
}
})
var Tagline = React.createClass({
render: function(){
var userURL ="https://www.reddit.com/user/" + this.props.author;
var subURL = "https://www.reddit.com/r/"+this.props.subreddit;
var created = new Date(this.props.timestamp * 1000);
if (this.props.author==="[deleted]"){
return (
<p className="tagline">
Submitted <time title={created.toString()}>{created.toRelativeString()}</time> by [deleted] to <a href={subURL}> /r/{this.props.subreddit}</a>
</p>
)
} else{
return (
<p className="tagline">
Submitted <time title={created.toString()}>{created.toRelativeString()}</time> by <a href={userURL}>{this.props.author}</a> to <a href={subURL}> /r/{this.props.subreddit}</a>
</p>
)
}
}
});
var Post = React.createClass({
render: function(){
return (
<div className="thing odd link">
<p className="parent"></p>
<span className="rank">{this.props.count + 1}</span>
<div className="midcol unvoted">
<div className="arrow up login-required access-required"></div>
<div className="score dislikes">0</div>
<div className="score unvoted">{this.props.data.score}</div>
<div className="score likes">0</div>
<div className="arrow down"></div>
</div>
<Thumbnail thumbnail={this.props.data.thumbnail} />
<div className="entry">
<p className="title">
<a className="title" href={this.props.data.url} target="_blank">
{this.props.data.title}
</a>
</p>
<Tagline author={this.props.data.author} subreddit={this.props.data.subreddit} timestamp={this.props.data.created_utc}/>
<ul className="flat-list buttons">
<li className="first">
<a href={"https://www.reddit.com"+this.props.data.permalink} target="_blank">
{this.props.data.num_comments+" comments"}
</a>
</li>
</ul>
</div>
<div className="child"></div>
<div className="clearleft"></div>
</div>
)
}
})
var PostList = React.createClass({
render: function(){
var curCount = this.props.count;
var postNodes = this.props.data.children.map(function(post, i){
return (<Post data={post.data} key={i} count={curCount-i}/>)
});
var tempNodes = [];
for (var i = postNodes.length - 1; i >= 0; i--) {
tempNodes.push(postNodes[i]);
tempNodes.push((<div className="clearleft" key={i+postNodes.length}></div>));
};
postNodes = tempNodes;
return (
<div className="postList sitetable linklisting">
{postNodes}
</div>
)
}
});
var pageData;
var totCount = 25;
var timeFrame = 'day';
$.getJSON('https://www.reddit.com/r/all/top/.json?before=t3_1juwvl&t='+timeFrame+'&callback=', function(data){
$('#'+timeFrame).css('font-weight', 'bold');
pageData = data;
console.log(pageData);
ReactDOM.render(
<PostList data = {pageData.data} count = {totCount}/>,
document.getElementById('content')
);
});
$('.nextPage').on('click', function(){
var markPage = pageData.data.children[0].data.name;
$('#content').empty();
$.getJSON('https://www.reddit.com/r/all/top/.json?before='+markPage+'&t='+timeFrame+'&callback=', function(data){
pageData = data;
totCount+=25;
console.log(pageData);
ReactDOM.render(
<PostList data = {pageData.data} count = {totCount}/>,
document.getElementById('content')
);
});
})
$('.timeFrame').on('click', function(){
$('#content').empty();
$('.timeFrame').css('font-weight', 'normal');
$(this).css('font-weight', 'bold')
timeFrame = $(this).attr('id');
$.getJSON('https://www.reddit.com/r/all/top/.json?before=t3_1juwvl&t='+timeFrame+'&callback=', function(data){
pageData = data;
totCount = 25;
console.log(pageData);
ReactDOM.render(
<PostList data = {pageData.data} count = {totCount}/>,
document.getElementById('content')
);
});
});
</script>
<!-- <div id="content"></div> -->
<body class="listing-page">
<header>
<h1>
Notreddit: The most downvoted posts on reddit
</h1>
<hr>
<div>As of 12/9/16, this site is broken due to Reddit messing with all the vote counts. After a couple weeks (or when somebody reminds me), once vote counts stabilize, I will get back to fixing this site. </div>
links from: <a class='timeFrame' id='all' href='#'>all time</a> | <a class='timeFrame' id='year' href='#'>past year</a> | <a class='timeFrame' id='month' href='#'>past month</a> | <a class='timeFrame' id='day' href='#'>past day</a> | <a class='timeFrame' id='hour' href='#'>past hour</a>
<div class="nav-buttons">
<span class="nextprev nextPage">view more: <a href="#">next ›</a></span>
</div>
<div class="content">
<div class="spacer" id="content">
</div>
</div>
<div class="nav-buttons">
<span class="nextprev nextPage">view more: <a href="#">next ›</a></span>
</div>
</body>
<footer>
Created by Horace He.
<a href="https://github.com/Chillee">Github</a> |
Contact me at [email protected]
</footer>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-74734596-3', 'auto');
ga('send', 'pageview');
</script>
</html>