// ==UserScript== // @name 豆瓣中图法分类 // @description 如果存在中图分类,则会在豆瓣信息栏中多显示如“中图分类: 中图分类: G442 (G 文化、 科学、 教育、 体育 ▸ G4 教育 ▸ G44 教育心理学 ▸ G442 学习心理学);学科分类参考: 880 教育学 | 880 教育学 | 88027 教育心理学”,方便对图书进行分类。 // @author 018(lyb018@gmail.com) // @contributor Rhilip // @connect * // @grant GM_xmlhttpRequest // @grant GM_setClipboard // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @grant GM_listValues // @grant GM_deleteValue // @grant GM_registerMenuCommand // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js // @require https://greasyfork.org/scripts/368137-encodeToGb2312/code/encodeToGb2312.js?version=601683 // @include https://book.douban.com/* // @version 0.2.2 // @icon https://img3.doubanio.com/favicon.ico // @run-at document-end // @namespace http://018.ai // @downloadURL none // ==/UserScript== // This Userscirpt can't run under Greasemonkey 4.x platform if (typeof GM_xmlhttpRequest === 'undefined') { alert('不支持Greasemonkey 4.x,请换用暴力猴或Tampermonkey') return } // 不属于豆瓣的页面 if (!/douban.com/.test(location.host)) { return } ;(function () { 'use strict'; $(document).ready(function () { // 分类 var info = $('#info'); if (info && info.length > 0) { var isbns = /ISBN: .*\n/.exec(info.eq(0).text()); if (isbns && isbns.length > 0) { var isbn = isbns[0].match(/\d+/g)[0].replace(/\n| /g, ''); var title = $('#wrapper h1').eq(0).text().replace(/\n| /g, ''); if( isbn && title ) { // superlib 搜索 requestSuperlib(isbn); } } } if (localStorage.getItem("IsticKeys") == '0') { $('div.indent div.intro').eq(0).after('
'); $('div.indent span.all div.intro').eq(0).after(''); $(".ShowKeys").click(function () { localStorage.setItem("IsticKeys", '1'); location.reload(); }); } else { // 关键字 let abstract = $('.indent .all .intro').eq(0).text(); if (!abstract || abstract.length <= 0) { abstract = $('.indent .intro').eq(0).text(); } // 目录 let id = getIDFromURL(location.href); let dir = $('#dir_' + id + '_full').text(); if (dir) { dir = dir.replace(/(([\xA0\s]*)\n([\xA0\s]*))+/g, '').replace('· · · · · · (收起)', ''); } let content = abstract + dir; if (content.length > 0) { requestIstic(content); } } }) function requestIstic(abstract) { let headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "Connection": "keep-alive", "Accept": "application/json, text/javascript, */*; q=0.01", "X-Requested-With": "XMLHttpRequest", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4229.0 Safari/537.36", "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "Origin": "https://ct.istic.ac.cn", "Sec-Fetch-Site": "same-origin", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Dest": "empty", "Referer": "https://ct.istic.ac.cn/site/term/participle", "Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7", "Cookie": "name=value" } doPost('https://ct.istic.ac.cn/site/term/ceshihjson', headers, 'id=lyb018' + new Date().getTime() + '&inputText=' + encodeURIComponent(abstract), {}, function(json, responseDetail, meta) { if (json && json.t1 && json.t1.length > 0) { // 最多取五个 let keys = []; json.t1.sort(function (a, b) { return b.frequency - a.frequency; }); for (let i = 0; i < json.t1.length; i++ ) { let work = json.t1[i].word.trim(); if(work.length == 0 || ['第', '部分', '章', '●', 'Chapter', '-', '#', '附录'].includes(work)) continue; keys.push('' + json.t1[i].word + '(' + json.t1[i].frequency + ')' + ''); replaceKey(json.t1[i].word); if (keys.length >= 5) break; } $('div.indent div.intro').eq(0).after('关键字: ' + keys.join(' | ') + ' (隐藏)
'); $('div.indent span.all div.intro').eq(0).after('关键字: ' + keys.join(' | ') + ' (隐藏)
'); $(".hideKeys").click(function () { localStorage.setItem("IsticKeys", '0'); $('.IsticKeys').hide(); location.reload(); }); } }, function(err, meta) { }); } function replaceKey(work) { for (let e of $('div.indent div.intro p')) { if (!e.querySelector('a')) { $(e).html($(e).html().replace(eval('/' + work + '/g'), '' + work + '')); } } } // 请求图书馆联盟 function requestSuperlib(isbn) { loadDoc('http://book.ucdrs.superlib.net/search?Field=all&channel=search&sw=' + isbn, {isbn: isbn}, function(doc, responseDetail, meta) { let found = false; let books = doc.querySelectorAll('.book1'); if (books.length <= 0) { $('#info').append('中图分类: 查无此信息'); return; } for (let book of books) { if (found) break; let a = book.querySelector('.book1 td>table a.px14');// if (a) { // superlib 单本书籍查看 let url = a.href.replace(location.host, 'book.ucdrs.superlib.net').replace('https', 'http'); loadDoc(url, {isbn: meta.isbn}, function(doc1, responseDetail1, meta1) { let tubox = doc1.querySelector('.tubox dl').textContent; let isbn1 = opt(/【ISBN号】.*\n/.exec(tubox)).replace(/【ISBN号】|-|\n/g, ''); if (eqisbn(meta1.isbn, isbn1)) { let clc = opt(opt(/【中图法分类号】.*\n/.exec(tubox)).match(/[a-zA-Z0-9\.]+/)); if (clc) { found = $("#clcText").length > 0; if (!found) { $('#info').append('中图分类: ' + clc + ' (...)