-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnico-search-range-increment.user.js
More file actions
58 lines (51 loc) · 2.58 KB
/
Copy pathnico-search-range-increment.user.js
File metadata and controls
58 lines (51 loc) · 2.58 KB
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
// ==UserScript==
// @name Nico Super Search Month Increment Helper
// @namespace https://github.com/horyu/
// @version 2025.5.14
// @description ニコニコ超検索( https://gokulin.info/search/ )の検索条件フォームに「Next Month Range」ボタンを追加します。ボタンをクリックすると現在の投稿日Toを基準に、投稿日From(翌月1日)・投稿日To(翌月最終日)・再生数Min(経過月数x840)を設定します。
// @author horyu (https://github.com/horyu/)
// @match https://gokulin.info/search/result.php*
// @grant none
// ==/UserScript==
(function () {
"use strict";
// Get input elements for From/To date and play count min strictly by DOM info
const fromInput = document.querySelector('input#dateform1[name="dn"][type="date"]');
const toInput = document.querySelector('input#dateform2[name="dx"][type="date"]');
const playCountMinInput = document.querySelector('input[name="vn"][type="number"]');
const PLAY_COUNT_PER_MONTH = 840;
const button = document.createElement("button");
button.textContent = "Next Month Range";
button.type = "button";
button.className = "search-submit";
button.addEventListener("click", () => {
if (!fromInput || !toInput || !playCountMinInput) {
alert("Input element not found.");
return;
}
if (!toInput.value) {
alert("To (date) is not set.");
return;
}
// Use toInput date as base, set From to the 1st of next month, To to the last day of next month
const base = new Date(toInput.value);
const fromDate = new Date(base.getFullYear(), base.getMonth() + 1, 1); // 1st of next month
const toDate = new Date(base.getFullYear(), base.getMonth() + 2, 0); // last day of next month
// Set in yyyy-mm-dd format
const pad = (n) => n.toString().padStart(2, "0");
const format = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
fromInput.value = format(fromDate);
toInput.value = format(toDate);
// Calculate elapsed months (difference in months between now and From)
const now = new Date();
let months = (now.getFullYear() - fromDate.getFullYear()) * 12 + (now.getMonth() - fromDate.getMonth());
if (now.getDate() < fromDate.getDate()) months--;
if (months < 0) months = 0;
playCountMinInput.value = months * PLAY_COUNT_PER_MONTH;
});
// Insert the button before the search button
const searchBtn = document.querySelector('button.search-submit');
if (searchBtn && searchBtn.parentNode) {
searchBtn.parentNode.insertBefore(button, searchBtn);
}
})();