// ==UserScript== // @name 豆瓣读书(Douban)跳转到Zlib搜索 // @namespace http://tampermonkey.net/ // @version 0.1.1 // @description Adds a hyperlink to the ISBN on Douban book pages to search on Zlib. // @author tianyw0 // @match https://book.douban.com/subject/* // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 获取 ISBN 号 function getISBN() { const infoDiv = document.querySelector('#info'); if (infoDiv) { const infoText = infoDiv.textContent; const isbnRegex = /ISBN:\s*(\d{13}|\d{10})/i; const match = infoText.match(isbnRegex); if (match) { return match[1].trim(); } } return null; } // 将 ISBN 改成超链接 function convertISBNToLink() { const isbn = getISBN(); const bookname = document.querySelector('span[property="v:itemreviewed"]').textContent; if (isbn && bookname) { const infoDiv = document.querySelector('#info'); const spans = infoDiv.querySelectorAll('span.pl'); for (let span of spans) { if (span.textContent.trim() === 'ISBN:') { const nextSpan = span.nextSibling; if (nextSpan) { const link = document.createElement('a'); link.href = `https://singlelogin.re/s/${isbn + ' ' + bookname}`; link.target = '_blank'; link.textContent = nextSpan.textContent; span.insertAdjacentElement('afterend', link); console.log(nextSpan); nextSpan.remove(); break; } } } } } // 页面加载完成后转换 ISBN 为超链接 window.addEventListener('load', convertISBNToLink); })();