-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
196 lines (184 loc) · 6.18 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
<!DOCTYPE html>
<head>
<title>Shit HN Says</title>
<meta name="description" content="Ackchyually..." />
<meta name="referrer" content="no-referrer" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" href="/sigma.png">
<link rel="apple-touch-icon" href="/sigma.png">
<meta property="og:type" content="website" />
<meta property="og:image" content="/sigma.png">
<meta property="og:url" content="https://hn.hotgarba.ge">
<meta name="twitter:card" content="summary_large_image">
<link href="news.css" rel="stylesheet" />
<style>
html {
filter: invert(1);
}
#hnmain {
width: 85%;
min-width: 750px; /* override stupid min-width/breakpoint mismatch */
}
@media (max-width: 750px) {
#hnmain {
width: 100%;
min-width: 0;
}
}
#hnmain > hr {
border: 0;
background-color: #ff6600;
height: 2px;
width: 100%;
transition-duration: 10s;
transition-timing-function: linear;
}
.title a {
font-weight: bold;
}
.default {
padding: 0 2em;
margin-bottom: 1.5em;
}
</style>
</head>
<body>
<div id="hnmain" style="background: #f6f6ef; margin: 0 auto;">
<table bgcolor="#ff6600" border="0" cellpadding="0" cellspacing="0" width="100%" style="padding:2px; position: -webkit-sticky; position: sticky; top: 0">
<tbody>
<tr>
<td style="width:18px;padding-right:4px"><span
style="border:1px white solid; color: white; display: block; width: 18px; font-weight: bold; text-align: center;">Σ</span>
</td>
<td style="line-height:12pt; height:10px;"><span class="pagetop"><b class="hnname">Shit HN Says</b></td>
</tr>
</tbody>
</table>
<hr />
<div class="yclinks" style="text-align: center; padding-bottom: .5em;">
<a href="https://www.hotgarba.ge" target="_blank">A Hot Garbage project</a> | <a href="https://github.com/hotgarbo/hn" target="_blank">GitHub</a>
</div>
</div>
</body>
<script>
var maxId = 0;
var failures = 0;
var autoscroll = true;
window.addEventListener('scroll', function() {
var bottom = window.scrollY + window.innerHeight >= document.documentElement.scrollHeight - 10;
if (autoscroll && !bottom) {
autoscroll = false;
} else if (!autoscroll && bottom) {
autoscroll = true;
}
});
function maxitem(id) {
console.debug("maxitem", id);
if (maxId == 0) {
// Backfill 4 items on page load
maxId = id - 5;
}
if (id > maxId) {
// maxitem has moved past maxId+1. Assume it'll always be null and move on
console.debug("skipping", maxId + 1);
getItem(maxId + 2);
} else {
getItem(maxId + 1);
}
}
function getItem(id) {
var jsonp = document.getElementById("jsonp");
document.body.removeChild(jsonp);
jsonp = document.createElement("script");
jsonp.id = "jsonp";
jsonp.src = `https://hacker-news.firebaseio.com/v0/item/${id}.json?callback=render&ts=${(new Date()).getTime()}`;
document.body.appendChild(jsonp);
}
function getMaxItem() {
var jsonp = document.getElementById("jsonp");
if (jsonp) {
document.body.removeChild(jsonp);
}
jsonp = document.createElement("script");
jsonp.id = 'jsonp';
jsonp.src = `https://hacker-news.firebaseio.com/v0/maxitem.json?callback=maxitem&ts=${(new Date()).getTime()}`;
document.body.appendChild(jsonp);
}
var burstCount = 0;
var burstTime = (new Date()).getTime();
function render(data) {
console.debug((new Date()).getTime(), data);
if (data) {
burstCount++;
if (failures) console.debug("previous failures", failures);
failures = 0;
maxId = data.id;
var date = (new Date(data.time * 1000)).toISOString();
var title = "";
var by = "";
var navs = "";
if (data.title) {
title = `
<div class="title"><span class="titleline"><a target="_blank" href="${data.url}">${data.title}</a></span></div>
`;
}
if (data.by) {
by = `<a target="_blank" href="https://news.ycombinator.com/user?id=${data.by}" class="hnuser">${data.by}</a>`;
}
if (data.type && data.type === "comment") {
navs = `
<span class="navs">
| <a target="_blank" href="https://news.ycombinator.com/item?id=${data.parent}">parent</a>
| <a target="_blank" href="https://news.ycombinator.com/context?id=${data.id}" rel="nofollow">context</a>
</span>
`;
}
var template = `
<div class="default">
<div style="margin-top:2px; margin-bottom: .25em;">
${title}
<span class="comhead">
${by}
<span class="age" title="${date}"><a target="_blank" href="https://news.ycombinator.com/item?id=${data.id}">${date}</a></span>
${navs}
</span>
</div>
<div class="comment">
<span class="commtext c00">${data.text ? data.text : data.deleted ? "[deleted]" : data.dead ? "[dead]" : ""}</span>
</div>
</div>
`;
document.querySelector("#hnmain > hr").insertAdjacentHTML("beforebegin", template);
if (autoscroll) {
window.scrollTo({
top: document.documentElement.scrollHeight,
left: 0,
behavior: "smooth",
});
}
window.setTimeout(function() { getItem(maxId + 1) }, 1000);
} else {
if (burstCount) {
console.log(burstCount, ((new Date()).getTime() - burstTime) / 1000);
burstCount = 0;
burstTime = (new Date()).getTime();
}
// retry backoff
failures++;
if (failures % 4 == 0) {
// Check if maxItem has moved ahead without us after 30s
getMaxItem();
return;
}
// Try again in 10s
document.querySelector("#hnmain > hr").style.transitionProperty = "width";
document.querySelector("#hnmain > hr").style.width = "0%";
window.setTimeout(function() {
getItem(maxId + 1);
document.querySelector("#hnmain > hr").style.width = "100%";
document.querySelector("#hnmain > hr").style.transitionProperty = "none";
}, 10000);
}
}
getMaxItem();
</script>