// ==UserScript==
// @name Linux DO 快捷评论助手
// @namespace http://tampermonkey.net/
// @version 1.01
// @description 为 Linux DO 论坛添加快捷评论功能
// @author Your name
// @match https://linux.do/*
// @license MIT
// @grant none
// ==/UserScript==
;(function () {
"use strict"
// 默认快捷评论列表
// 默认快捷评论列表
const quickComments = [
"感谢分享 🙏",
"直接起飞 🚀",
"感谢大佬分享 ✨",
"学习了,收藏! 📚",
"涨知识了 🧠",
"学到了学到了 ✌️",
"mark一下,以后用得着 🔖",
"太强了吧 🚀",
"学习ing... 📝",
"收藏了,慢慢消化 🤓",
"大佬tql 🎉",
"学习了,学习了 💪"
]
// 创建快捷评论面板
function createQuickCommentPanel() {
const panel = document.createElement("div")
panel.style.cssText = `
position: fixed;
right: 80px;
top: 50%;
transform: translateY(-50%);
background: linear-gradient(145deg, #e8f4f8, #d5e6f3);
padding: 15px;
border-radius: 16px;
box-shadow: 5px 5px 15px rgba(0,0,0,0.1),
-5px -5px 15px rgba(255,255,255,0.5);
width: 160px;
z-index: 999;
transition: all 0.3s ease;
`
// 添加标题
const title = document.createElement("div")
title.textContent = "✨ 快捷评论"
title.style.cssText = `
font-size: 16px;
font-weight: bold;
margin-bottom: 15px;
text-align: center;
color: #2c3e50;
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
padding-bottom: 10px;
border-bottom: 2px solid #b8d4e8;
`
panel.appendChild(title)
// 添加快捷评论按钮
quickComments.forEach(comment => {
const button = document.createElement("button")
button.textContent = comment
button.style.cssText = `
display: block;
width: 100%;
margin: 8px 0;
padding: 8px 12px;
border: none;
border-radius: 8px;
background: linear-gradient(145deg, #f0f9ff, #d8e9f3);
box-shadow: 3px 3px 6px rgba(0,0,0,0.1),
-3px -3px 6px rgba(255,255,255,0.8);
cursor: pointer;
font-size: 13px;
color: #444;
transition: all 0.2s ease;
position: relative;
overflow: hidden;
`
button.addEventListener("mouseover", () => {
button.style.cssText += `
transform: translateY(-2px);
background: linear-gradient(145deg, #e6e6e6, #ffffff);
color: #2980b9;
box-shadow: 4px 4px 8px rgba(0,0,0,0.15),
-4px -4px 8px rgba(255,255,255,0.9);
`
})
button.addEventListener("mouseout", () => {
button.style.cssText = button.getAttribute("style").replace(/transform:[^;]+;/, "")
button.style.background = "linear-gradient(145deg, #f0f9ff, #d8e9f3)"
button.style.color = "#444"
})
button.addEventListener("mousedown", () => {
button.style.cssText += `
transform: scale(0.95);
box-shadow: 2px 2px 4px rgba(0,0,0,0.1),
-2px -2px 4px rgba(255,255,255,0.8);
`
})
button.addEventListener("mouseup", () => {
button.style.transform = "scale(1)"
})
button.addEventListener("click", () => {
const replyButton = document.querySelector(".widget-button.reply")
if (replyButton) {
insertComment(comment)
}
})
panel.appendChild(button)
})
// 添加面板hover效果
panel.addEventListener("mouseover", () => {
panel.style.transform = "translateY(-50%) scale(1.02)"
panel.style.boxShadow = "6px 6px 20px rgba(0,0,0,0.15), -6px -6px 20px rgba(255,255,255,0.6)"
})
panel.addEventListener("mouseout", () => {
panel.style.transform = "translateY(-50%) scale(1)"
panel.style.boxShadow = "5px 5px 15px rgba(0,0,0,0.1), -5px -5px 15px rgba(255,255,255,0.8)"
})
return panel
}
// 插入评论到输入框
function insertComment(comment) {
// 首先找到并点击回复按钮
const replyButton = document.querySelector(".widget-button.reply")
if (replyButton) {
replyButton.click()
// 等待500ms让评论框加载出来
setTimeout(() => {
const editor = document.querySelector(".d-editor-textarea-wrapper textarea")
if (editor) {
editor.value = comment
// 触发 input 和 change 事件以确保评论框和预览都能正确更新
editor.dispatchEvent(new Event("input", { bubbles: true }))
editor.dispatchEvent(new Event("change", { bubbles: true }))
// 让评论框获得焦点
editor.focus()
} else {
console.log("未找到评论框")
}
}, 500)
} else {
console.log("未找到回复按钮")
}
}
// 等待页面加载完成后添加快捷评论面板
function init() {
// 检查当前页面是否为帖子页面
const checkAndAddPanel = () => {
const hasCommentFeature = document.querySelector(".timeline-controls")
const hasPanel = document.querySelector(".quick-comment-panel")
if (hasCommentFeature && !hasPanel) {
const panel = createQuickCommentPanel()
panel.classList.add("quick-comment-panel")
document.body.appendChild(panel)
} else if (!hasCommentFeature && hasPanel) {
hasPanel.remove()
}
}
// 初始检查
checkAndAddPanel()
// 监听 URL 变化
let lastUrl = location.href
new MutationObserver(() => {
const url = location.href
if (url !== lastUrl) {
lastUrl = url
checkAndAddPanel()
}
}).observe(document.body, { subtree: true, childList: true })
// 监听 DOM 变化
const observer = new MutationObserver(() => {
checkAndAddPanel()
})
observer.observe(document.body, {
childList: true,
subtree: true
})
}
// 页面加载完成后初始化
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init)
} else {
init()
}
})()