在编写入群欢迎语时,我发现纯文字效果不尽如人意,内容一多就影响阅读体验。
然后我想到用图片来呈现(真能废话),可自己又不太会用PS这类专业软件。后来我琢磨着,能不能先通过网页生成帮助内容,再用截图软件把网页内容截下来做成图片呢?
但新问题又来了,要是帮助内容有变动,难道每次都得重新走一遍网页编辑、打开网页、截图保存的流程吗?这也太麻烦了。
直到有一天,我在一个展示多地Ping延迟的网站上,看到它能把结果直接生成截图,这一下子给了我灵感……
然后就有了这玩意_(:з」∠)_
ps:纯自用如有bug请丢给ai解决(应该不会有吧?)
然后我想到用图片来呈现
但新问题又来了,要是帮助内容有变动,难道每次都得重新走一遍网页编辑、打开网页、截图保存的流程吗?这也太麻烦了。
直到有一天,我在一个展示多地Ping延迟的网站上,看到它能把结果直接生成截图,这一下子给了我灵感……
然后就有了这玩意_(:з」∠)_
ps:纯自用如有bug请丢给ai解决(应该不会有吧?)
HTML:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>服务器帮助手册</title>
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
font-family: 'FZPixel', 'Microsoft YaHei', 'PingFang SC', sans-serif;
padding: 20px;
}
.container {
width: 100%;
/*决定最后截图的宽度,请自行设置*/
max-width: 800px;
}
.card {
background: #ffffff;
border-radius: 12px;
border: 3px solid #e0e0e0;
box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.3);
padding: 28px;
color: #333;
}
.title {
text-align: center;
font-size: 26px;
font-weight: bold;
margin-bottom: 20px;
color: #333;
border-bottom: 3px solid #4a90e2;
padding-bottom: 12px;
}
.section {
margin-bottom: 18px;
}
.section-title {
font-size: 20px;
font-weight: bold;
margin-bottom: 8px;
color: #4a90e2;
display: flex;
align-items: center;
background: #f5f7fa;
padding: 8px 12px;
border-radius: 6px;
border-left: 4px solid #4a90e2;
}
.section-title::before {
content: '▸';
margin-right: 6px;
color: #4a90e2;
}
.content {
line-height: 1.6;
font-size: 16px;
background: #f5f7fa;
padding: 12px;
border-radius: 6px;
border: 1px solid #e0e0e0;
color: #555;
}
.highlight {
color: #4a90e2;
font-weight: bold;
background: rgba(74, 144, 226, 0.1);
padding: 1px 4px;
border-radius: 3px;
}
.command-list {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
gap: 8px;
}
.command-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: #f5f7fa;
padding: 12px 10px;
border-radius: 6px;
border: 2px solid #e0e0e0;
}
.command-name {
font-family: 'FZPixel', 'Consolas', 'Courier New', monospace;
font-weight: bold;
color: #4a90e2;
font-size: 20px;
margin-bottom: 4px;
}
.command-desc {
color: #666;
font-size: 16px;
}
.divider {
height: 2px;
background: linear-gradient(90deg, transparent, #4a90e2, transparent);
margin: 12px 0;
}
.game-tip {
background: #f5f7fa;
border: 2px solid #e0e0e0;
padding: 16px;
border-radius: 8px;
font-size: 16px;
font-weight: normal;
margin-top: 15px;
}
.game-tip-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.game-tip-row:last-child {
margin-bottom: 0;
}
.game-tip-row .command {
font-family: 'FZPixel', 'Consolas', 'Courier New', monospace;
color: #4a90e2;
font-size: 16px;
font-weight: bold;
padding: 3px 10px;
white-space: nowrap;
flex-shrink: 0;
}
.game-tip-row span:not(.command) {
margin-left: 12px;
color: #666;
}
.divider-line {
flex: 1;
height: 1px;
background: linear-gradient(90deg, transparent, #e0e0e0, transparent);
margin: 0 12px;
}
.screenshot-btn {
position: fixed;
top: 20px;
right: 20px;
background: #4a90e2;
color: #fff;
border: 3px solid #3a7bc8;
padding: 12px 24px;
border-radius: 6px;
font-size: 14px;
font-weight: bold;
cursor: pointer;
box-shadow: 0 4px 15px rgba(74, 144, 226, 0.4);
transition: all 0.3s ease;
z-index: 1000;
}
.screenshot-btn:hover {
background: #3a7bc8;
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(74, 144, 226, 0.6);
}
.screenshot-btn:active {
transform: translateY(0);
}
.faq-category {
font-size: 16px;
font-weight: bold;
color: #4a90e2;
margin-bottom: 8px;
padding-bottom: 4px;
border-bottom: 1px dashed #e0e0e0;
}
.faq-item {
margin-bottom: 10px;
padding: 10px;
background: #fff;
border-radius: 6px;
border-left: 3px solid #4a90e2;
box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.faq-question {
display: flex;
align-items: center;
margin-bottom: 4px;
font-weight: bold;
}
.faq-tag {
background: #f5f7fa;
border: 1px solid #e0e0e0;
border-radius: 12px;
padding: 2px 8px;
font-size: 12px;
margin-left: 8px;
color: #666;
}
.faq-answer {
line-height: 1.6;
color: #555;
padding-left: 20px;
border-left: 2px solid #f0f0f0;
}
</style>
</head>
<body>
<button class="screenshot-btn" onclick="captureScreenshot()">截图保存</button>
<div class="container" id="capture-area">
<div class="card">
<h1 class="title">xxxx手册</h1>
<div class="divider"></div>
<!-- 进服验证流程 -->
<div class="section">
<div class="section-title">进服验证流程</div>
<!-- 看情况复制 <br>换行 -->
<div class="content">
进服提示需验证,回到群发送:<br>
<span class="highlight">绑定 xxxx</span><br>
等机器人提示:<br>
<span class="highlight">绑定 (你的游戏名) 成功! 你可以进入服务器了!</span>(请勿使用中文名)<br>
然后回到游戏退到多人游戏重新进服即可
</div>
</div>
<div class="divider"></div>
<!-- 群内可用命令 -->
<div class="section">
<div class="section-title">群内可用命令(文字或文字首字母都可)</div>
<div class="command-list">
<!-- 添加复制这些↓↓↓↓ -->
<div class="command-item">
<span class="command-name">qd</span>
<span class="command-desc">签到</span>
</div>
<!-- 添加复制这些↑↑↑↑ -->
</div>
</div>
<div class="divider"></div>
<!-- 游戏常用命令 -->
<div class="section">
<div class="section-title">游戏常用命令</div>
<div class="game-tip">
<!-- 添加复制这些↓↓↓↓ -->
<div class="game-tip-row">
<span class="command">/cd</span>
<div class="divider-line"></div>
<span>打开菜单</span>
</div>
<!-- 添加复制这些↑↑↑↑ -->
<div class="game-tip-row">
<span class="command">/tpa <玩家名></span>
<div class="divider-line"></div>
<span>请求传送到玩家</span>
</div>
</div>
</div>
<div class="divider"></div>
<!-- 常见问题 -->
<div class="section">
<div class="section-title">常见问题</div>
<div class="game-tip">
<div class="faq-item">
<!-- 添加复制这些↓↓↓↓ -->
<div class="faq-question">
<span class="command">为什么母猪会上树</span>
<span class="faq-tag">趣味问题</span>
</div>
<div class="faq-answer">
答:本来就会2333
</div>
</div>
<!-- 添加复制这些↑↑↑↑ -->
<!-- 类似问题添加复制这些↓↓↓↓ -->
<div class="faq-item" style="margin-top:12px;">
<div class="faq-question">
<span class="command">验证失败常见原因</span>
<span class="faq-tag">操作指南</span>
</div>
<div class="faq-answer">
1. 未使用英文ID注册<br>
2. 机器人响应延迟
</div>
</div>
<!-- 类似问题添加复制这些↑↑↑↑ -->
</div>
</div>
</div>
</div>
<script>
function captureScreenshot() {
const captureArea = document.getElementById('capture-area');
const btn = document.querySelector('.screenshot-btn');
// 隐藏截图按钮
btn.style.display = 'none';
html2canvas(captureArea, {
backgroundColor: null,
scale: 2, // 提高清晰度
useCORS: true,
allowTaint: true
}).then(canvas => {
// 恢复截图按钮
btn.style.display = 'block';
// 创建下载链接
const link = document.createElement('a');
link.download = '养老小镇手册-简洁版.png';
link.href = canvas.toDataURL('image/png');
link.click();
}).catch(err => {
console.error('截图失败:', err);
btn.style.display = 'block';
alert('截图失败,请重试');
});
}
</script>
</body>
</html>