forked from plibither8/refined-hacker-news
-
Notifications
You must be signed in to change notification settings - Fork 0
/
past-choose-date.js
66 lines (55 loc) · 1.41 KB
/
past-choose-date.js
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
function init() {
const navigator = document
.querySelectorAll("table.itemlist > tbody > tr")[3]
.querySelectorAll("td")[1];
const yearInput = document.createElement("select");
const monthInput = document.createElement("select");
const dayInput = document.createElement("select");
// Year Input
for (let y = new Date().getFullYear(); y >= 2007; y--) {
yearInput.innerHTML += `<option value=${y}>${y}</option>`;
}
// Month Input
for (let m = 1; m <= 12; m++) {
m = String(m).padStart(2, "0");
monthInput.innerHTML += `<option value=${m}>${m}</option>`;
}
// Day Input
for (let d = 1; d <= 31; d++) {
d = String(d).padStart(2, "0");
dayInput.innerHTML += `<option value=${d}>${d}</option>`;
}
const goSpan = document.createElement("span");
goSpan.classList.add("hnmore");
const goBtn = document.createElement("a");
goBtn.href = "javascript:void(0)";
goBtn.innerHTML = "Go";
goBtn.addEventListener("click", () => {
window.location.href = `front?day=${yearInput.value}-${monthInput.value}-${
dayInput.value
}`;
});
goSpan.append(goBtn);
navigator.append(
" Choose a date: ",
yearInput,
"-",
monthInput,
"-",
dayInput,
" ",
goSpan,
"."
);
return true;
}
const details = {
id: "past-choose-date",
pages: {
include: ["/front"],
exclude: [],
},
loginRequired: false,
init,
};
export default details;