// ==UserScript==
// @name 武理资源共享平台小助手
// @namespace https://resource.haoli.site/
// @version 0.0.1
// @description 为“武理资源共享平台”添加一个轻量介绍浮窗,方便新用户快速了解资源站用途与常用入口。
// @author 毫厘
// @match https://resource.haoli.site/*
// @match http://localhost/*
// @match http://127.0.0.1/*
// @icon https://resource.haoli.site/favicon.png
// @grant none
// @run-at document-idle
// @license MIT
// ==/UserScript==
(function () {
'use strict';
const STORAGE_KEY = 'haoli_resource_helper_intro_hidden_v001';
function $(selector) {
return document.querySelector(selector);
}
function focusSearchBox() {
const input = $('#searchInput, input[type="search"], input[placeholder*="搜索"], input[placeholder*="Search"]');
if (input) {
input.focus();
input.scrollIntoView({ behavior: 'smooth', block: 'center' });
return true;
}
return false;
}
function createButton(text, onClick) {
const button = document.createElement('button');
button.textContent = text;
button.type = 'button';
button.addEventListener('click', onClick);
Object.assign(button.style, {
border: '0',
borderRadius: '999px',
padding: '7px 12px',
cursor: 'pointer',
color: '#ffffff',
background: 'linear-gradient(135deg, #3b82f6, #8b5cf6)',
fontSize: '13px',
boxShadow: '0 6px 16px rgba(59, 130, 246, 0.28)',
});
return button;
}
function showIntroPanel() {
if (localStorage.getItem(STORAGE_KEY) === '1') return;
if (document.getElementById('haoli-resource-helper-panel')) return;
const panel = document.createElement('section');
panel.id = 'haoli-resource-helper-panel';
panel.innerHTML = `
武理资源共享平台小助手
这里是面向武汉理工大学同学的课程资料共享资源站。你可以在这里检索课件、复习资料、实验报告、往年题等学习资源,也可以在规则允许范围内上传自己的整理内容,帮助更多同学少走弯路。
- 优先使用关键词搜索课程名、老师名、资料类型。
- 下载前可查看文件路径与说明,避免拿错资料。
- 上传内容请遵守分享规则,保护个人隐私与版权。
`;
const style = document.createElement('style');
style.textContent = `
#haoli-resource-helper-panel {
position: fixed;
right: 18px;
bottom: 18px;
z-index: 999999;
width: min(360px, calc(100vw - 36px));
padding: 16px 16px 14px;
color: #172033;
background: rgba(255, 255, 255, 0.96);
border: 1px solid rgba(59, 130, 246, 0.18);
border-radius: 18px;
box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
backdrop-filter: blur(14px);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
line-height: 1.65;
}
#haoli-resource-helper-panel .hrh-title {
font-size: 17px;
font-weight: 800;
margin-bottom: 8px;
}
#haoli-resource-helper-panel .hrh-desc {
font-size: 13px;
color: #334155;
}
#haoli-resource-helper-panel .hrh-list {
margin: 8px 0 12px 18px;
padding: 0;
font-size: 12.5px;
color: #475569;
}
#haoli-resource-helper-panel .hrh-actions {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
@media (prefers-color-scheme: dark) {
#haoli-resource-helper-panel {
color: #e5e7eb;
background: rgba(15, 23, 42, 0.94);
border-color: rgba(147, 197, 253, 0.25);
}
#haoli-resource-helper-panel .hrh-desc,
#haoli-resource-helper-panel .hrh-list {
color: #cbd5e1;
}
}
`;
const actions = panel.querySelector('.hrh-actions');
actions.append(
createButton('去搜索', () => {
if (!focusSearchBox()) window.scrollTo({ top: 0, behavior: 'smooth' });
}),
createButton('分享规则', () => {
window.location.href = '/sharing_rules.html';
}),
createButton('不再提示', () => {
localStorage.setItem(STORAGE_KEY, '1');
panel.remove();
}),
);
document.head.appendChild(style);
document.body.appendChild(panel);
}
showIntroPanel();
})();