Repository navigation
Expand file tree
/
Copy pathcontent.js
More file actions
174 lines (151 loc) · 4.24 KB
/
Copy pathcontent.js
File metadata and controls
174 lines (151 loc) · 4.24 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
// Run this in chrome console on discord
(() => {
if (window.__randomSenderInjected) return;
window.__randomSenderInjected = true;
let timeoutId = null;
let running = false;
let nextSendTimestamp = 0;
// --- Send random number function ---
const sendRandomNumber = () => {
const randomNum = Math.floor(Math.random() * 10000) + 1;
const inputBox = document.querySelector('[contenteditable="true"][data-slate-editor="true"]');
if (!inputBox) return;
inputBox.focus();
const insertEvent = new InputEvent("beforeinput", {
inputType: "insertText",
data: String(randomNum),
bubbles: true,
cancelable: true
});
inputBox.dispatchEvent(insertEvent);
const enter = new KeyboardEvent("keydown", {
key: "Enter",
code: "Enter",
keyCode: 13,
which: 13,
bubbles: true
});
inputBox.dispatchEvent(enter);
scheduleNext();
};
// --- Schedule next random send ---
const scheduleNext = () => {
if (!running) return;
const delay = 8000 + Math.random() * 2000; // 8-10 sec
nextSendTimestamp = Date.now() + delay;
timeoutId = setTimeout(sendRandomNumber, delay);
};
// --- Start/Pause/Stop ---
const startSending = () => {
if (running) return;
running = true;
statusIndicator.textContent = "▶ Playing";
scheduleNext();
};
const pauseSending = () => {
running = false;
clearTimeout(timeoutId);
statusIndicator.textContent = "⏸ Paused";
};
const stopSending = () => {
running = false;
clearTimeout(timeoutId);
popup.remove();
window.__randomSenderInjected = false;
};
// --- Countdown updater ---
const updateCountdown = () => {
if (running) {
const remaining = Math.max(0, nextSendTimestamp - Date.now());
countdown.textContent = `Next in: ${(remaining / 1000).toFixed(1)}s`;
} else {
countdown.textContent = "Next in: --s";
}
requestAnimationFrame(updateCountdown);
};
// --- Popup UI ---
const popup = document.createElement("div");
Object.assign(popup.style, {
position: "fixed",
top: "10px",
right: "10px",
backgroundColor: "#1e1f23",
color: "#fff",
padding: "12px",
borderRadius: "8px",
boxShadow: "0 4px 12px rgba(0,0,0,0.6)",
zIndex: 999999,
display: "flex",
flexDirection: "column",
gap: "8px",
fontFamily: "Arial, sans-serif",
fontSize: "13px",
minWidth: "160px"
});
const controls = document.createElement("div");
Object.assign(controls.style, {
display: "flex",
gap: "6px",
justifyContent: "space-between"
});
const startBtn = document.createElement("button");
startBtn.textContent = "▶ Start";
Object.assign(startBtn.style, {
flex: "1",
padding: "4px 6px",
borderRadius: "4px",
border: "none",
backgroundColor: "#4caf50",
color: "#fff",
cursor: "pointer"
});
startBtn.onclick = startSending;
const pauseBtn = document.createElement("button");
pauseBtn.textContent = "⏸ Pause";
Object.assign(pauseBtn.style, {
flex: "1",
padding: "4px 6px",
borderRadius: "4px",
border: "none",
backgroundColor: "#f0ad4e",
color: "#fff",
cursor: "pointer"
});
pauseBtn.onclick = pauseSending;
const stopBtn = document.createElement("button");
stopBtn.textContent = "✕ Stop";
Object.assign(stopBtn.style, {
flex: "1",
padding: "4px 6px",
borderRadius: "4px",
border: "none",
backgroundColor: "#d9534f",
color: "#fff",
cursor: "pointer"
});
stopBtn.onclick = stopSending;
controls.appendChild(startBtn);
controls.appendChild(pauseBtn);
controls.appendChild(stopBtn);
const statusIndicator = document.createElement("div");
statusIndicator.textContent = "⏸ Paused";
Object.assign(statusIndicator.style, {
fontWeight: "bold",
textAlign: "center",
backgroundColor: "#333",
padding: "2px 4px",
borderRadius: "4px"
});
const countdown = document.createElement("div");
countdown.textContent = "Next in: --s";
Object.assign(countdown.style, {
fontSize: "11px",
textAlign: "center",
color: "#ccc"
});
popup.appendChild(controls);
popup.appendChild(statusIndicator);
popup.appendChild(countdown);
document.body.appendChild(popup);
updateCountdown();
})();