-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.htm
More file actions
193 lines (152 loc) · 4.8 KB
/
Copy pathindex.htm
File metadata and controls
193 lines (152 loc) · 4.8 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
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://w3.org">
<HEAD>
<meta charset="Shift_JIS">
<TITLE>none</TITLE>
<style type="text/css">
body {
background-image: url("kkb.png");
background-repeat: repeat;
background-position: left top;
background-attachment: scroll;
}
</style>
</HEAD>
<table align="center" bgcolor="#C4FFCA" border="1" width="90%" cellpadding="2" cellspacing="7">
<tr>
<td>
<font size="4"> <strong>テスト@掲示板</strong></font>
<br>
<br> テスト用の板です。何でも書いてください。
<br></td>
</tr>
<tr>
<td align="center"><a href="m"><small>書き込む前に読んでね</small></a> <a href="k"><small>ガイドライン</small></a></td>
</tr>
</table>
<br>
<div id="threads"></div>
<br>
<table align="center" bgcolor="#C4FFCA" border="1" width="90%" cellpadding="2" cellspacing="7">
<tr>
<td align="center"><a href="tate.htm"><small>すれたて</small></a></td>
</tr>
</table>
<script>
const params = new URLSearchParams(location.search);
const bbs = params.get('bbs') || location.pathname.split('/')[1];
// /test/2ch.html → "test"
async function loadSubject() {
const text = await fetchSJIS(`subject.txt`) || '';
const lines = text.trim().split('\n');
const container = document.getElementById('threads');
container.innerHTML = '';
for (const line of lines) {
const [dat, rest] = line.split('<>');
if (!dat || !rest) return;
const key = dat.replace('.dat', '');
const div = document.createElement('div');
div.className = 'thread';
let ue = `
<br>
<table bgcolor="#F0F0F0" align="center" border="1" width="90%" cellpadding="2" cellspacing="7">
<tr>
<td>
<div><b></b><font size="5" color="red"><b>${rest}</b></font></div>
<br>
`;
const text = await fetchSJIS(`/dat/${key}.dat`) || '';
const lines = text.trim().split('\n');
lines.forEach((line, idx) => {
const cols = line.split('<>');
const no = cols[0];
const name = escapeHtml(cols[1]);
const mail = escapeHtml(cols[2]);
const time = escapeHtml(cols[3]);
const body = escapeHtml(cols[4]);
const title = escapeHtml(cols[5]);
ue += `
${no} 名前:<font color="green"><strong>${mail ? '<a href="mailto:' + mail + '">' + name + '</a>' : name}</strong></font> :${time}<br>
   ${body}<br><br>
`;
});
div.innerHTML =`
${ue}
<br>
<br>
<form action="/bbs.cgi" method="post">
<input name="key" type="hidden" value="${key}">
<button type="submit">書き込む</button>
<label for="username">名前:</label>
<input type="text" id="username" width="100" name="FROM" placeholder="名無し">
<label for="useremail">メアド:</label>
<input type="text" id="useremail" name="mail">
<br>
<br>
<textarea id="usermessage" name="MESSAGE" rows="5" cols="65" required></textarea>
</form>
<a href="."><strong>リロード</strong></a> <a href="/"><strong>板のトップ</strong></a>
</td>
</tr>
</table>
`;
container.appendChild(div);
}
}
function escapeHtml(str) {
return str
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">");
}
async function loadDat() {
const res = await fetch(`/${bbs}/dat/${key}.dat`, { cache: 'no-cache' });
const text = await res.text();
const lines = text.trim().split('\n');
const container = document.getElementById('reslist');
container.innerHTML = '';
lines.forEach((line, idx) => {
const cols = line.split('<>');
const no = cols[0];
const name = escapeHtml(cols[1]);
const mail = escapeHtml(cols[2]);
const time = escapeHtml(cols[3]);
const body = escapeHtml(cols[4]);
const title = escapeHtml(cols[5]);
if (idx === 0) {
document.getElementById('title').textContent = title;
}
const bodyHtml = body.replace(
/(https?:\/\/\S+)/g,
'<a href="$1" target="_blank">$1</a>'
);
const div = document.createElement('div');
div.className = 'res';
div.innerHTML = `
<div class="meta">
<span>${no}</span> :
<span class="name">${mail ? '<a href="mailto:' + mail + '">' + name + '</a>' : name}</span>
<span>${time}</span>
</div>
<div class="body">${bodyHtml}</div>
`;
container.appendChild(div);
});
}
async function fetchSJIS(url) {
const res = await fetch(url, { cache: 'no-cache' });
const buf = await res.arrayBuffer();
const decoder = new TextDecoder("shift_jis");
return decoder.decode(buf);
}
async function loadSetting() {
const res = await fetch(`/${bbs}/setting.txt`);
const text = await res.text();
const titleLine = text.split('\n').find(l => l.startsWith('BBS_TITLE='));
if (titleLine) {
document.getElementById('boardTitle').textContent = titleLine.replace('BBS_TITLE=', '').trim();
}
}
loadSetting();
loadSubject();
</script>
</HTML>