Skip to content

Instantly share code, notes, and snippets.

@IwakuraRein
Last active December 26, 2024 06:55
Show Gist options
  • Save IwakuraRein/a287988919899f1fdf938b18912efb48 to your computer and use it in GitHub Desktop.
Save IwakuraRein/a287988919899f1fdf938b18912efb48 to your computer and use it in GitHub Desktop.
Enhance Douban Book
// ==UserScript==
// @name 豆瓣读书增强
// @namespace https://github.com/IwakuraRein/
// @version 0.1
// @description 给豆瓣读书的页面添加转到其他数据库和电子书库的链接
// @author Iwakura Rein
// @match *://book.douban.com/subject/*
// @icon https://img3.doubanio.com/favicon.ico
// @grant none
// ==/UserScript==
(function() {
'use strict';
function getMetaHTML(value, valueName) {
var metas = document.getElementsByTagName('meta');
for (let i = 0; i < metas.length; i++) {
if (metas[i].getAttribute(value) === valueName) {
return metas[i].getAttribute(value).innerHTML;
}
}
return "";
}
function getISBN() {
var info = document.getElementById("info").innerHTML;
var re = new RegExp("<span class=\"pl\">ISBN:</span>.*?<br");
var isbn = info.match(re)[0];
isbn=isbn.replace("<span class=\"pl\">ISBN:</span> ", "").replace("<br", "");
return isbn;
}
function getAuthors() {
var info = document.getElementById("info").innerHTML;
var re = new RegExp('<span>[\\s\\S]*?<span class="pl"> 作者</span>:[\\s\\S]*?</span>');
var authors = info.match(re)[0];
authors = authors.match(/<a.*?>.*?<\/a>/g);
for (let i = 0; i < authors.length; i++) {
authors[i] = authors[i].replace(/<a.*?>/i, '').replace('</a>', '');
var nationality = authors[i].match(/\[.*?\] /i);
if (typeof nationality === 'undefined' || nationality == null || nationality === '') {
continue;
}
authors[i] = authors[i].replace(nationality[0], '');
}
return authors;
}
// var title = getMetaHTML("description", "content");
// var isbn = getMetaHTML("property", "book:isbn");
var info = document.getElementById('info').innerHTML;
var title = document.getElementsByTagName('title')[0].innerHTML.replace(" (豆瓣)", "");
var isbn = getISBN();
var authors = getAuthors();
for (let i = 0; i < authors.length; i++) {
var baike = authors[i]+'</a> <a href="https://zh.wikipedia.org/wiki/'+authors[i]+'" target="_blank">(维基百科)</a> <a href="https://baike.baidu.com/item/'+authors[i]+'" target="_blank">(百度百科)</a>';
document.getElementById('info').innerHTML = document.getElementById('info').innerHTML.replace(authors[i]+'</a>', baike);
}
var sideColumn = document.getElementsByClassName('aside')[0].innerHTML;
var newContent = "<h2>电子书库</h2><ul>";
newContent = newContent + '<li><a href="https://z-library.sk/s/'+title+'" target="_blank">在 zlibrary 搜索《'+title+'》</a></li>';
newContent = newContent + '<li><a href="https://www.pansoso.com/zh/'+title+'" target="_blank">在盘搜搜搜索《'+title+'》</a></li>';
newContent = newContent + '<li><a href="http://www.tuiliw.com/?s='+title+'" target="_blank">在推书搜索《'+title+'》</a></li>';
newContent = newContent + '<li><a href="https://pds.sslibrary.com/book/search?sw='+title+'" target="_blank">在超星汇雅搜索《'+title+'》</a></li>';
newContent = newContent + '<li><a href="https://mox.moe/list.php?s='+title+'" target="_blank">在 Mox.moe 搜索《'+title+'》</a></li>';
newContent = newContent + '<li><a href="https://www.jiumodiary.com/" target="_blank">在鸠摩搜索《'+title+'》</a><small> (需手动输入)</small></li>';
newContent = newContent + '<li><a href="https://www.99csw.com/book/search.php?type=站内&q='+title+'" target="_blank">在 99 藏书网搜索《'+title+'》</a></li>';
newContent = newContent + '<li><a href="http://book.ucdrs.superlib.net/search?Field=all&channel=search&sw='+title+'" target="_blank">在图盟搜索《'+title+'》</a></li>';
newContent = newContent + '</ul><hr><h2>其他数据库</h2><ul>';
newContent = newContent + '<li><a href="http://find.nlc.cn/search/doSearch?query='+title+'&actualQuery='+title+'" target="_blank">在文津搜索《'+title+'》</a></li>';
newContent = newContent + '<li><a href="https://www.google.com/search?tbm=bks&q='+title+'" target="_blank">在 Google 图书搜索《'+title+'》</a> (<a href="https://www.google.com/search?tbm=bks&q='+isbn+'" target="_blank">搜 ISBN</a>)</li>';
newContent = newContent + '<li><a href="https://www.worldcat.org/search?q='+title+'" target="_blank">在 WorldCat 搜索《'+title+'》</a> (<a href="https://www.worldcat.org/search?q=isbn%3A'+isbn+'" target="_blank">搜 ISBN</a>)</li>';
newContent = newContent + '<li><a href="https://openlibrary.org/search?q='+title+'" target="_blank">在 Open Library 搜索《'+title+'》</a> (<a href="https://openlibrary.org/search?isbn='+isbn+'" target="_blank">搜 ISBN</a>)</li>';
newContent = newContent + '</ul><hr><h2>搜二手</h2><ul>';
newContent = newContent + '<li><a href="https://www.duozhuayu.com/search/book/'+title+'" target="_blank">在多抓鱼搜索《'+title+'》</a></li>';
newContent = newContent + '<li><a href="https://search.kongfz.com/product_result/?key='+title+'" target="_blank">在孔夫子网搜索《'+title+'》</a></li>';
newContent = newContent + '</ul><hr>';
document.getElementsByClassName('aside')[0].innerHTML = newContent + sideColumn;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment