Douban Book HUST Helper

豆瓣读书添加HUST图书馆信息 1.01 修改了显示位置,让借书信息可以正常显示

当前为 2021-09-28 提交的版本,查看 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Douban Book HUST Helper
// @description 豆瓣读书添加HUST图书馆信息 1.01 修改了显示位置,让借书信息可以正常显示
// @author      lastmayday & ab00b
// @namespace   http://lastmayday.org
// @include     https://book.douban.com/*
// @require     https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @version     1.0.1
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// @grant GM_openInTab
// @grant GM_deleteValue
// @grant GM_addStyle
// @grant GM_registerMenuCommand
// @icon        http://douban.com/favicon.ico
// ==/UserScript==
/* global $, jQuery */
function insertInfo() {
  if ($('#dale_book_subject_top_middle').length) {
    $('#dale_book_subject_top_middle').before('<div class="clearfix" id="hustlib"></div>');
    $('#hustlib').append('<h2>华科图书馆有没有?</h2><div class="bs" id="isex"></div>');
    if (typeof($('#info').text().split('ISBN:')[1]) != 'undefined') {
      let isbn = $('#info').text().split('ISBN:')[1].split(' ')[1];
      let url = 'https://ftp.lib.hust.edu.cn/search~S0*chx/?searchtype=i&searcharg=+' + isbn;
      GM_xmlhttpRequest({
        url: url,
        method: 'GET',
        onload: function(msg) {
          let text = msg.responseText;
          if (text.indexOf('未找到符合查询条件的馆藏') !== -1) {
            $('#isex').html('我科快去买书啦~竟然没有!');
          } else {
            $('#isex').html('我科的图书馆当然有!');
            $('#isex').after('<br><h2>在哪里在哪里?</h2>');
            $(text).find(".bibOrderEntry").appendTo('#hustlib');
            $(text).find('.bibItems').appendTo('#hustlib');
            $('#hustlib').append('<br><h2>再具体点?</h2><p><div class="bs" id="mdt"><a href="' + url + '" target="_blank">戳这里~</a></div>');
            for (let i = 1; i <= $('#hustlib tr').length - 1; i++) {
              let booknum = $('#hustlib tr').eq(i).find('td').eq(1).text();
              $('#hustlib tr').eq(i).find('td').eq(1).remove();
              $('#hustlib tr').eq(i).find('td').eq(0).after('<td width="43%">' + booknum + '</td>');
            }
          }
        }
      });
    } else {
      $('#isex').html('竟然没有!');
    }
  }
}
insertInfo();