// ==UserScript==
// @name 豆瓣侠
// @version 1.0.1
// @description 云盘搜索(5个站点) + 电影简介生成(加回豆瓣页面可点击IMDb链接)
// @author 全网搜:wpys.cc
// @match https://movie.douban.com/subject/*
// @match https://book.douban.com/subject/*
// @match https://music.douban.com/subject/*
// @grant GM_setClipboard
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// @require https://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==
(function() {
'use strict';
GM_addStyle(`
.c-aside { margin-bottom: 30px; }
.c-aside h2 { font-size: 14px; color: #333; margin-bottom: 10px; }
.c-aside-body a {
border-radius: 6px; color: #006400; display: inline-block;
margin: 0 8px 8px 0; padding: 0 8px; text-align: center;
width: 65px; background-color: #f5f5f5; text-decoration: none;
font-size: 12px; line-height: 24px; font-weight: bold;
}
.c-aside-body a:hover { background-color: #e8e8e8; }
#md-generator {
margin: 20px 0; padding: 15px; background: #f9f9f9;
border-radius: 6px; border-left: 4px solid #00a65a;
}
#md-generator-btn {
background: #00a65a; color: white; border: none;
padding: 8px 20px; border-radius: 4px; cursor: pointer;
font-size: 14px; font-weight: bold;
}
#md-generator-btn:hover { background: #008d4c; }
#md-preview {
margin-top: 15px; padding: 15px; background: #f5f5f5;
border-radius: 4px; border: 1px solid #ddd; display: none;
}
#md-preview pre {
margin: 0; white-space: pre-wrap; font-family: 'Courier New', monospace;
font-size: 13px; line-height: 1.6; background: #f5f5f5; padding: 10px;
}
.preview-header {
display: flex; justify-content: space-between; align-items: center;
margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px dashed #ccc;
}
.preview-header-left {
display: flex; align-items: center;
}
.preview-header-left span {
font-weight: bold;
margin-right: 15px;
}
#md-copy-btn {
background: #337ab7; color: white; border: none;
padding: 4px 12px; border-radius: 4px; cursor: pointer;
font-size: 12px;
}
#md-copy-btn:hover { background: #286090; }
#md-copy-btn.copied { background: #5cb85c; }
/* 设置面板样式 */
#doudanxia-settings {
position: fixed; top: 80px; right: 20px; width: 380px;
background: white; border: 1px solid #ddd; border-radius: 8px;
box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 9999;
padding: 20px; font-size: 13px;
}
.settings-header {
display: flex; justify-content: space-between; align-items: center;
margin-bottom: 15px; padding-bottom: 10px; border-bottom: 2px solid #00a65a;
}
.settings-header h3 { margin: 0; color: #00a65a; }
.settings-section {
margin-bottom: 20px; padding: 12px; background: #f9f9f9; border-radius: 6px;
}
.site-tag {
display: inline-block; background: #e8e8e8; padding: 4px 12px;
border-radius: 20px; font-size: 12px; margin: 0 5px 5px 0;
}
.close-btn {
background: #f0f0f0; border: none; padding: 5px 20px;
border-radius: 20px; cursor: pointer; font-size: 12px;
}
.close-btn:hover { background: #e0e0e0; }
.view-original {
display: inline-block;
margin-left: 10px;
font-size: 12px;
color: #00a65a;
text-decoration: none;
}
.view-original:hover { text-decoration: underline; }
`);
const PAN_SITES = [
{ name: '网盘论坛', url: 'https://wpzy.cc/?q=' },
{ name: '网盘影视', url: 'https://wpzy.me/?q=' },
{ name: '网盘资源社', url: 'https://www.wpzy.cc/?q=' },
{ name: '全网搜索', url: 'https://wpys.cc/s/' },
{ name: '博哥影视', url: 'https://blog.wpys.cc/search/' }
];
// 读取用户设置,默认启用生成器
const enableGenerator = GM_getValue('enable-generator', true);
$(document).ready(function() {
const pageType = location.host.split('.')[0];
const subjectId = location.href.match(/(\d{7,8})/);
if (!subjectId) return;
let title = $('#content h1 span').first().text().trim();
let searchTitle = title;
if (title.includes(' ')) {
searchTitle = title.split(' ')[0];
}
const searchKeyword = encodeURIComponent(searchTitle);
// 插入豆瓣侠标识和云盘搜索
$('#content div.aside').prepend(`
云盘搜索· · · · · ·
${PAN_SITES.map(site =>
`
${site.name}`
).join('')}
`);
// 插入设置按钮
$("#db-global-nav > div > div.top-nav-info").append(`⚙️ 豆瓣侠设置`);
$("#doudanxia-setting-btn").click(showSettingsPanel);
if ($('#mainpic').length) {
addViewOriginalLink();
}
// ===== 电影页面额外处理:加回可点击的IMDb链接 =====
if (pageType === 'movie') {
let imdb_anchor = $('#info span.pl:contains("IMDb")');
if (imdb_anchor.length > 0) {
let imdb_text = imdb_anchor[0].nextSibling.nodeValue;
if (imdb_text) {
let imdb_id = imdb_text.trim();
let imdb_link = `https://www.imdb.com/title/${imdb_id}/`;
$(imdb_anchor[0].nextSibling).replaceWith(` ${imdb_id}`);
}
}
}
// 根据设置决定是否显示生成器
if (enableGenerator) {
if (pageType === 'movie') insertMovieGenerator();
else if (pageType === 'book') insertBookGenerator();
else if (pageType === 'music') insertMusicGenerator();
}
});
// 设置面板
function showSettingsPanel() {
if ($('#doudanxia-settings').length) {
$('#doudanxia-settings').remove();
return;
}
const sitesHtml = PAN_SITES.map(site =>
`${site.name}`
).join('');
const currentEnable = GM_getValue('enable-generator', true);
$('body').append(`
📁 云盘搜索 (5个站点)
${sitesHtml}
点击链接自动搜索当前资源
`);
$('#close-settings').click(() => $('#doudanxia-settings').remove());
$('#enable-generator').change(function() {
const enabled = $(this).is(':checked');
GM_setValue('enable-generator', enabled);
if (confirm('设置已保存,是否刷新页面?')) {
location.reload();
}
});
$(document).mouseup(function(e) {
const container = $('#doudanxia-settings');
if (!container.is(e.target) && container.has(e.target).length === 0) {
container.remove();
}
});
}
// 查看原图
function addViewOriginalLink() {
let posterImg = document.querySelector('#mainpic > a > img');
if (!posterImg) return;
let postersUrl = posterImg.getAttribute('src');
let rawUrl = postersUrl.replace(/\/photo\/[sl](?:_ratio_poster|pic|\/)?\/public\/(p\d+).+$/, "/photo/raw/public/$1.jpg");
if (rawUrl === postersUrl) {
rawUrl = postersUrl.split('?')[0];
}
$('#mainpic p.gact').after(`
🔗 查看原图
`);
}
function insertMovieGenerator() {
$('#info').after(`
`);
$('#md-generator-btn').click(function() {
if ($('#md-preview').is(':visible')) {
$('#md-preview').slideUp(300);
$(this).text('📋 生成电影简介');
} else {
generateMovieMarkdown();
$('#md-preview').slideDown(300);
$(this).text('📋 收缩预览');
}
});
$('#md-copy-btn').click(copyToClipboard);
}
function generateMovieMarkdown() {
const data = {};
data.title = $('#content h1 span').first().text().trim();
// 获取豆瓣原图 + weserv.nl 处理
let posterImg = document.querySelector('#mainpic > a > img');
if (posterImg) {
let postersUrl = posterImg.getAttribute('src');
// 先用原脚本的正则提取原图地址
let rawUrl = postersUrl.replace(/\/photo\/[sl](?:_ratio_poster|pic|\/)?\/public\/(p\d+).+$/, "/photo/raw/public/$1.jpg");
// 如果正则替换失败,至少去掉 ? 后面的参数
if (rawUrl === postersUrl) {
rawUrl = postersUrl.split('?')[0];
}
// 用 weserv.nl 处理成 1080p
data.poster = `https://images.weserv.nl/?url=${encodeURIComponent(rawUrl)}&width=1080&fit=inside&we&output=webp`;
}
const infoText = $('#info').text();
const akaMatch = infoText.match(/又名:\s*([^\n]+)/);
data.aka = akaMatch ? akaMatch[1].trim() : '';
const yearMatch = infoText.match(/(\d{4})-/);
data.year = yearMatch ? yearMatch[1] : '';
const regionMatch = infoText.match(/制片国家\/地区:\s*([^\n]+)/);
data.region = regionMatch ? regionMatch[1].trim() : '';
const languageMatch = infoText.match(/语言:\s*([^\n]+)/);
data.language = languageMatch ? languageMatch[1].trim() : '';
const imdbMatch = infoText.match(/IMDb:\s*([a-z]{2}\d{7,8})/i);
data.imdbId = imdbMatch ? imdbMatch[1] : '';
data.genres = $('span[property="v:genre"]').map(function() {
return $(this).text().trim();
}).get().join('/');
data.releaseDate = $('span[property="v:initialReleaseDate"]').first().text().trim();
data.runtime = $('span[property="v:runtime"]').text().trim();
data.directors = $('a[rel="v:directedBy"]').map(function() {
return $(this).text().trim();
}).get().join(' / ');
data.writers = [];
$('#info span.pl:contains("编剧")').parent().find('a[href*="celebrity"]').each(function() {
data.writers.push($(this).text().trim());
});
data.casts = [];
$('.actor a[href*="celebrity"]').each(function(index) {
if (index < 15) data.casts.push($(this).text().trim());
});
data.doubanRating = $('strong.ll.rating_num').text().trim();
data.doubanVotes = $('a.rating_people span').text().trim();
data.intro = $('#link-report .all').text().trim() ||
$('span[property="v:summary"]').text().trim() ||
'暂无简介';
data.intro = data.intro.replace(/\s+/g, ' ').replace(/ /g, ' ');
const doubanId = window.location.href.match(/\d{7,8}/)?.[0] || '';
let md = '';
if (data.poster) md += `\n\n`;
if (data.aka) md += `◎译 名 ${data.aka}\n`;
md += `◎片 名 ${data.title}\n`;
if (data.year) md += `◎年 代 ${data.year}\n`;
if (data.region) md += `◎产 地 ${data.region}\n`;
if (data.genres) md += `◎类 别 ${data.genres}\n`;
if (data.language) md += `◎语 言 ${data.language}\n`;
if (data.releaseDate) md += `◎上映日期 ${data.releaseDate}\n`;
if (data.imdbId) md += `◎IMDb链接 https://www.imdb.com/title/${data.imdbId}/\n`;
if (data.doubanRating) {
md += `◎豆瓣评分 ${data.doubanRating}/10 from ${data.doubanVotes} users\n`;
}
md += `◎豆瓣链接 https://douban.com/subject/${doubanId}/\n`;
if (data.runtime) md += `◎片 长 ${data.runtime}\n`;
if (data.directors) md += `◎导 演 ${data.directors}\n`;
if (data.writers.length) {
md += `◎编 剧 ${data.writers[0]}\n`;
for (let i = 1; i < data.writers.length; i++) {
md += ` ${data.writers[i]}\n`;
}
}
if (data.casts.length) {
md += `◎主 演 ${data.casts[0]}\n`;
for (let i = 1; i < data.casts.length; i++) {
md += ` ${data.casts[i]}\n`;
}
}
if (data.intro) {
md += `\n◎简 介\n\n`;
md += ` ${data.intro}\n`;
}
$('#md-content').text(md);
}
function insertBookGenerator() {
$('#info').after(`
`);
$('#md-generator-btn').click(function() {
if ($('#md-preview').is(':visible')) {
$('#md-preview').slideUp(300);
$(this).text('📋 生成图书简介');
} else {
generateBookMarkdown();
$('#md-preview').slideDown(300);
$(this).text('📋 收缩预览');
}
});
$('#md-copy-btn').click(copyToClipboard);
}
function generateBookMarkdown() {
const data = {};
data.title = $('#content h1 span').first().text().trim();
let coverImg = document.querySelector('#mainpic > a > img');
if (coverImg) {
let coverUrl = coverImg.getAttribute('src');
// 提取原图
let rawUrl = coverUrl.replace(/\/photo\/[sl](?:_ratio_poster|pic|\/)?\/public\/(p\d+).+$/, "/photo/raw/public/$1.jpg");
if (rawUrl === coverUrl) {
rawUrl = coverUrl.split('?')[0];
}
data.cover = `https://images.weserv.nl/?url=${encodeURIComponent(rawUrl)}&width=1080&fit=inside&we&output=webp`;
}
const infoText = $('#info').text();
data.author = $('#info a[href*="search?cat=1003"]').map(function() {
return $(this).text().trim();
}).get().join(' / ');
const publisherMatch = infoText.match(/出版社:\s*([^\n]+)/);
data.publisher = publisherMatch ? publisherMatch[1].trim() : '';
const seriesMatch = infoText.match(/丛书:\s*([^\n]+)/);
data.series = seriesMatch ? seriesMatch[1].trim() : '';
const isbnMatch = infoText.match(/ISBN:\s*([0-9X-]+)/);
data.isbn = isbnMatch ? isbnMatch[1].trim() : '';
data.rating = $('strong.ll.rating_num').text().trim();
data.votes = $('a.rating_people span').text().trim();
data.intro = $('#link-report .all').text().trim() ||
$('#link-report').text().trim() ||
'暂无简介';
const doubanId = window.location.href.match(/\d{7,8}/)?.[0] || '';
let md = '';
if (data.cover) md += `\n\n`;
md += `◎书 名 ${data.title}\n`;
if (data.author) md += `◎作 者 ${data.author}\n`;
if (data.publisher) md += `◎出版社 ${data.publisher}\n`;
if (data.series) md += `◎丛 书 ${data.series}\n`;
if (data.isbn) md += `◎ISBN ${data.isbn}\n`;
if (data.rating) md += `◎豆瓣评分 ${data.rating}/10 from ${data.votes} users\n`;
md += `◎豆瓣链接 https://book.douban.com/subject/${doubanId}/\n\n`;
if (data.intro) {
md += `◎简 介\n\n`;
md += ` ${data.intro}\n`;
}
$('#md-content').text(md);
}
function insertMusicGenerator() {
$('#info').after(`
`);
$('#md-generator-btn').click(function() {
if ($('#md-preview').is(':visible')) {
$('#md-preview').slideUp(300);
$(this).text('📋 生成音乐简介');
} else {
generateMusicMarkdown();
$('#md-preview').slideDown(300);
$(this).text('📋 收缩预览');
}
});
$('#md-copy-btn').click(copyToClipboard);
}
function generateMusicMarkdown() {
const data = {};
data.title = $('#content h1 span').first().text().trim();
let coverImg = document.querySelector('#mainpic > a > img');
if (coverImg) {
let coverUrl = coverImg.getAttribute('src');
// 提取原图
let rawUrl = coverUrl.replace(/\/photo\/[sl](?:_ratio_poster|pic|\/)?\/public\/(p\d+).+$/, "/photo/raw/public/$1.jpg");
if (rawUrl === coverUrl) {
rawUrl = coverUrl.split('?')[0];
}
data.cover = `https://images.weserv.nl/?url=${encodeURIComponent(rawUrl)}&width=1080&fit=inside&we&output=webp`;
}
data.artist = $('#info a[href*="search?cat=1003"]').first().text().trim();
const infoText = $('#info').text();
const typeMatch = infoText.match(/专辑类型:\s*([^\n]+)/);
data.type = typeMatch ? typeMatch[1].trim() : '';
const mediaMatch = infoText.match(/介质:\s*([^\n]+)/);
data.media = mediaMatch ? mediaMatch[1].trim() : '';
const dateMatch = infoText.match(/发行时间:\s*([^\n]+)/);
data.date = dateMatch ? dateMatch[1].trim() : '';
const publisherMatch = infoText.match(/出版者:\s*([^\n]+)/);
data.publisher = publisherMatch ? publisherMatch[1].trim() : '';
data.rating = $('strong.ll.rating_num').text().trim();
data.votes = $('a.rating_people span').text().trim();
data.tracks = [];
$('.track-list li, #content .song-item').each(function() {
const track = $(this).text().trim();
if (track) data.tracks.push(track);
});
data.intro = $('#link-report .all').text().trim() ||
$('#link-report').text().trim() ||
'暂无简介';
const doubanId = window.location.href.match(/\d{7,8}/)?.[0] || '';
let md = '';
if (data.cover) md += `\n\n`;
md += `◎专辑名称 ${data.title}\n`;
if (data.artist) md += `◎表演者 ${data.artist}\n`;
if (data.type) md += `◎专辑类型 ${data.type}\n`;
if (data.media) md += `◎介质 ${data.media}\n`;
if (data.date) md += `◎发行时间 ${data.date}\n`;
if (data.publisher) md += `◎出版者 ${data.publisher}\n`;
if (data.rating) md += `◎豆瓣评分 ${data.rating}/10 from ${data.votes} users\n`;
md += `◎豆瓣链接 https://music.douban.com/subject/${doubanId}/\n\n`;
if (data.tracks.length) {
md += `◎曲 目\n\n`;
data.tracks.forEach((track, i) => {
md += ` ${i+1}. ${track}\n`;
});
md += `\n`;
}
if (data.intro) {
md += `◎简 介\n\n`;
md += ` ${data.intro}\n`;
}
$('#md-content').text(md);
}
// 复制到剪贴板(自动加三个回车)
function copyToClipboard() {
const text = $('#md-content').text();
if (!text) return;
const textWithBreaks = text + '\n\n\n';
GM_setClipboard(textWithBreaks);
const btn = $('#md-copy-btn');
btn.addClass('copied').text('✅ 复制成功');
setTimeout(() => {
btn.removeClass('copied').text('复制到剪贴板');
}, 2000);
}
})();