// ==UserScript==
// @name 豆瓣电影图书主页一键搜索
// @version 3.0
// @description 豆瓣电影、图书主页添加资源网站的搜索链接,图书主页添加复制信息按钮,一键复制作者/译者/出版社等信息,可直接粘贴到excel
// @supportURL
// @match *://movie.douban.com/subject/*
// @match *://book.douban.com/subject/*
// @namespace https://gf.qytechs.cn/users/1117672
// ==/UserScript==
let fetch_anchor = function (anchor) {
return anchor[0].nextSibling.nodeValue.trim();
};
function showLinks () {
let title = document.title.replace(/\([^\)]*\)/g, '');
//这段是用Kimi.ai写的,改了两天,豆瓣的作者和译者信息实在太乱了啊啊啊啊啊啊,每个上传者都有自己的写法,烦死了。谢谢Kimi~
function extractNames(selector) {
let namesSet = new Set(); // 使用Set来存储唯一的名字
if ($(selector).length > 0) {
// 获取所有指定标签的<a>子元素
let linkElements = $(selector).nextAll('a');
linkElements.each(function() {
let name = $(this).text();
// 移除所有括号及其内容,包括空格
name = name.replace(/[()\(\)\【\】\[\]“”‘’“”‘’]+.*?[)\(\)\】\]””’””’]+/g, '').trim();
// 移除人名后面的空格和非人名内容
name = name.replace(/(?:\s+[^ ]+)+$/, '').trim();
// 将“•”替换为“·”
name = name.replace(/•/g, '·').replace(/·/g, '·');
// 分割名字并去除空格
let extractedNames = name.split(/[,\/\s]+/).filter(n => n.trim() !== '');
extractedNames.forEach(function(extractedName) {
namesSet.add(extractedName); // 将名字添加到Set中,自动去重
});
});
}
// 使用“ / ”连接所有唯一的名字
return Array.from(namesSet).join(' / ');
}
let is_writer = $('#info span.pl:contains("作者")').length > 0;
let writer = is_writer ? extractNames('#info span.pl:contains("作者")') : '';
let is_translator = $('#info span.pl:contains("译者")').length > 0;
let translator = is_translator ? extractNames('#info span.pl:contains("译者")') : '';
let is_series = $('#info span.pl:contains("丛书")').length > 0;
let series = is_series ? ' ' + $('#info span.pl:contains("丛书")')[0].nextSibling.nextSibling.textContent : '';
let is_producer = $('#info span.pl:contains("出品方")').length > 0;
let producer = is_producer ? ' ' + $('#info span.pl:contains("出品方")')[0].nextSibling.nextSibling.textContent: '';
let is_publisher = $('#info span.pl:contains("出版社")').length > 0;
let publisher = is_publisher ? ' ' + $('#info span.pl:contains("出版社")')[0].nextSibling.nextSibling.textContent: '';
let is_publishYear = $('#info span.pl:contains("出版年")').length > 0;
let publishYear = is_publishYear ? ' ' + $('#info span.pl:contains("出版年")')[0].nextSibling.textContent : '';
let is_page = $('#info span.pl:contains("页数")').length > 0;
let page = is_page ? ' ' + $('#info span.pl:contains("页数")')[0].nextSibling.textContent.match(/\d+/) : '';
let is_price = $('#info span.pl:contains("定价")').length > 0;
let price = is_price ? ' ' + $('#info span.pl:contains("定价")')[0].nextSibling.textContent.match(/[\d.]+/) : '';
let isbn_anchor = $('#info span.pl:contains("ISBN")');
let isbn = isbn_anchor[0] ? fetch_anchor(isbn_anchor) : '';
let QMark = '"';
//复制的信息顺序:作者|译者|丛书|出品方|出版社|出版年|页数|定价
//做这个功能是为了一键复制信息粘贴到excel,可以根据自己的excel修改顺序和信息
var info_list = [writer, translator, series, producer, publisher, publishYear, page, price].map(function(item) {
return (item || '').toString().trim();
});
var info_export = info_list.join('\t');
var Movie_links = [
{ html: "BiliBili", href: "https://search.bilibili.com/pgc?keyword=" + title },
{ html: "皮皮虾", href: "https://ppxzy.net/?s=" + title },
{ html: "搜片", href: "https://soupian.pro/search?key=" + title },
{ html: "中国高清网", href: "https://gaoqing.la/?s=" + title },
];
var Book_read_links = [
//{ html: "", href: "" + title + " " + writer },
{ html: "Anna", href: "https://annas-archive.li/search?q=" + title + writer + "&ext=pdf&ext=epub&ext=mobi" },
{ html: "Z-Lib", href: "https://zh.z-library.rs/s/" + title + "?extensions[]=EPUB&extensions[]=PDF"},
{ html: "Kox.moe", href: "https://kox.moe/list.php?s=" + title },
{ html: "OceanofPDF", href: "https://oceanofpdf.com/?s=" + title },
{ html: "HathiTrust", href: "https://catalog.hathitrust.org/Search/Home?lookfor=" + title + "&searchtype=title&ft=ft&setft=true"},
{ html: "Gallica(法语)", href: "https://gallica.bnf.fr/services/engine/search/sru?operation=searchRetrieve&version=1.2&query=(gallica all " + QMark + title + "" + writer + QMark + ")"},
{ html: "全国新书目", href: "https://cnpub.com.cn/search.html#/quick?keyword=&checkedTypeList=%5B%22cip%22%5D&checkedClass=%5B%5D&filterbox=%5B%7B%22key%22%3A%22isbn%22,%22value%22%3A%22" + isbn + "%22,%22link%22%3A%22and%22,%22value1%22%3A%22%22,%22rule%22%3A%22like%22%7D%5D&priceStart=&priceEnd=&publishingStart=&publishingEnd=&createdateStart=&createdateEnd=&auditdateStart=&auditdateEnd=&zz=%5B%5D&ztc=%5B%5D&xglb=%5B%5D&xglbWord=%5B%5D&xglbAwardDate=%5B%5D&ca_textlangue=%5B%5D&jd_cate=%5B%5D&firstauthor=%5B%5D&ca_keyword=%5B%5D&searchType=cip&filter=%28%20%28%20isbn%20like%20%27" + isbn + "%27%20%29%20%29&type=cip,&gh=1&hs=1&pageNum=1&pageSize=10&firstbookname=&firstauthor1=&publisher1=&subjecttype1=&subjecttype2=&subjecttype1_1=&subjecttype2_1=&cate=%5B%5D&cate1=&jd_cate1=&zzz=%20&cbn=&publisher=%5B%5D&download=0&ids=&cbnStart=&cbnEnd=&noneStr=7e82a440e3fe44dfe4ac4f9ca1db226b&isbnl=&ca_isbookseries=0&stat=0&sort=&jd_cate1_2=&jd_cate1_1=&search=&jd_cate_index=%5B%5D"},
];
var Book_buy_links = [
{ html: "京东", href: "https://search.jd.com/Search?keyword=" + title + publisher },
{ html: "淘宝", href: "https://s.taobao.com/search?page=1&sort=price-asc&q=图书 " + title + publisher },
{ html: "当当", href: "https://search.dangdang.com/?key=" + title + publisher + "&show=big" },
{ html: "闲鱼", href: "https://www.goofish.com/search?q=" + title + writer },
//{ html: "拼多多", href: "https://mobile.yangkeduo.com/search_result.html?search_key=" + title + " " + writer },
{ html: "孔夫子", href: "https://search.kongfz.com/product_result/?order=100&ajaxdata=4&quality=90h&quaselect=2&key=" + title + publisher},
];
var copyButton = $('<button>点击复制</button>');
//$('body').append(copyButton);
var link = $("<div>").append(
$("<span>").attr("class", "pl").html("下载链接:")
);
switch(location.host){
case "book.douban.com":
appendLinks(Book_read_links, link)
link.append('<br>')
.append('<span class="pl">买买买:</span>')
appendLinks(Book_buy_links, link)
link.append('<br>')
.append('<span class="pl">复制信息:</span>')
.append(copyButton)
copyInfo(copyButton, info_export)
break;
case "movie.douban.com":
appendLinks(Movie_links, link)
break;
}
$('#info').append(link);
function appendLinks(items, appendTo){
items.forEach(function(item, i){
$("<a>")
.html(item.html)
.attr({
href: item.href,
target: "_blank"
})
.appendTo(appendTo);
if(i != items.length -1){
appendTo.append(" | ");
}
});
}
function addStyles() {
var styleExists = document.querySelector('style.toast-style');
if (!styleExists) {
var style = document.createElement('style');
style.className = 'toast-style'; // 给style标签添加一个类名以便识别
style.type = 'text/css';
style.innerHTML = `
.toast {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #333;
color: #fff;
padding: 10px;
border-radius: 5px;
opacity: 0.9;
z-index: 1000; /* 确保提示显示在最上层 */
width: auto; /* 自动宽度 */
text-align: center; /* 文本居中 */
white-space: nowrap; /* 防止文本换行 */
box-shadow: 0 4px 6px rgba(0,0,0,0.1); /* 添加阴影效果 */
}
`;
document.head.appendChild(style);
}
}
function copyInfo(nameButton, infoCont){
addStyles(); // 确保样式被添加
nameButton.click(function() {
navigator.clipboard.writeText(infoCont).then(function() {
// 创建提示元素
var toast = document.createElement('div');
toast.className = 'toast';
toast.textContent = '文本已复制到剪贴板';
document.body.appendChild(toast);
// 设置定时器,自动移除提示
setTimeout(function() {
toast.remove();
}, 2000);
}).catch(function(err) {
console.error('无法复制', err);
});
});
}
}
showLinks()