-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
214 lines (178 loc) · 6.25 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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Misskeyノート検索</title>
<style>
@viewport {
width: device-width;
zoom: 1.0;
}
input,
textarea,
select,
button {
font-size: 18px;
}
#notesContainer,
#searchContainer,
form {
max-width: 98%;
margin: 0 auto;
}
#notesContainer {
display: flex;
flex-direction: column;
}
#notesContainer>div:nth-child(even) {
background-color: rgba(173, 216, 230, 0.3);
}
a {
text-decoration: none;
color: black;
border-bottom: 1px solid rgba(0, 0, 0, 0.2);
padding: 0.5em 0;
}
span.date-text {
font-size: 0.8em;
display: block;
}
p.cw-text {
color: rgba(0, 0, 0, 0.6);
margin-right: 3ch;
}
p.note-text {
color: black;
}
</style>
</head>
<body>
<form id="form">
<label for="instance">Instance:</label>
<input type="text" id="instance" required>
<label for="jsonUpload">JSONファイル:</label>
<input type="file" id="jsonUpload" accept=".json" required>
</form>
<button id="loadBtn">JSONを読み込む</button>
<div id="searchContainer">
<input type="text" id="searchInput" placeholder="検索ワード">
<label for="searchText">Text:</label>
<input type="checkbox" id="searchText" checked>
<label for="searchCW">CW:</label>
<input type="checkbox" id="searchCW" checked>
<input type="date" id="dateFrom">
<input type="date" id="dateTo">
<label for="searchType">検索タイプ:</label>
<select id="searchType">
<option value="or">OR</option>
<option value="and">AND</option>
</select>
<button id="searchBtn">検索</button>
</div>
<div id="errorContainer"></div>
<div id="notesContainer"></div>
<button id="loadMoreBtn">もっと見る</button>
<script>
const form = document.getElementById('form');
const instanceInput = document.getElementById('instance');
const jsonUpload = document.getElementById('jsonUpload');
const loadBtn = document.getElementById('loadBtn');
const searchInput = document.getElementById('searchInput');
const searchText = document.getElementById('searchText');
const searchCW = document.getElementById('searchCW');
const dateFrom = document.getElementById('dateFrom');
const dateTo = document.getElementById('dateTo');
const searchBtn = document.getElementById('searchBtn');
const errorContainer = document.getElementById('errorContainer');
const notesContainer = document.getElementById('notesContainer');
const loadMoreBtn = document.getElementById('loadMoreBtn');
let notes = [];
let filteredNotes = [];
let displayedNotes = 0;
const notesPerPage = 50;
loadBtn.addEventListener('click', () => {
const instance = instanceInput.value;
errorContainer.textContent = '';
if (!instance) {
errorContainer.textContent = 'Instanceの入力が必要です。';
event.preventDefault();
return;
}
const file = jsonUpload.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = (event) => {
try {
const json = JSON.parse(event.target.result);
notes = json.filter(note => note.id && note.createdAt && (note.text || note.cw));
filteredNotes = notes;
displayNotes();
} catch (e) {
alert('エラー: JSONファイルが無効です');
}
};
reader.readAsText(file);
});
searchBtn.addEventListener('click', () => {
notesContainer.innerHTML = '';
const keywords = searchInput.value.trim().split(' ');
const searchInText = searchText.checked;
const searchInCW = searchCW.checked;
const fromDate = dateFrom.value ? new Date(dateFrom.value) : null;
const toDate = dateTo.value ? new Date(dateTo.value) : null;
if (toDate) toDate.setDate(toDate.getDate() + 1);
filteredNotes = notes.filter(note => {
const createdAt = new Date(note.createdAt);
if (fromDate && createdAt < fromDate) return false;
if (toDate && createdAt >= toDate) return false;
if (keywords.length === 1 && keywords[0] === '') return true;
const searchFields = [];
if (searchInText && note.text) searchFields.push(note.text);
if (searchInCW && note.cw) searchFields.push(note.cw);
const searchType = document.getElementById('searchType').value;
if (searchType === 'or') {
return keywords.some(keyword =>
searchFields.some(field => field.includes(keyword))
);
} else {
return keywords.every(keyword =>
searchFields.some(field => field.includes(keyword))
);
}
});
displayedNotes = 0;
displayNotes();
});
loadMoreBtn.addEventListener('click', displayNotes);
function displayNotes() {
const notesToDisplay = filteredNotes.slice(displayedNotes, displayedNotes + notesPerPage);
displayedNotes += notesPerPage;
notesToDisplay.forEach(note => {
const noteUrl = `https://${instanceInput.value}/notes/${note.id}`;
const noteElement = document.createElement('div');
const noteLink = document.createElement('a');
const noteDateElem = document.createElement('span');
noteDateElem.className = 'date-text';
noteDateElem.textContent = new Date(note.createdAt).toLocaleString();
const noteTextElem = document.createElement('p');
noteTextElem.className = 'note-text';
noteTextElem.textContent = note.text ? note.text : '';
const noteCWElem = document.createElement('p');
noteCWElem.className = 'cw-text';
noteCWElem.textContent = note.cw ? `CW: ${note.cw}` : '';
noteLink.href = noteUrl;
noteLink.appendChild(noteDateElem);
if (note.cw) noteLink.appendChild(noteCWElem);
if (note.text) noteLink.appendChild(noteTextElem);
noteElement.appendChild(noteLink);
notesContainer.appendChild(noteElement);
});
if (displayedNotes >= filteredNotes.length) {
loadMoreBtn.style.display = 'none';
} else {
loadMoreBtn.style.display = 'block';
}
}
</script>
</body>
</html>