// ==UserScript==
// @name 洛谷自动发诗脚本(F3+N快捷键版)
// @namespace http://tampermonkey.net/
// @version 1.2
// @description 使用F3+N快捷键打开控制面板,自动在洛谷发送诗句,支持多种分类和一键发送自定义犇犇
// @author mixue_bc
// @match https://www.luogu.com.cn/*
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_notification
// @grant GM_xmlhttpRequest
// @require https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.10.7/dayjs.min.js
// @connect api.apiopen.top
// @connect jinrishici.com
// @connect v1.jinrishici.com
// @connect api.cenguigui.cn
// ==/UserScript==
(function() {
'use strict';
// 诗词分类数据
const poetryCategories = [
{name: "全部", value: "all"},
{name: "抒情", value: "shuqing"},
{name: "四季", value: "siji"},
{name: "山水", value: "shanshui"},
{name: "天气", value: "tianqi"},
{name: "人物", value: "renwu"},
{name: "人生", value: "rensheng"},
{name: "生活", value: "shenghuo"},
{name: "节日", value: "jieri"},
{name: "动物", value: "dongwu"},
{name: "植物", value: "zhiwu"},
{name: "食物", value: "shiwu"},
{name: "抒情-爱情", value: "shuqing/aiqing"},
{name: "抒情-友情", value: "shuqing/youqing"},
{name: "抒情-离别", value: "shuqing/libie"},
{name: "抒情-思念", value: "shuqing/sinian"},
{name: "抒情-思乡", value: "shuqing/sixiang"},
{name: "抒情-伤感", value: "shuqing/shanggan"},
{name: "抒情-孤独", value: "shuqing/gudu"},
{name: "抒情-闺怨", value: "shuqing/guiyuan"},
{name: "抒情-悼亡", value: "shuqing/daowang"},
{name: "抒情-怀古", value: "shuqing/huaigu"},
{name: "抒情-爱国", value: "shuqing/aiguo"},
{name: "抒情-感恩", value: "shuqing/ganen"},
{name: "四季-春天", value: "siji/chuntian"},
{name: "四季-夏天", value: "siji/xiatian"},
{name: "四季-秋天", value: "siji/qiutian"},
{name: "四季-冬天", value: "siji/dongtian"},
{name: "山水-庐山", value: "shanshui/lushan"},
{name: "山水-泰山", value: "shanshui/taishan"},
{name: "山水-江河", value: "shanshui/jianghe"},
{name: "山水-长江", value: "shanshui/changjiang"},
{name: "山水-黄河", value: "shanshui/huanghe"},
{name: "山水-西湖", value: "shanshui/xihu"},
{name: "山水-瀑布", value: "shanshui/pubu"},
{name: "天气-写风", value: "tianqi/xiefeng"},
{name: "天气-写云", value: "tianqi/xieyun"},
{name: "天气-写雨", value: "tianqi/xieyu"},
{name: "天气-写雪", value: "tianqi/xiexue"},
{name: "天气-彩虹", value: "tianqi/caihong"},
{name: "天气-太阳", value: "tianqi/taiyang"},
{name: "天气-月亮", value: "tianqi/yueliang"},
{name: "天气-星星", value: "tianqi/xingxing"},
{name: "人物-女子", value: "renwu/nvzi"},
{name: "人物-父亲", value: "renwu/fuqin"},
{name: "人物-母亲", value: "renwu/muqin"},
{name: "人物-老师", value: "renwu/laoshi"},
{name: "人物-儿童", value: "renwu/ertong"},
{name: "人生-励志", value: "rensheng/lizhi"},
{name: "人生-哲理", value: "rensheng/zheli"},
{name: "人生-青春", value: "rensheng/qingchun"},
{name: "人生-时光", value: "rensheng/shiguang"},
{name: "人生-梦想", value: "rensheng/mengxiang"},
{name: "人生-读书", value: "rensheng/dushu"},
{name: "人生-战争", value: "rensheng/zhanzheng"},
{name: "生活-乡村", value: "shenghuo/xiangcun"},
{name: "生活-田园", value: "shenghuo/tianyuan"},
{name: "生活-边塞", value: "shenghuo/biansai"},
{name: "生活-写桥", value: "shenghuo/xieqiao"},
{name: "节日-春节", value: "jieri/chunjie"},
{name: "节日-元宵节", value: "jieri/yuanxiaojie"},
{name: "节日-寒食节", value: "jieri/hanshijie"},
{name: "节日-清明节", value: "jieri/qingmingjie"},
{name: "节日-端午节", value: "jieri/duanwujie"},
{name: "节日-七夕节", value: "jieri/qixijie"},
{name: "节日-中秋节", value: "jieri/zhongqiujie"},
{name: "节日-重阳节", value: "jieri/chongyangjie"},
{name: "动物-写鸟", value: "dongwu/xieniao"},
{name: "动物-写马", value: "dongwu/xiema"},
{name: "动物-写猫", value: "dongwu/xiemao"},
{name: "植物-梅花", value: "zhiwu/meihua"},
{name: "植物-梨花", value: "zhiwu/lihua"},
{name: "植物-桃花", value: "zhiwu/taohua"},
{name: "植物-荷花", value: "zhiwu/hehua"},
{name: "植物-菊花", value: "zhiwu/juhua"},
{name: "植物-柳树", value: "zhiwu/liushu"},
{name: "植物-叶子", value: "zhiwu/yezi"},
{name: "植物-竹子", value: "zhiwu/zhuzi"},
{name: "食物-写酒", value: "shiwu/xiejiu"},
{name: "食物-写茶", value: "shiwu/xiecha"},
{name: "食物-荔枝", value: "shiwu/lizhi"}
];
// 添加样式
GM_addStyle(`
.autopoetry-container {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 450px;
background: white;
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
z-index: 10000;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
overflow: hidden;
display: none;
transition: all 0.3s ease;
}
.autopoetry-container.visible {
display: block;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
from { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.autopoetry-header {
background: linear-gradient(90deg, #6a11cb 0%, #2575fc 100%);
color: white;
padding: 18px;
display: flex;
justify-content: space-between;
align-items: center;
cursor: move;
}
.autopoetry-title {
font-size: 18px;
font-weight: 600;
}
.autopoetry-close {
background: none;
border: none;
color: white;
font-size: 22px;
cursor: pointer;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
transition: background 0.2s;
}
.autopoetry-close:hover {
background: rgba(255, 255, 255, 0.2);
}
.autopoetry-body {
padding: 20px;
max-height: 500px;
overflow-y: auto;
}
.autopoetry-section {
margin-bottom: 20px;
}
.autopoetry-section-title {
font-size: 16px;
font-weight: 600;
margin-bottom: 12px;
color: #1a1a1a;
display: flex;
align-items: center;
padding-bottom: 8px;
border-bottom: 1px solid #f0f0f0;
}
.autopoetry-section-title i {
margin-right: 10px;
color: #6a11cb;
}
.autopoetry-input {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 14px;
margin-bottom: 12px;
transition: border 0.2s;
}
.autopoetry-input:focus {
border-color: #6a11cb;
outline: none;
}
.autopoetry-select {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 14px;
margin-bottom: 12px;
background: white;
}
.autopoetry-btn {
width: 100%;
padding: 12px;
background: linear-gradient(90deg, #6a11cb 0%, #2575fc 100%);
color: white;
border: none;
border-radius: 6px;
font-size: 15px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
margin-bottom: 12px;
display: flex;
align-items: center;
justify-content: center;
}
.autopoetry-btn:hover {
opacity: 0.9;
transform: translateY(-2px);
box-shadow: 0 4px 10px rgba(106, 17, 203, 0.3);
}
.autopoetry-btn i {
margin-right: 8px;
}
.autopoetry-switch {
position: relative;
display: inline-block;
width: 50px;
height: 24px;
}
.autopoetry-switch input {
opacity: 0;
width: 0;
height: 0;
}
.autopoetry-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 24px;
}
.autopoetry-slider:before {
position: absolute;
content: "";
height: 18px;
width: 18px;
left: 3px;
bottom: 3px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .autopoetry-slider {
background: linear-gradient(90deg, #6a11cb 0%, #2575fc 100%);
}
input:checked + .autopoetry-slider:before {
transform: translateX(26px);
}
.autopoetry-status {
font-size: 14px;
padding: 10px;
border-radius: 6px;
background-color: #f9f9f9;
margin-top: 12px;
border-left: 4px solid #6a11cb;
}
.autopoetry-history {
max-height: 150px;
overflow-y: auto;
font-size: 13px;
border: 1px solid #eee;
border-radius: 6px;
padding: 12px;
background: #fafafa;
}
.autopoetry-history-item {
padding: 8px 0;
border-bottom: 1px solid #eee;
display: flex;
align-items: center;
}
.autopoetry-history-item:last-child {
border-bottom: none;
}
.autopoetry-time {
color: #888;
font-size: 12px;
margin-right: 10px;
min-width: 90px;
}
.autopoetry-toggle {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}
.autopoetry-label {
font-size: 15px;
font-weight: 500;
}
.autopoetry-api-select {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 14px;
margin-bottom: 12px;
background: white;
}
.autopoetry-hotkey {
position: absolute;
bottom: 15px;
right: 15px;
font-size: 12px;
color: #888;
background: #f5f5f5;
padding: 4px 8px;
border-radius: 4px;
}
.autopoetry-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: none;
}
.autopoetry-overlay.visible {
display: block;
animation: fadeIn 0.3s ease;
}
.autopoetry-category-container {
display: none;
}
.autopoetry-category-container.visible {
display: block;
}
.autopoetry-textarea {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 14px;
margin-bottom: 12px;
transition: border 0.2s;
resize: vertical;
min-height: 80px;
font-family: inherit;
}
.autopoetry-textarea:focus {
border-color: #6a11cb;
outline: none;
}
.autopoetry-divider {
height: 1px;
background: #eee;
margin: 20px 0;
}
`);
let panelVisible = false;
let panel = null;
let overlay = null;
let checkTimer = null;
// 创建UI
function createUI() {
// 创建遮罩层
overlay = document.createElement('div');
overlay.className = 'autopoetry-overlay';
document.body.appendChild(overlay);
// 创建面板
panel = document.createElement('div');
panel.className = 'autopoetry-container';
panel.innerHTML = `
<div class="autopoetry-header">
<div class="autopoetry-title">洛谷自动发诗</div>
<button class="autopoetry-close">×</button>
</div>
<div class="autopoetry-body">
<div class="autopoetry-section">
<div class="autopoetry-section-title">
<i class="fas fa-cog"></i> 发送设置
</div>
<div class="autopoetry-toggle">
<span class="autopoetry-label">自动发送</span>
<label class="autopoetry-switch">
<input type="checkbox" id="autopoetry-enabled">
<span class="autopoetry-slider"></span>
</label>
</div>
<select class="autopoetry-api-select" id="autopoetry-api">
<option value="apiopen">随机诗句API (apiopen.top)</option>
<option value="jinrishici">今日诗词API (jinrishici.com)</option>
<option value="yiyan">随机一言古诗版 (cenguigui.cn)</option>
</select>
<div class="autopoetry-category-container" id="autopoetry-category-container">
<select class="autopoetry-select" id="autopoetry-category">
${poetryCategories.map(cat => `<option value="${cat.value}">${cat.name}</option>`).join('')}
</select>
</div>
<input type="time" class="autopoetry-input" id="autopoetry-time" value="09:00">
<button class="autopoetry-btn" id="autopoetry-send-now">
<i class="fas fa-paper-plane"></i> 立即发送诗句
</button>
</div>
<div class="autopoetry-divider"></div>
<div class="autopoetry-section">
<div class="autopoetry-section-title">
<i class="fas fa-edit"></i> 发送自定义犇犇
</div>
<textarea class="autopoetry-textarea" id="autopoetry-custom-content" placeholder="请输入犇犇内容..."></textarea>
<button class="autopoetry-btn" id="autopoetry-send-custom">
<i class="fas fa-paper-plane"></i> 立即发送犇犇
</button>
</div>
<div class="autopoetry-section">
<div class="autopoetry-section-title">
<i class="fas fa-history"></i> 发送状态
</div>
<div class="autopoetry-status" id="autopoetry-status">
准备就绪,等待发送...
</div>
</div>
<div class="autopoetry-section">
<div class="autopoetry-section-title">
<i class="fas fa-list"></i> 发送历史
</div>
<div class="autopoetry-history" id="autopoetry-history">
<div class="autopoetry-history-item">暂无发送记录</div>
</div>
</div>
</div>
<div class="autopoetry-hotkey">F3+N 打开/关闭面板</div>
`;
document.body.appendChild(panel);
// 关闭按钮事件
panel.querySelector('.autopoetry-close').addEventListener('click', hidePanel);
// 遮罩层点击事件
overlay.addEventListener('click', hidePanel);
// 立即发送按钮事件
panel.querySelector('#autopoetry-send-now').addEventListener('click', sendPoetryNow);
// 自定义犇犇发送按钮事件
panel.querySelector('#autopoetry-send-custom').addEventListener('click', sendCustomBenben);
// API选择变化事件
panel.querySelector('#autopoetry-api').addEventListener('change', function() {
const categoryContainer = panel.querySelector('#autopoetry-category-container');
if (this.value === 'jinrishici') {
categoryContainer.classList.add('visible');
} else {
categoryContainer.classList.remove('visible');
}
GM_setValue('autopoetry_api', this.value);
});
// 从存储中加载设置
loadSettings();
// 初始化历史记录
loadHistory();
// 初始化拖拽功能
makeDraggable(panel, panel.querySelector('.autopoetry-header'));
// 启动定时检查
startAutoSendCheck();
}
// 显示面板
function showPanel() {
if (!panel) return;
panel.classList.add('visible');
overlay.classList.add('visible');
panelVisible = true;
}
// 隐藏面板
function hidePanel() {
if (!panel) return;
panel.classList.remove('visible');
overlay.classList.remove('visible');
panelVisible = false;
}
// 切换面板显示状态
function togglePanel() {
if (panelVisible) {
hidePanel();
} else {
showPanel();
}
}
// 加载设置
function loadSettings() {
if (!panel) return;
const enabled = GM_getValue('autopoetry_enabled', false);
const time = GM_getValue('autopoetry_time', '09:00');
const api = GM_getValue('autopoetry_api', 'apiopen');
const category = GM_getValue('autopoetry_category', 'all');
panel.querySelector('#autopoetry-enabled').checked = enabled;
panel.querySelector('#autopoetry-time').value = time;
panel.querySelector('#autopoetry-api').value = api;
panel.querySelector('#autopoetry-category').value = category;
// 显示/隐藏分类选择框
const categoryContainer = panel.querySelector('#autopoetry-category-container');
if (api === 'jinrishici') {
categoryContainer.classList.add('visible');
} else {
categoryContainer.classList.remove('visible');
}
// 设置变化时保存
panel.querySelector('#autopoetry-enabled').addEventListener('change', function() {
GM_setValue('autopoetry_enabled', this.checked);
updateStatus(this.checked ? `已启用自动发送,将在每天 ${panel.querySelector('#autopoetry-time').value} 发送` : '已禁用自动发送');
// 重新启动定时检查
stopAutoSendCheck();
if (this.checked) {
startAutoSendCheck();
}
});
panel.querySelector('#autopoetry-time').addEventListener('change', function() {
GM_setValue('autopoetry_time', this.value);
if (panel.querySelector('#autopoetry-enabled').checked) {
updateStatus(`已更新发送时间,将在每天 ${this.value} 发送`);
// 重新启动定时检查
stopAutoSendCheck();
startAutoSendCheck();
}
});
panel.querySelector('#autopoetry-category').addEventListener('change', function() {
GM_setValue('autopoetry_category', this.value);
const selectedCategory = poetryCategories.find(cat => cat.value === this.value);
updateStatus(`已切换分类: ${selectedCategory ? selectedCategory.name : this.value}`);
});
}
// 加载历史记录
function loadHistory() {
if (!panel) return;
const history = GM_getValue('autopoetry_history', []);
const historyElement = panel.querySelector('#autopoetry-history');
if (history.length === 0) {
historyElement.innerHTML = '<div class="autopoetry-history-item">暂无发送记录</div>';
return;
}
historyElement.innerHTML = '';
history.slice(-5).forEach(item => {
const itemElement = document.createElement('div');
itemElement.className = 'autopoetry-history-item';
itemElement.innerHTML = `<span class="autopoetry-time">${item.time}</span> ${item.poetry}`;
historyElement.appendChild(itemElement);
});
}
// 更新状态
function updateStatus(message) {
if (!panel) return;
panel.querySelector('#autopoetry-status').textContent = message;
}
// 发送诗句
async function sendPoetryNow() {
if (!panel) return;
updateStatus('正在获取诗句...');
try {
// 获取API选择
const apiType = panel.querySelector('#autopoetry-api').value;
// 获取随机诗句
const poetry = await getRandomPoetry(apiType);
updateStatus('正在发送诗句...');
// 发送到洛谷
await sendBenBen(poetry);
// 保存到历史记录
const history = GM_getValue('autopoetry_history', []);
history.push({
time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
poetry: poetry
});
GM_setValue('autopoetry_history', history);
// 更新界面
loadHistory();
updateStatus('诗句发送成功!');
// 显示通知
GM_notification({
title: '洛谷自动发诗',
text: '诗句发送成功!',
timeout: 3000
});
} catch (error) {
console.error('发送失败:', error);
updateStatus('发送失败: ' + error.message);
}
}
// 发送自定义犇犇
async function sendCustomBenben() {
if (!panel) return;
const content = panel.querySelector('#autopoetry-custom-content').value.trim();
if (!content) {
updateStatus('请输入犇犇内容');
return;
}
updateStatus('正在发送自定义犇犇...');
try {
// 发送到洛谷
await sendBenBen(content);
// 保存到历史记录
const history = GM_getValue('autopoetry_history', []);
history.push({
time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
poetry: content
});
GM_setValue('autopoetry_history', history);
// 清空输入框
panel.querySelector('#autopoetry-custom-content').value = '';
// 更新界面
loadHistory();
updateStatus('自定义犇犇发送成功!');
// 显示通知
GM_notification({
title: '洛谷发送犇犇',
text: '犇犇发送成功!',
timeout: 3000
});
} catch (error) {
console.error('发送失败:', error);
updateStatus('发送失败: ' + error.message);
}
}
// 获取随机诗句
function getRandomPoetry(apiType) {
return new Promise((resolve, reject) => {
if (apiType === 'jinrishici') {
// 获取选定的分类
const category = panel.querySelector('#autopoetry-category').value;
// 使用今日诗词API
GM_xmlhttpRequest({
method: 'GET',
url: `https://v1.jinrishici.com/${category}.json`,
timeout: 10000,
onload: function(response) {
try {
const data = JSON.parse(response.responseText);
if (data && data.content) {
resolve(data.content);
} else {
reject(new Error('API返回数据格式不正确'));
}
} catch (e) {
reject(new Error('解析API响应失败'));
}
},
onerror: function(error) {
reject(new Error('网络请求失败'));
},
ontimeout: function() {
reject(new Error('请求超时'));
}
});
} else if (apiType === 'yiyan') {
// 使用随机一言古诗版API
GM_xmlhttpRequest({
method: 'GET',
url: 'https://api.cenguigui.cn/api/yyan/api.php',
timeout: 10000,
onload: function(response) {
try {
// 直接返回文本内容
if (response.responseText && response.responseText.trim()) {
resolve(response.responseText.trim());
} else {
reject(new Error('API返回数据为空'));
}
} catch (e) {
reject(new Error('解析API响应失败'));
}
},
onerror: function(error) {
reject(new Error('网络请求失败'));
},
ontimeout: function() {
reject(new Error('请求超时'));
}
});
} else {
// 默认使用apiopen.top的API
GM_xmlhttpRequest({
method: 'GET',
url: 'https://api.apiopen.top/api/sentences',
timeout: 10000,
onload: function(response) {
try {
const data = JSON.parse(response.responseText);
if (data && data.result && data.result.name) {
resolve(data.result.name);
} else {
reject(new Error('API返回数据格式不正确'));
}
} catch (e) {
reject(new Error('解析API响应失败'));
}
},
onerror: function(error) {
reject(new Error('网络请求失败'));
},
ontimeout: function() {
reject(new Error('请求超时'));
}
});
}
});
}
// 发送犇犇
async function sendBenBen(content) {
// 这里是您提供的发送函数
await fetch("https://www.luogu.com.cn/api/feed/postBenben", {
headers: [
["content-type", "application/json"],
["referer", "https://www.luogu.com.cn/"],
["x-csrf-token", document.querySelector("meta[name=csrf-token]").content],
],
body: JSON.stringify({
content: content
}),
method: "POST",
});
}
// 启动自动发送检查
function startAutoSendCheck() {
const enabled = GM_getValue('autopoetry_enabled', false);
if (!enabled) return;
// 清除之前的定时器
stopAutoSendCheck();
// 设置新的定时器,每分钟检查一次
checkTimer = setInterval(() => {
checkAndSendIfTime();
}, 60000); // 每分钟检查一次
// 立即检查一次
checkAndSendIfTime();
console.log('自动发送检查已启动');
}
// 停止自动发送检查
function stopAutoSendCheck() {
if (checkTimer) {
clearInterval(checkTimer);
checkTimer = null;
console.log('自动发送检查已停止');
}
}
// 检查时间并发送
function checkAndSendIfTime() {
const enabled = GM_getValue('autopoetry_enabled', false);
if (!enabled) return;
const time = GM_getValue('autopoetry_time', '09:00');
const now = new Date();
const currentTime = `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
// 获取上次发送日期
const lastSentDate = GM_getValue('autopoetry_last_sent_date', '');
const today = dayjs().format('YYYY-MM-DD');
// 如果当前时间匹配设置的时间,并且今天还没有发送过
if (currentTime === time && lastSentDate !== today) {
console.log('时间匹配,开始发送诗句');
sendPoetryNow();
// 更新最后发送日期
GM_setValue('autopoetry_last_sent_date', today);
}
}
// 使元素可拖动
function makeDraggable(element, handle) {
let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
handle.onmousedown = dragMouseDown;
function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
// 获取鼠标初始位置
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// 计算新的鼠标位置
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// 设置元素的新位置
element.style.top = (element.offsetTop - pos2) + "px";
element.style.left = (element.offsetLeft - pos1) + "px";
}
function closeDragElement() {
document.onmouseup = null;
document.onmousemove = null;
}
}
// 检查是否已登录
function checkLogin() {
return document.querySelector("meta[name=csrf-token]") !== null;
}
// 初始化快捷键
function initHotkey() {
let f3Pressed = false;
document.addEventListener('keydown', function(e) {
// 检测F3键
if (e.key === 'F3' || e.keyCode === 114) {
f3Pressed = true;
e.preventDefault();
}
// 检测N键,且F3已按下
if ((e.key === 'n' || e.key === 'N' || e.keyCode === 78) && f3Pressed) {
togglePanel();
e.preventDefault();
}
});
document.addEventListener('keyup', function(e) {
if (e.key === 'F3' || e.keyCode === 114) {
f3Pressed = false;
}
});
}
// 初始化
function init() {
// 等待页面加载完成
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function() {
if (checkLogin()) {
createUI();
initHotkey();
} else {
console.log('未检测到登录状态,脚本未激活');
}
});
} else {
if (checkLogin()) {
createUI();
initHotkey();
} else {
console.log('未检测到登录状态,脚本未激活');
}
}
}
// 启动脚本
init();
})();剪贴板
剪贴板 9621v758
剪贴板信息
剪贴板信息
- 收录
- 更新