// ==UserScript== // @name douban_shenzhenLib // @name:zh-CN 深圳图书馆图书信息豆瓣脚本 // @namespace http://www.douban.com/note/180166013/ // @description Show book available info in douban book page, show book's douban score in Shenzhen Library book page // @description:zh-cn 为豆瓣书籍页面(book.douban.com)添加书籍在深圳图书馆的信息,预借链接,为深圳图书馆书籍信息页面添加书籍在豆瓣的评分,链接 // @license MIT License // @supportURL http://www.douban.com/note/180166013/ // @version 1.24.10 // @require http://code.jquery.com/jquery-1.4.4.min.js // @include http://book.douban.com/* // @include https://book.douban.com/* // @include https://www.douban.com/doulist/* // @include https://www.szlib.org.cn/Search/searchdetail.jsp* // @include https://www.szlib.org.cn/Search/searchshow.jsp* // @include http://opac.nslib.cn/Search/searchdetail.jsp* // @include http://opac.nslib.cn/Search/searchshow.jsp* // @include https://www.szln.gov.cn/Search/searchdetail.jsp* // @include https://www.szln.gov.cn/Search/searchshow.jsp* // @include http://218.17.147.50/Search/searchdetail.jsp* // @include http://218.17.147.50/Search/searchshow.jsp* // @grant GM_addStyle // @grant GM_xmlhttpRequest // @grant GM_registerMenuCommand // @grant GM_getValue // @grant GM_setValue // @author morningSky // @refer books_recommend_THU, bean vine (49911) and others... // @updateDate 2019-03-25 /* @reason 1. 深圳图书馆查询url变更, sortfield=ptitle 2. 减少加载时间:缓存图书的索书号,是否有多本,可预借,可快递。在馆信息还是需要查询图书馆网站 3. 豆瓣api只对企业开放,个人用户不提供key,修改为在html中解析isbn10 Firefox Greasemonkey v4.0及之后版本修改了API,这个脚本失效了;请用tampermonkey插件,需要再次安装这个脚本。 争取找时间修改脚本,使其适用于新版的Greasemonkey插件————可能tampermonkey插件后续也会修改API,导致脚本失效。 @end*/ // // @downloadURL none // ==/UserScript== /* * opac.nslib.cn 南山,szln.gov.cn 盐田,218.17.147.50 龙岗 */ var fDebug = false; var title, isbn, isbn10; var SZLIB_HOST = 'https://www.szlib.org.cn/'; var LIBOPAC_URL = SZLIB_HOST + 'Search/searchshow.jsp?v_tablearray=bibliosm,serbibm,apabibibm,mmbibm,&v_book=on&sortfield=ptitle&sorttype=desc&pageNum=10'; // 查询索书号 var LIBOPAC_URL_CALLNO = SZLIB_HOST + 'Search/getpreholding.jsp?v_curtable=bibliosm&v_recno='; var LIBBOOK_URL = SZLIB_HOST + 'Search/searchdetail.jsp?v_tablearray=bibliosm&v_curtable=bibliosm&site=null&v_recno='; var LIBQRYRESERVABLE_URL = SZLIB_HOST + 'Search/getpreLoan.jsp?'; var LIBRESERVE_URL = SZLIB_HOST + 'MyLibrary/Reader-Access.jsp?destPage=ReserveSubmit.jsp&v_tablearray=bibliosm&v_TableName=80000002&v_recno='; var LIB_EXPRESS_URL = SZLIB_HOST + 'MyLibrary/Reader-Access.jsp?destPage=/Search/searchshow.jsp?v_index=isbn&v_tablearray=bibliosm,&sorttype=desc&sortfield=ptitle&v_value='; var HTML_LOADING = '正在查询图书馆馆藏情况 · · · · · · '; var LIBSEARCH_LINK_PRE = '在豆瓣搜索'; } function getLibHeadHtml() { var htmlStr = ''; return htmlStr; } function setLibMemberStyle() { GM_addStyle('\ #libInfo {\ overflow: visible;\ }\ .libMem {\ z-index: 97;\ position: relative;\ float: right;\ }\ .libMemMenu {\ position: absolute;\ top: -5px;\ left: 0px;\ visibility: hidden;\ }\ .libMem a {\ -moz-border-radius: 7px;\ -webkit-border-radius: 7px;\ border-radius: 7px;\ display: block;\ background: #f6f6f1;\ padding: 5px;\ width: 90px;\ line-height: 160%;\ border: 1px solid #fff;\ }\ .libMem a:hover {\ background: #FFF;\ border: 1px solid #aaa;\ color: #000;\ }\ .libMem:hover .libMemMenu {\ visibility: visible;\ }\ .libMem .libMemLink {\ border: 1px solid #aaa;\ line-height: 100%;\ width: 90px;\ }\ '); } // getpreLoan.jsp?tableList=bibliosm,bibliosm,bibliosm,&metaidList=934991,1209378,698561, function getReservableQryUrl(bookRecNos) { var qryParam = 'tableList='; for (var i = 0; i < bookRecNos.length; i++) { qryParam += 'bibliosm,'; } // array.toString: arr[0],arr[1],... qryParam += '&metaidList=' + bookRecNos + ','; if (fDebug) console.log('Reservable qryUrl: ' + LIBQRYRESERVABLE_URL + qryParam); return LIBQRYRESERVABLE_URL + qryParam; } /* * Append the book link, search link, preserve link, call no with location info * * @param bookRecNos is an Array * The reservable query return a xml: * truefalse */ function appendLibBookInfo(bookRecNos) { if (bookRecNos == null || bookRecNos.length == 0) return ; var fMore = (bookRecNos.length > 1); var bookRecNo = bookRecNos[0];// set the first book as default var reservableQry_url = getReservableQryUrl(bookRecNos); GM_xmlhttpRequest({ method: 'GET', url: reservableQry_url, headers: { 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey', "Accept": "text/xml" }, onload: function(res) { // the reservable query return is a xml document var fHasReservable = false; if (fDebug) console.log('preloan xml: ' + res.responseText); var xmldata = new DOMParser().parseFromString(res.responseText, "text/xml"); if (fDebug) console.log('preloan xml: ' + xmldata); var preloans = xmldata.getElementsByTagName('preloan'); for (var i = 0; i < preloans.length;i++) { if (fDebug) console.log('preloan : ' + i + ', ' + preloans[i].childNodes[0].nodeValue); if (preloans[i].childNodes[0].nodeValue == 'true') { bookRecNo = bookRecNos[i]; fHasReservable = true; break; } } var fHasExpress = false; var exps = xmldata.getElementsByTagName('express'); for (var j = 0; j < exps.length; j++) { if (exps[j].childNodes[0].nodeValue == 'true') { fHasExpress = true; break; } } var cacheInfo = '{"bookRecNo":"' + bookRecNo + '", "hasMore":"'+ fMore + '", "reservable":"' + fHasReservable + '", "expressable":"' + fHasExpress + '"}'; GM_setValue(isbn, cacheInfo); appendLibBookHtml(bookRecNo, fMore, fHasReservable, fHasExpress); } // end function(res) } ); } // end appendLibBookInfo function appendLibBookHtml(bookRecNo, fMore, fHasReservable, fHasExpress) { if (fDebug) console.log('book recNo: ' + bookRecNo + ', fHasReservable: ' + fHasReservable + ', fHasExpress:' + fHasExpress); var book_url = LIBBOOK_URL + bookRecNo; var htmlStr = ''; htmlStr += '