// ==UserScript==
// @name HuggingFace镜像链接提取器
// @namespace http://tampermonkey.net/
// @version 1.3.3
// @description 在HuggingFace页面提取下载链接,同时显示原始链接和hf-mirror.com镜像链接。v1.3.3: 彻底修复搜索高亮间距问题,改用精确匹配和渐变背景
// @author AI Assistant
// @match https://huggingface.co/*
// @match https://hf-mirror.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=huggingface.co
// @grant none
// @downloadURL https://update.greasyfork.icu/scripts/541818/HuggingFace%E9%95%9C%E5%83%8F%E9%93%BE%E6%8E%A5%E6%8F%90%E5%8F%96%E5%99%A8.user.js
// @updateURL https://update.greasyfork.icu/scripts/541818/HuggingFace%E9%95%9C%E5%83%8F%E9%93%BE%E6%8E%A5%E6%8F%90%E5%8F%96%E5%99%A8.meta.js
// ==/UserScript==
(function() {
'use strict';
// 创建样式
const style = document.createElement('style');
style.textContent = `
.hf-extractor-btn {
position: fixed;
top: 20px;
left: 20px;
width: 60px;
height: 60px;
background: linear-gradient(45deg, #ff6b6b, #feca57);
color: white;
border: none;
border-radius: 50%;
cursor: pointer;
font-size: 12px;
font-weight: bold;
z-index: 10000;
box-shadow: 0 4px 15px rgba(0,0,0,0.3);
transition: all 0.3s ease;
}
.hf-extractor-btn:hover {
transform: scale(1.1);
box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.hf-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.5);
z-index: 9999;
display: none;
justify-content: center;
align-items: center;
}
.hf-modal-content {
background: white;
border-radius: 15px;
padding: 20px;
max-width: 95vw;
max-height: 95vh;
overflow: hidden;
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
min-width: 800px;
display: flex;
flex-direction: column;
}
.hf-header {
text-align: center;
margin-bottom: 15px;
color: #333;
border-bottom: 2px solid #eee;
padding-bottom: 10px;
}
.hf-stats {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 10px;
border-radius: 8px;
text-align: center;
margin-bottom: 15px;
font-weight: bold;
font-size: 14px;
}
.hf-buttons {
display: flex;
gap: 8px;
margin-bottom: 15px;
flex-wrap: wrap;
}
.hf-sort-buttons {
display: flex;
gap: 5px;
margin-bottom: 10px;
justify-content: center;
}
.hf-search-container {
margin-bottom: 15px;
position: relative;
}
.hf-search-input {
width: 100%;
padding: 10px 40px 10px 15px;
border: 2px solid #ddd;
border-radius: 8px;
font-size: 14px;
outline: none;
transition: all 0.3s ease;
box-sizing: border-box;
color: #2c3e50 !important;
background: #ffffff !important;
}
.hf-search-input:focus {
border-color: #3498db;
box-shadow: 0 0 10px rgba(52, 152, 219, 0.3);
}
.hf-search-input::placeholder {
color: #7f8c8d !important;
}
.hf-search-clear {
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
background: none;
border: none;
font-size: 18px;
cursor: pointer;
color: #999;
padding: 5px;
border-radius: 50%;
transition: all 0.2s ease;
}
.hf-search-clear:hover {
background: #f0f0f0;
color: #666;
}
.hf-search-stats {
font-size: 12px;
color: #2c3e50 !important;
text-align: center;
margin-top: 5px;
font-weight: 500;
}
.hf-highlight {
background: linear-gradient(to bottom, transparent 0%, transparent 20%, #ffeb3b 20%, #ffeb3b 80%, transparent 80%, transparent 100%) !important;
color: inherit !important;
font-weight: 600 !important;
padding: 0 !important;
margin: 0 !important;
border: none !important;
border-radius: 0 !important;
font-size: inherit !important;
font-family: inherit !important;
display: inline !important;
line-height: inherit !important;
letter-spacing: inherit !important;
word-spacing: inherit !important;
text-decoration: none !important;
vertical-align: baseline !important;
box-shadow: none !important;
outline: none !important;
text-shadow: none !important;
position: relative !important;
}
/* 针对黑暗模式的额外优化 */
@media (prefers-color-scheme: dark) {
.hf-modal-content {
background: #ffffff !important;
color: #2c3e50 !important;
}
.hf-link-item {
background: #f8f9fa !important;
color: #2c3e50 !important;
}
.hf-link-row {
background: #ffffff !important;
color: #2c3e50 !important;
}
}
.hf-sort-btn {
padding: 5px 10px;
border: 1px solid #ddd;
border-radius: 5px;
cursor: pointer;
font-size: 12px;
background: white;
transition: all 0.2s ease;
}
.hf-sort-btn:hover {
background: #f0f0f0;
}
.hf-sort-btn.active {
background: #3498db;
color: white;
border-color: #3498db;
}
.hf-links-wrapper {
flex: 1;
overflow-y: auto;
max-height: calc(95vh - 300px);
}
.hf-btn {
padding: 8px 12px;
border: none;
border-radius: 6px;
cursor: pointer;
font-weight: bold;
transition: all 0.3s ease;
flex: 1;
min-width: 100px;
font-size: 13px;
}
.hf-btn:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.hf-btn-close { background: #e74c3c; color: white; }
.hf-btn-copy-first { background: #3498db; color: white; }
.hf-btn-copy-all-orig { background: #27ae60; color: white; }
.hf-btn-copy-all-mirror { background: #f39c12; color: white; }
.hf-link-item {
background: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 6px;
padding: 8px;
margin-bottom: 6px;
transition: all 0.2s ease;
}
.hf-link-item.main-file {
border: 2px solid #ff6b6b;
background: linear-gradient(135deg, #fff5f5 0%, #ffe8e8 100%);
}
.hf-link-item:hover {
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
transform: translateY(-1px);
}
.hf-file-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 4px;
}
.hf-file-name {
font-weight: bold;
color: #2c3e50 !important;
font-size: 14px;
display: flex;
align-items: center;
gap: 6px;
flex: 1;
}
.hf-file-size {
font-size: 12px;
color: #2c3e50 !important;
background: #e9ecef;
padding: 2px 6px;
border-radius: 4px;
margin-left: 8px;
font-weight: 500;
}
.hf-main-file {
background: linear-gradient(45deg, #ff6b6b, #feca57);
color: white;
padding: 1px 6px;
border-radius: 8px;
font-size: 10px;
font-weight: bold;
}
.hf-link-row {
display: flex;
align-items: center;
margin-bottom: 2px;
padding: 4px;
background: white;
border-radius: 4px;
}
.hf-link-label {
font-weight: bold;
min-width: 45px;
margin-right: 6px;
font-size: 11px;
color: #2c3e50 !important;
}
.hf-link-url {
flex: 1;
font-family: monospace;
font-size: 12px;
word-break: break-all;
margin-right: 6px;
color: #2c3e50 !important;
font-weight: 500;
}
.hf-copy-btn {
padding: 3px 8px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 10px;
font-weight: bold;
transition: all 0.2s ease;
min-width: 40px;
}
.hf-copy-orig { background: #3498db; color: white; }
.hf-copy-mirror { background: #f39c12; color: white; }
.hf-copy-btn:hover { opacity: 0.8; }
.hf-more-info {
text-align: center;
padding: 15px;
color: #7f8c8d;
font-style: italic;
background: #ecf0f1;
border-radius: 8px;
}
`;
document.head.appendChild(style);
// 创建提取按钮
const extractBtn = document.createElement('button');
extractBtn.className = 'hf-extractor-btn';
extractBtn.innerHTML = '🔗
提取';
document.body.appendChild(extractBtn);
// 创建模态框
const modal = document.createElement('div');
modal.className = 'hf-modal';
modal.innerHTML = `