-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestrendaer.html
More file actions
340 lines (307 loc) · 10.7 KB
/
testrendaer.html
File metadata and controls
340 lines (307 loc) · 10.7 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>わんコメ テストコメント連打er</title>
<style>
body { font-family: sans-serif; padding: 20px; }
.row { margin-top: 10px; }
.container { max-width: 600px; margin: 0 auto; padding: 0 1rem; }
.datacontainer { display: flex; column-gap: 20px; }
.block { display: flex; flex-direction: column; flex: 1; }
textarea { width: 100%; box-sizing: border-box; resize: vertical; }
.commentOptions { display: flex; flex-wrap: wrap; column-gap: 1rem; }
.commentOptions .commentOptionCols { flex: 1 1 calc(50% - 1rem); min-width: 250px; display: flex; align-items: center; gap: 0.5rem; }
.commentOptionText { min-width: 75px; text-align: right; }
.actionModeSelection {
span { margin-right: 5px; };
input { margin-right: -2px; };
}
@media (max-width: 600px) {
.datacontainer {
flex-direction: column;
}
}
.hammer {
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<h2>わんコメ テストコメント連打er</h2>
<div class="datacontainer">
<div class="block">
<label for="usernames">ユーザ名:</label>
<textarea id="usernames" rows="5" cols="20" wrap="off" autocomplete="off"></textarea>
</div>
<div class="block">
<label for="comments">コメント内容:</label>
<textarea id="comments" rows="5" cols="20" wrap="off" autocomplete="off"></textarea>
</div>
</div>
<form>
<fieldset id="actionModeSelections">
<legend>動作モード</legend>
<span class="actionModeSelection">
<input type="radio" id="actionModeSingle" name="actionMode" value="single" />
<label for="actionModeSingle">先頭</label>
</span>
<span class="actionModeSelection">
<input type="radio" id="actionModeList" name="actionMode" value="list" />
<label for="actionModeList">リスト順</label>
</span>
<span class="actionModeSelection">
<input type="radio" id="actionModeRandom" name="actionMode" value="random" />
<label for="actionModeRandom">ランダム</label>
</span>
</fieldset>
<fieldset>
<legend>コメントオプション</legend>
<div class="commentOptions">
<span class="commentOptionCols">
<label for="commentOptionNewRate" class="commentOptionText">New率</label>
<input type="range" id="commentOptionNewRate" min="0" max="100" step="1">
<span id="commentOptionNewRateText">100%</span>
</span>
<span class="commentOptionCols">
<label for="commentOptionRepeaterRate" class="commentOptionText">リピ率</label>
<input type="range" id="commentOptionRepeaterRate" min="0" max="100" step="1">
<span id="commentOptionRepeaterRateText">100%</span>
</span>
<span class="commentOptionCols">
<label for="commentOptionMembershipRate" class="commentOptionText">メンシ率</label>
<input type="range" id="commentOptionMembershipRate" min="0" max="100" step="1">
<span id="commentOptionMembershipRateText">100%</span>
</span>
<span class="commentOptionCols">
<label for="commentOptionSpeech" class="commentOptionText">読み上げ</label>
<input type="checkbox" id="commentOptionSpeech" />
</span>
</div>
</fieldset>
</form>
<div class="row">
<button id="sendSingle">単発送信</button>
</div>
<div class="row">
<div>
<label for="startstop">連続送信 </label>
<button id="startstop">Start</button>
<progress id="gauge" value="0.0" max="1">10</progress>
</div>
<div>
<label for="interval">送信間隔:</label>
<input id="interval" type="range" min="100" max="2000" step="50">
<span id="intervalValue">1000</span> ms
</div>
</div>
<div class="row">
<span id="hammer" class="hammer">🔨</span>
</div>
</div>
<script>
function addRangeValueApplier(rangeId, labelId, formatter) {
document.getElementById(rangeId).addEventListener("input", e => {
document.getElementById(labelId).textContent = formatter(e.target.value);
});
}
addRangeValueApplier("commentOptionNewRate", "commentOptionNewRateText", x => x + "%");
addRangeValueApplier("commentOptionRepeaterRate", "commentOptionRepeaterRateText", x => x + "%");
addRangeValueApplier("commentOptionMembershipRate", "commentOptionMembershipRateText", x => x + "%");
addRangeValueApplier("interval", "intervalValue", x => x);
let listIndex = 0;
function sendOne() {
const getLines = (text) => {
const lines = text.split("\n").map(s=>s.trim()).filter(s=>s.length>0);
return lines;
}
const usernames = getLines(document.getElementById("usernames").value);
const comments = getLines(document.getElementById("comments").value);
let username = "";
let comment = "";
const selectedMode = document.querySelector('input[name="actionMode"]:checked').value;
switch (selectedMode) {
case "list":
username = usernames[listIndex % usernames.length];
comment = comments[listIndex % comments.length];
listIndex++;
if (listIndex > 1e10) listIndex = 0; // 一応あふれないように
break;
case "random":
username = usernames[Math.floor(Math.random() * usernames.length)];
comment = comments[Math.floor(Math.random() * comments.length)];
break;
case "single":
default:
username = usernames[0];
comment = comments[0];
break;
}
// 値が空だとわんコメ側で設定したデフォ値になるようだ
const getBoolFromSliderValueRate = (elementId) => {
const rate = document.getElementById(elementId).value; // 0 - 100
return Math.random() * 100 < rate;
};
fetch("http://localhost:11180/api/comments/test", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"platform": "youtube",
"hasGift": false,
"unit": "",
"price": 0,
"giftType": "none",
"newComment": getBoolFromSliderValueRate("commentOptionNewRate"),
"repeater": getBoolFromSliderValueRate("commentOptionRepeaterRate"),
"subscribe": getBoolFromSliderValueRate("commentOptionMembershipRate"),
"speech": document.getElementById("commentOptionSpeech").checked,
"username": username,
"comment": comment
})
}).catch(err => console.error(err));
}
document.getElementById("sendSingle").addEventListener("click", () => {
sendOne();
});
document.getElementById("startstop").addEventListener("click", () => {
let newtext = "Stop"
if(running) {
resetProgress();
newtext="Start";
}
else {
// sendOne();
running = true;
requestAnimationFrame(sendloop);
}
document.getElementById("startstop").textContent=newtext;
});
let lastTime = 0;
let running = false;
let progress = 0.0;
function updateGauge() {
document.getElementById("gauge").value = progress;
}
function resetProgress() {
lastTime = 0;
running = false;
progress = 0.0;
listIndex = 0;
updateGauge();
}
function sendloop(timestamp) {
if(!running) return;
if(!lastTime) lastTime = timestamp;
const delta = timestamp - lastTime;
lastTime = timestamp;
const interval = Number(document.getElementById("interval").value);
progress += delta / interval;
updateGauge();
if(progress >= 1) {
progress = 0.0;
sendOne();
}
requestAnimationFrame(sendloop);
}
const SAVE_KEYS = {
usernames: {
key: "usernames",
init: "ずんだもん\nあんこもん\nきなこもん\nそーだもん",
description: "ユーザ名"
},
comments: {
key: "comments",
init: "のだ\nなのだ\nちがうのだ\nかもなのだ",
description: "コメント"
},
actionMode: {
key: "actionMode",
init: "random",
description: "動作モード"
},
interval: {
key: "interval",
init: "1000",
description: "連打用インターバル[ms]"
},
newRate: {
key: "commentOptionNewRate",
init: "0",
description: "Newコメント率"
},
repeater: {
key: "commentOptionRepeaterRate",
init: "0",
description: "再訪率"
},
membership: {
key: "commentOptionMembershipRate",
init: "0",
description: "メンバーシップ率"
},
speech: {
key: "commentOptionSpeech",
init: "false",
description: "読み上げ"
}
}
function onload() {
// 値を復帰&変更時のリスナー埋め込み
const initializeStorage = (identifier) => {
if(localStorage.getItem(identifier.key) === null) {
console.log(identifier.key + " initialized to :" + identifier.init);
localStorage.setItem(identifier.key, identifier.init);
}
//console.log(identifier.key + " : " + identifier.init );
};
initializeStorage(SAVE_KEYS.comments);
initializeStorage(SAVE_KEYS.usernames);
initializeStorage(SAVE_KEYS.actionMode);
initializeStorage(SAVE_KEYS.interval);
const commentsArea = document.getElementById("comments");
commentsArea.value = localStorage.getItem(SAVE_KEYS.comments.key);
commentsArea.addEventListener("input", () => {
localStorage.setItem(SAVE_KEYS.comments.key, commentsArea.value);
});
const usernamesArea = document.getElementById("usernames");
usernamesArea.value = localStorage.getItem(SAVE_KEYS.usernames.key);
usernamesArea.addEventListener("input", () => {
localStorage.setItem(SAVE_KEYS.usernames.key, usernamesArea.value);
});
const savedValue = localStorage.getItem(SAVE_KEYS.actionMode.key);
// console.log(savedValue);
document.querySelector(`input[name="actionMode"][value="${savedValue}"]`).checked = true;
document.getElementById("actionModeSelections").addEventListener("change", (e) => {
// console.log(e.target.value);
localStorage.setItem(SAVE_KEYS.actionMode.key, e.target.value);
});
const sliderUpdater = (key) => {
const slider = document.getElementById(key);
slider.value = Number(localStorage.getItem(key));
slider.dispatchEvent(new Event("input")); // spanに反映さす
slider.addEventListener("change", e => {
localStorage.setItem(key, e.target.value.toString());
});
};
sliderUpdater(SAVE_KEYS.interval.key);
sliderUpdater(SAVE_KEYS.newRate.key);
sliderUpdater(SAVE_KEYS.repeater.key);
sliderUpdater(SAVE_KEYS.membership.key);
const speechCheckbox = document.getElementById(SAVE_KEYS.speech.key);
speechCheckbox.checked = localStorage.getItem(SAVE_KEYS.speech.key) === "true";
speechCheckbox.addEventListener("input", (e) => {
localStorage.setItem(SAVE_KEYS.speech.key, e.target.checked.toString())
})
}
document.addEventListener("DOMContentLoaded", onload);
function deleteStorages() {
if(window.confirm("ページを初期状態に戻しますか?")) {
localStorage.clear();
window.location.reload();
}
}
document.getElementById("hammer").addEventListener("click", deleteStorages);
</script>
</body>
</html>