Greasy Fork

来自缓存

Greasy Fork is available in English.

豆瓣读书 Zlib 之间快捷跳转

Adds a hyperlink to the ISBN on Douban book pages to search on Zlib.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         豆瓣读书 Zlib 之间快捷跳转
// @namespace    http://tampermonkey.net/
// @version      0.1.5
// @description  Adds a hyperlink to the ISBN on Douban book pages to search on Zlib.
// @author       tianyw0
// @match        https://book.douban.com/subject/*
// @match        https://singlelogin.re/book/*
// @match        https://z-library.sk/book/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // 获取 ISBN 号
    function getDoubanISBN() {
        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 genZlibLink() {
        const isbn = getDoubanISBN();
        if (isbn) {
            const bookname = document.querySelector('span[property="v:itemreviewed"]').textContent;
            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://z-library.sk/s/${isbn + ' ' + bookname}`;
                        link.target = '_blank';
                        link.textContent = nextSpan.textContent;
                        span.insertAdjacentElement('afterend', link);
                        console.log(nextSpan);
                        nextSpan.remove();
                        break;
                    }
                }
            }
        }
    }
    window.addEventListener('load', genZlibLink);

    function genDoubanLink() {
        // 获取书籍标题
        const bookTitleElement = document.querySelector('h1[itemprop="name"]')
        const bookName = bookTitleElement.innerText.trim();
        if (bookTitleElement && bookName) {
            // 构建豆瓣搜索链接
            const doubanSearchUrl = `https://www.douban.com/search?cat=1001&source=suggest&q=${encodeURIComponent(bookName)}`;

            // 创建一个超链接元素
            const linkElement = document.createElement('a');
            linkElement.href = doubanSearchUrl;
            linkElement.target = '_blank'; // 在新标签页中打开链接
            linkElement.innerText = bookName;
            linkElement.className = 'douban-search-link'; // 添加CSS类

            // 替换原有的书籍标题元素
            bookTitleElement.innerHTML = '';
            bookTitleElement.appendChild(linkElement);

            // 添加CSS样式
            const style = document.createElement('style');
            style.textContent = `
                .douban-search-link {
                    color: #428bca; /* 设置超链接颜色 */
                    text-decoration: none; /* 去掉下划线 */
                }
                .douban-search-link:hover {
                    text-decoration: underline; /* 鼠标悬停时显示下划线 */
                }
            `;
            document.head.appendChild(style);
        }
    }
    window.addEventListener('load', genDoubanLink);
})();