Douban eBooks Finder

search the book on your preferred ebook platforms with just one click

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Douban eBooks Finder
// @version      1.13
// @description  search the book on your preferred ebook platforms with just one click
// @author       limpido
// @license      MIT License
// @match        https://book.douban.com/subject/*
// @namespace
// @namespace https://github.com/caspartse/eBooksAssistant
// ==/UserScript==

const platforms = [
    {
        title: "zlib (singlelogin.re)",
        urlPrefix: "https://singlelogin.re/s/?q="
    },
    {
        title: "zlib (z-library.sk)",
        urlPrefix: "https://z-library.sk/s/"
    },
    {
        title: "zlib (z-lib.gs)",
        urlPrefix: "https://z-lib.gs/s/"
    },
    {
        title: "Anna's Archive",
        urlPrefix: "https://annas-archive.org/search?q="
    }
]

const aside = document.querySelector(".aside");

if (aside) {
    bookTitle = document.querySelector("h1 > span").textContent;

    bookSubtitle = null;
    infoSpans = document.querySelectorAll("div#info > span");
    for (const span of infoSpans) {
        if (span.textContent === "副标题:") {
            bookSubtitle = span.nextSibling.textContent.trim();
        }
    }

    const ebookLinks = document.createElement("div");
    ebookLinks.id = "ebook_links";
    ebookLinks.style.padding = "18px 16px";
    ebookLinks.style.margin = "0 0 20px 0";
    ebookLinks.style.background = "#f6f6f2";

    const sectionTitle = document.createElement("h2");
    const sectionTitleSpan = document.createElement("span");
    sectionTitleSpan.textContent = "搜索电子版";
    sectionTitle.appendChild(sectionTitleSpan);
    sectionTitle.innerHTML += `  · · · · · ·`;
    ebookLinks.appendChild(sectionTitle);

    ul = document.createElement("ul");
    for (const platform of platforms) {
        li = document.createElement("li");
        li.style.borderBottom = "1px solid rgba(0,0,0,.08)";
        li.style.padding = "12px 0";
        a = document.createElement("a");
        a.textContent = platform.title;
        a.href = `${platform.urlPrefix}${bookTitle}${bookSubtitle ? "+" + bookSubtitle : ""}`;
        li.appendChild(a);
        ul.appendChild(li);
    }
    
    ebookLinks.appendChild(ul);
    aside.insertAdjacentElement("afterbegin", ebookLinks);
} else {
    console.log("aside element not found!");
}