其实是通过js+html+css动态生成对话内容的工具,前段设置对话内容头像时间这些信息,js就能自动把信息更新到前段页面里面。
-
HTML:用于搭建页面结构。
-
CSS:用于美化页面样式。
-
JavaScript:实现核心逻辑,包括对话生成、随机选择、复制功能等。
核心框架代码部分:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>抖音对话生成器</title>
<style>
/* CSS 样式 */
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
width: 400px;
text-align: center;
}
h1 {
font-size: 24px;
margin-bottom: 20px;
}
.input-group, .output-group {
margin-bottom: 15px;
}
label {
display: block;
font-weight: bold;
margin-bottom: 5px;
}
textarea {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 14px;
resize: none;
}
button {
padding: 10px 20px;
margin: 5px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: #fff;
font-size: 14px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
#output {
background-color: #f9f9f9;
}
</style>
</head>
<body>
<div class="container">
<h1>抖音对话生成器</h1>
<div class="input-group">
<label for="user1">用户1名称:</label>
<input type="text" id="user1" placeholder="例如:小明" value="小明">
</div>
<div class="input-group">
<label for="user2">用户2名称:</label>
<input type="text" id="user2" placeholder="例如:小红" value="小红">
</div>
<div class="input-group">
<button id="generate-btn">生成对话</button>
<button id="copy-btn">复制对话</button>
</div>
<div class="output-group">
<label for="output">生成的对话:</label>
<textarea id="output" readonly></textarea>
</div>
</div>
<script>
// JavaScript 逻辑
document.addEventListener('DOMContentLoaded', () => {
const user1Input = document.getElementById('user1');
const user2Input = document.getElementById('user2');
const generateBtn = document.getElementById('generate-btn');
const copyBtn = document.getElementById('copy-btn');
const outputArea = document.getElementById('output');
// 预设的对话库
const dialogues = [
"{用户1}:这个视频太搞笑了!\n{用户2}:哈哈哈,我也笑疯了!",
"{用户1}:你觉得这个视频怎么样?\n{用户2}:我觉得很棒,很有创意!",
"{用户1}:这个背景音乐真好听!\n{用户2}:对啊,我已经单曲循环了!",
"{用户1}:你觉得博主会回复我们吗?\n{用户2}:说不定哦,博主很宠粉的!",
"{用户1}:这个视频让我想起了小时候。\n{用户2}:我也是,满满的回忆!"
];
// 生成对话
generateBtn.addEventListener('click', () => {
const user1 = user1Input.value || '用户1';
const user2 = user2Input.value || '用户2';
const dialogueTemplate = dialogues[Math.floor(Math.random() * dialogues.length)];
const dialogue = dialogueTemplate
.replace(/{用户1}/g, user1)
.replace(/{用户2}/g, user2);
outputArea.value = dialogue;
});
// 复制对话
copyBtn.addEventListener('click', () => {
outputArea.select();
document.execCommand('copy');
alert('对话已复制到剪贴板!');
});
});
</script>
</body>
</html>