gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
html css js copy random text per line repeat ms
- User
html css js copy random text per line repeat ms
- Assistant
html css js copy random text per line repeat ms
If I understand you correctly, you want to create a snippet that copies a random line of text repeatedly at some interval (in milliseconds). This involves:
Here is a simple HTML/JS example that does this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Copy Random Line Repeatedly</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
#log { margin-top: 20px; white-space: pre-wrap; background: #f0f0f0; padding: 10px; border: 1px solid #ccc; height: 150px; overflow-y: auto;}
</style>
</head>
<body>
<h2>Copy Random Line Repeatedly</h2>
<textarea id="text-lines" rows="6" cols="40">
Line one of text
Second line here
Another random line
Last example line
Yet another line
</textarea>
<br/>
<label for="interval">Repeat Interval (ms): </label>
<input type="number" id="interval" value="2000" min="100" step="100" />
<button id="start">Start Copying</button>
<button id="stop" disabled>Stop Copying</button>
<div id="log"></div>
<script>
const textarea = document.getElementById('text-lines');
const intervalInput = document.getElementById('interval');
const startBtn = document.getElementById('start');
const stopBtn = document.getElementById('stop');
const logDiv = document.getElementById('log');
let timerId = null;
function copyTextToClipboard(text) {
// Use Clipboard API - best modern way
if (navigator.clipboard) {
navigator.clipboard.writeText(text).then(() => {
log(`Copied: "${text}"`);
}).catch(err => {
log('Could not copy text: ', err);
});
} else {
// fallback for older browsers - use a temporary textarea
const tempTextArea = document.createElement('textarea');
tempTextArea.value = text;
document.body.appendChild(tempTextArea);
tempTextArea.select();
try {
document.execCommand('copy');
log(`Copied (fallback): "${text}"`);
} catch (err) {
log('Fallback: Unable to copy', err);
}
document.body.removeChild(tempTextArea);
}
}
function log(message) {
const time = new Date().toLocaleTimeString();
logDiv.textContent += `[${time}] ${message}\n`;
logDiv.scrollTop = logDiv.scrollHeight;
}
function startCopying() {
const lines = textarea.value.split('\n').filter(line => line.trim() !== '');
if (lines.length === 0) {
alert('Please enter some lines of text.');
return;
}
const intervalMs = Number(intervalInput.value);
if (isNaN(intervalMs) || intervalMs < 100) {
alert('Please enter a valid interval of at least 100 ms.');
return;
}
startBtn.disabled = true;
stopBtn.disabled = false;
timerId = setInterval(() => {
const randIndex = Math.floor(Math.random() * lines.length);
const textToCopy = lines[randIndex];
copyTextToClipboard(textToCopy);
}, intervalMs);
log('Started copying...');
}
function stopCopying() {
if (timerId) {
clearInterval(timerId);
timerId = null;
log('Stopped copying.');
startBtn.disabled = false;
stopBtn.disabled = true;
}
}
startBtn.addEventListener('click', startCopying);
stopBtn.addEventListener('click', stopCopying);
</script>
</body>
</html>
Note: Clipboard API usually requires user interaction to copy, but this is triggered inside a setInterval after you click start, which usually satisfies that requirement in most browsers.
Let me know if you want a version using a specific framework or with other features!
Not yet included in a published release.