User:Lch 333/BlockView.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
<!DOCTYPE JavaScript>
<JavaScript lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>封鎖原因預覽工具</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'Segoe UI', 'Microsoft JhengHei', sans-serif;
}
body {
background-color: #f8f9fa;
color: #333;
padding: 20px;
min-height: 100vh;
}
.container {
max-width: 800px;
margin: 0 auto;
}
header {
text-align: center;
margin-bottom: 30px;
padding: 20px;
background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
color: white;
border-radius: 10px;
box-shadow: 0 4px 12px rgba(220, 53, 69, 0.2);
}
h1 {
font-size: 24px;
margin-bottom: 10px;
}
.subtitle {
font-size: 14px;
opacity: 0.9;
max-width: 600px;
margin: 0 auto;
line-height: 1.5;
}
.main-content {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
@media (max-width: 768px) {
.main-content {
grid-template-columns: 1fr;
}
}
.input-section, .preview-section {
background: white;
border-radius: 10px;
padding: 25px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}
.section-title {
font-size: 18px;
color: #495057;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 2px solid #f1f3f4;
display: flex;
align-items: center;
gap: 10px;
}
.section-title i {
color: #dc3545;
}
textarea {
width: 100%;
min-height: 200px;
padding: 15px;
border: 2px solid #e9ecef;
border-radius: 8px;
font-size: 16px;
line-height: 1.5;
resize: vertical;
transition: border-color 0.3s;
}
textarea:focus {
border-color: #dc3545;
outline: none;
box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}
.preview-container {
min-height: 200px;
padding: 15px;
border: 2px solid #e9ecef;
border-radius: 8px;
background-color: #f8f9fa;
font-size: 16px;
line-height: 1.5;
white-space: pre-wrap;
word-wrap: break-word;
}
.templates-section {
margin-top: 25px;
background: white;
border-radius: 10px;
padding: 25px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}
.templates-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 15px;
margin-top: 15px;
}
.template-item {
padding: 15px;
background: #f8f9fa;
border-radius: 8px;
border: 1px solid #e9ecef;
cursor: pointer;
transition: all 0.2s;
}
.template-item:hover {
background: #e9ecef;
border-color: #dc3545;
transform: translateY(-2px);
}
.template-title {
font-weight: 600;
color: #495057;
margin-bottom: 8px;
display: flex;
align-items: center;
gap: 8px;
}
.template-reason {
color: #6c757d;
font-size: 14px;
line-height: 1.4;
}
.button-group {
display: flex;
gap: 10px;
margin-top: 20px;
}
button {
padding: 12px 20px;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 15px;
font-weight: 500;
transition: all 0.2s;
display: flex;
align-items: center;
gap: 8px;
}
.primary-btn {
background: #dc3545;
color: white;
}
.primary-btn:hover {
background: #c82333;
transform: translateY(-2px);
}
.secondary-btn {
background: #6c757d;
color: white;
}
.secondary-btn:hover {
background: #5a6268;
transform: translateY(-2px);
}
.warning-note {
margin-top: 20px;
padding: 15px;
background: #fff3cd;
border-radius: 8px;
border-left: 4px solid #ffc107;
font-size: 14px;
color: #856404;
}
.highlight {
background-color: #fff3cd;
padding: 1px 3px;
border-radius: 3px;
}
.error {
background-color: #f8d7da;
padding: 1px 3px;
border-radius: 3px;
text-decoration: line-through;
}
.correction {
background-color: #d4edda;
padding: 1px 3px;
border-radius: 3px;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>封鎖原因預覽工具</h1>
<p class="subtitle">即時預覽封鎖原因,防止打字錯誤造成尷尬局面。輸入時自動修正常見錯別字。</p>
</header>
<div class="main-content">
<div class="input-section">
<div class="section-title">
<i>📝</i> 輸入封鎖原因
</div>
<textarea id="blockInput" placeholder="請輸入封鎖原因...">由於用戶持續進行破壞性編緝,違反破壞方針,現予以封鎖。請在討論頁提出異議。</textarea>
<div class="button-group">
<button class="primary-btn" id="clearBtn">
<i>🗑️</i> 清除
</button>
<button class="secondary-btn" id="exampleBtn">
<i>📋</i> 載入示例
</button>
</div>
</div>
<div class="preview-section">
<div class="section-title">
<i>👁️</i> 預覽效果
</div>
<div class="preview-container" id="previewOutput">
預覽將在此顯示...
</div>
<div class="button-group">
<button class="primary-btn" id="copyBtn">
<i>📋</i> 複製到剪貼板
</button>
</div>
<div class="warning-note">
<strong>注意:</strong> 預覽中<mark class="highlight">黃色標記</mark>的部分是自動修正的常見錯別字,<mark class="error">紅色刪除線</mark>表示錯誤詞語,<mark class="correction">綠色</mark>表示修正後的詞語。
</div>
</div>
</div>
<div class="templates-section">
<div class="section-title">
<i>📋</i> 常用封鎖原因模板
</div>
<div class="templates-grid" id="templatesGrid">
<!-- 模板將由JavaScript動態生成 -->
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const blockInput = document.getElementById('blockInput');
const previewOutput = document.getElementById('previewOutput');
const clearBtn = document.getElementById('clearBtn');
const exampleBtn = document.getElementById('exampleBtn');
const copyBtn = document.getElementById('copyBtn');
const templatesGrid = document.getElementById('templatesGrid');
// 常見錯別字對照表
const commonErrors = {
"編緝": "編輯",
"編揖": "編輯",
"緝輯": "編輯",
"違返": "違反",
"違返": "違反",
"方針針": "方針",
"方什": "方針",
"傳記記": "傳記",
"宣傳": "宣傳",
"廣吿": "廣告",
"帳號": "帳戶",
"賬戶": "帳戶",
"賬號": "帳戶",
"異議議": "異議",
"討讑": "討論",
"討淪": "討論",
"討倫": "討論",
"惡搞": "破壞",
"亂搞": "破壞",
"攻擊擊": "攻擊",
"攻撃": "攻擊",
"無故": "無故",
"任意": "任意",
"持續": "持續",
"重複": "重複"
};
// 不專業或情緒化詞彙(應該避免使用)
const unprofessionalWords = ["白痴", "笨蛋", "蠢貨", "混蛋", "去死", "垃圾", "廢物", "智障", "腦殘","SB","畜生"];
// 封鎖原因模板
const blockTemplates = [
{
title: "破壞性編輯",
reason: "由於多次進行破壞性編輯,違反破壞方針,現予以不限期封鎖。請在討論頁提出異議。"
},
{
title: "編輯戰",
reason: "因打編輯戰,違反回退不過三原則,現予以封鎖。請在討論頁提出異議。"
},
{
title: "違反生者傳記",
reason: "由於在人物相關條目中添加未經查證的內容,違反生者傳記方針,現予以封鎖。請在討論頁提出異議。"
},
{
title: "宣傳內容",
reason: "由於添加宣傳或廣告內容,違反相關方針,現予以封鎖。請在討論頁提出異議。"
},
{
title: "人身攻擊",
reason: "由於對其他用戶進行人身攻擊,違反不要人身攻擊方針,現予以封鎖。請在討論頁提出異議。"
},
{
title: "濫用多個帳戶",
reason: "由於濫用多個帳戶進行違規操作,違反傀儡方針,現予以封鎖。請在討論頁提出異議。"
},
{
title: "侵權內容",
reason: "由於持續添加侵權內容,違反版權方針,現予以封鎖。請在討論頁提出異議。"
},
{
title: "傀儡帳戶",
reason: "此帳戶被確認為傀儡帳戶,違反傀儡方針,現予以不限期封鎖。"
}
];
// 初始化模板
function initTemplates() {
templatesGrid.innerHTML = '';
blockTemplates.forEach(template => {
const templateItem = document.createElement('div');
templateItem.className = 'template-item';
templateItem.innerHTML = `
<div class="template-title">
<i>📄</i> ${template.title}
</div>
<div class="template-reason">${template.reason}</div>
`;
templateItem.addEventListener('click', function() {
blockInput.value = template.reason;
updatePreview();
});
templatesGrid.appendChild(templateItem);
});
}
// 更新預覽
function updatePreview() {
let text = blockInput.value;
let previewHTML = text;
// 替換常見錯別字並標記
for (const [error, correction] of Object.entries(commonErrors)) {
if (text.includes(error)) {
const regex = new RegExp(`(${error})`, 'g');
previewHTML = previewHTML.replace(regex, `<span class="error">$1</span><span class="correction">${correction}</span>`);
}
}
// 標記不專業詞彙
unprofessionalWords.forEach(word => {
if (text.includes(word)) {
const regex = new RegExp(`(${word})`, 'g');
previewHTML = previewHTML.replace(regex, `<span class="error">$1</span>`);
}
});
// 將換行轉換為HTML換行
previewHTML = previewHTML.replace(/\n/g, '<br>');
// 更新預覽區域
previewOutput.innerHTML = previewHTML || '<span style="color:#6c757d;">預覽將在此顯示...</span>';
}
// 清除輸入
function clearInput() {
blockInput.value = '';
updatePreview();
blockInput.focus();
}
// 載入示例
function loadExample() {
blockInput.value = "由於用戶持續進行破壞性編緝,違反破壞方針,並在討論頁對其他編輯者進行人身攻擊(使用不當言辭如'白痴'),現予以封鎖。請在討論頁提出異議。";
updatePreview();
}
// 複製到剪貼板
function copyToClipboard() {
const correctedText = getCorrectedText();
if (!correctedText.trim()) {
alert('沒有內容可複製');
return;
}
navigator.clipboard.writeText(correctedText)
.then(() => {
// 顯示成功反饋
const originalText = copyBtn.innerHTML;
copyBtn.innerHTML = '<i>✓</i> 已複製';
copyBtn.style.backgroundColor = '#28a745';
setTimeout(() => {
copyBtn.innerHTML = originalText;
copyBtn.style.backgroundColor = '';
}, 2000);
})
.catch(err => {
console.error('複製失敗: ', err);
alert('複製失敗,請手動複製內容');
});
}
// 獲取修正後的文本(自動修正錯別字)
function getCorrectedText() {
let text = blockInput.value;
// 替換常見錯別字
for (const [error, correction] of Object.entries(commonErrors)) {
if (text.includes(error)) {
text = text.replace(new RegExp(error, 'g'), correction);
}
}
return text;
}
// 事件監聽器
blockInput.addEventListener('input', updatePreview);
clearBtn.addEventListener('click', clearInput);
exampleBtn.addEventListener('click', loadExample);
copyBtn.addEventListener('click', copyToClipboard);
// 初始化
initTemplates();
updatePreview();
// 快捷鍵支持
document.addEventListener('keydown', function(e) {
// Ctrl + Enter 複製
if (e.ctrlKey && e.key === 'Enter') {
e.preventDefault();
copyToClipboard();
}
// Ctrl + L 載入示例
if (e.ctrlKey && e.key === 'l') {
e.preventDefault();
loadExample();
}
// Ctrl + K 清除
if (e.ctrlKey && e.key === 'k') {
e.preventDefault();
clearInput();
}
});
});
</script>
</body>
</JavaScript>