Greasy Fork

Greasy Fork is available in English.

ZJUlib2douban

在ZJU图书馆书目详情页面右上角添加一个前往豆瓣该书页面的链接,仅限具有ISBN的书目。刚刚适配了早期没有978开头的ISBN。

当前为 2023-12-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         ZJUlib2douban
// @namespace    https://github.com/AlainAlan/ZJUlib2douban/tree/main
// @version      0.2
// @description  在ZJU图书馆书目详情页面右上角添加一个前往豆瓣该书页面的链接,仅限具有ISBN的书目。刚刚适配了早期没有978开头的ISBN。
// @author       AlainAllen
// @match        *://opac.zju.edu.cn/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=csdn.net
// @grant        GM_setClipboard
// @license MIT
// ==/UserScript==
(function() {
    'use strict';

    // Function to extract the last ISBN using regular expression
    function extractLastISBN() {
        // Regular expression for matching ISBN-10 and ISBN-13
        var isbnRegex = /ISBN(?:-1[03])?:?\s*(\d{0,3}-?\d{1,5}-?\d{1,7}-?\d{1,7}-?[\dX])/g;
        var bodyText = document.body.innerText;
        var isbnMatches = [...bodyText.matchAll(isbnRegex)];
        if (isbnMatches.length > 0) {
            // Get the last match
            var lastIsbnMatch = isbnMatches[isbnMatches.length - 1];
            var isbn = lastIsbnMatch[1]; // Capture group 1 contains the ISBN
            return isbn;
        } else {
            return null;
        }
    }

    // Function to create and append the link
    function appendLink(isbn) {
        if (isbn) {
            // Create the link element
            console.log(isbn);
            var header = document.getElementById('header');
            var link = document.createElement('a')
            var linkText = '豆瓣'; // Change this to your desired link text
            link.appendChild(document.createTextNode(linkText));
            link.title = linkText;
            link.className = 'smc';
            link.href = 'http://douban.com/isbn/' + isbn + '/'; // Change this to your desired URL structure

            // Append the link to the body or any other element of your choice
            header.appendChild(link);
        } else {
            console.log('ISBN not found. Cannot create link.');
        }
    }

    // Run the functions when the page loads
    window.addEventListener('load', function() {
        var isbn = extractLastISBN();
        appendLink(isbn);
    });
})();