-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwho-is-hiring.tmpl.html
153 lines (124 loc) · 4.63 KB
/
who-is-hiring.tmpl.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
<!doctype html>
<html lang="en">
<head>
<title class="title">{{.Title}}</title>
<link href="who-is-hiring.css" rel="stylesheet">
<meta charset="utf-8">
</head>
<body>
<h1 class="title"><a href="https://news.ycombinator.com/item?id={{.ID}}">{{.Title}}</a></h1>
<div id="text">{{.Text}}</div>
<hr>
<div class="filter">
<button id="remote">Remote</button>
<button id="intern">Interns</button>
<button id="visa">Visa</button>
<br/>
<label>
Case insensitive filtering:
<input id="query" type="text" placeholder="hit enter to activate the filter" />
Filters can be string literals or JS regular expressions (do not use surrounding slashes).
</label>
</div>
<hr>
<div class="removed">
<button id="restoreAllRemoved">Restore All Removed Items</button>
</div>
<hr>
<div class="comments">
{{range .Comments}}
<div
class="content {{if .Remote}} remote {{end}}{{if .Interns}} interns {{end}}{{if .Visa}} visa {{end}}"
{{if gt .Level 0 }}style="margin-left: {{spacer .Level}}px"{{end}}
id="comment_{{.ID}}"
>
<div class="close">×</div>
<strong>by <a href="https://news.ycombinator.com/user?id={{.By}}">{{.By}}</a></strong>
<small><a href="https://news.ycombinator.com/item?id={{.ID}}">Original Post</a> {{ts .Time}}</small>
{{if or (gt .PrevID 0) (gt .NextID 0)}} | {{end}}
{{if gt .PrevID 0}}<a href="#" class="scrolly" data-scroll-to-id="comment_{{.PrevID}}">Prev</a>{{end}}
{{if and (gt .PrevID 0) (gt .NextID 0)}} | {{end}}
{{if gt .NextID 0}}<a href="#" class="scrolly" data-scroll-to-id="comment_{{.NextID}}">Next</a>{{end}}
<br><br>
{{.Text}}
</div>
{{end}}
</div>
<footer>The content for this page was fetched at {{ts .FetchedAt}}. The code for this tool is on <a href="https://github.com/nchelluri/hnjobs">GitHub</a>.</footer>
<script>
var comments = document.getElementsByClassName('comments')[0].getElementsByClassName('content');
function filterButton(hiddenKlass, initialText, afterText, keyword) {
return function filter(e) {
var button = e.currentTarget;
if (button.innerText == initialText) {
for (var i = 0; i < comments.length; i++) {
if (! comments[i].classList.contains(keyword)) {
comments[i].classList.add(hiddenKlass);
}
}
button.innerText = afterText;
} else {
for (var i = 0; i < comments.length; i++) {
comments[i].classList.remove(hiddenKlass);
}
button.innerText = initialText;
}
};
}
document.getElementById('remote').addEventListener('click', filterButton('remoteHidden', 'Remote', 'Remote & Onsite', 'remote'));
document.getElementById('intern').addEventListener('click', filterButton('internsHidden', 'Interns', 'Interns & FT', 'interns'));
document.getElementById('visa').addEventListener('click', filterButton('visaHidden', 'Visa', 'Visa & Non-Visa', 'visa'));
document.getElementById('query').addEventListener('change', function(e) {
var textField = e.currentTarget;
var hiddenKlass = 'queryHidden';
if (textField.value === '') {
for (var i = 0; i < comments.length; i++) {
comments[i].classList.remove(hiddenKlass);
}
} else {
for (var i = 0; i < comments.length; i++) {
if (! comments[i].innerText.match(new RegExp(textField.value, 'i'))) {
comments[i].classList.add(hiddenKlass);
}
}
}
});
document.addEventListener('click', function(e) {
var target = e.target;
if (target.tagName == 'DIV' && target.classList.contains('close')) {
if (target.parentNode.id) {
var removed = localStorage.getItem('removed');
if (! removed) {
removed = {};
} else {
removed = JSON.parse(removed);
}
removed[target.parentNode.id] = true;
localStorage.setItem("removed", JSON.stringify(removed));
}
target.parentNode.parentNode.removeChild(target.parentNode);
} else if (target.tagName == 'A' && target.classList.contains('scrolly')) {
if (target.dataset.scrollToId) {
var el = document.getElementById(target.dataset.scrollToId);
el.scrollIntoView({ behavior: 'smooth' });
e.preventDefault();
}
}
});
document.getElementById('restoreAllRemoved').addEventListener('click', function() {
localStorage.setItem('removed', JSON.stringify({}));
window.location.reload();
});
var removed = localStorage.getItem('removed');
if (removed) {
removed = JSON.parse(removed);
Object.keys(removed).forEach(function(id) {
var comment = document.getElementById(id);
if (comment) {
comment.parentNode.removeChild(comment);
}
});
}
</script>
</body>
</html>