// ==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.9 // @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 // @author morningSky // @refer books_recommend_THU, bean vine (49911) and others... // @updateDate 2017-11-03 /* @reason 1. 深圳图书馆站点启用https 2. 深圳图书馆提供快递送书上门服务,显示快递送书按钮 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; var SZLIB_HOST = 'http://www.szlib.org.cn/'; var LIBOPAC_URL = SZLIB_HOST + 'Search/searchshow.jsp?v_tablearray=bibliosm,serbibm,apabibibm,mmbibm,&v_book=on&sortfield=score&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=score&v_value='; var HTML_LOADING = '正在查询图书馆馆藏情况 · · · · · · '; var LIBSEARCH_LINK_PRE = '在豆瓣搜索'; } function getLibHeadHtml() { var htmlStr = '
条码号 | 索书号 | 所在地点 |
04400511016054 | K825.4/1023 | 深图中文图书借阅区(3楼) |
索 书 号 | 馆藏地点 | ' + '|
.*?<\/td><\/tr>/igm); //libLocs[i].match(/ | ||
[0-9]+.*?<\/td><\/tr>/igm); if (fDebug) console.log('shelfLocs: ' + shelfLocs + ', len: ' + shelfLocs.length); var callNoArr = new Array(); for (var j = 0; j < shelfLocs.length; j++) { // extract the 索书号, 馆内位置 try{ var shelfLocArr = shelfLocs[j].match(/ | .*?<\/td>/igm); var callNoStr = shelfLocArr[1]; var shelfLocStr = shelfLocArr[2]; // 4 = " | ".length, 5 = " | ".length callNoStr = callNoStr.substring(4, callNoStr.length-5); shelfLocStr = shelfLocStr.substring(4, shelfLocStr.length-5).trim(); if (fDebug) console.log('callNo : ' + callNoStr + ', loc: ' + shelfLocStr); // 索 书 号+馆藏地点 相同的不重复显示 if (callNoArr.indexOf(callNoStr + shelfLocStr) == -1) { callNoArr.push(callNoStr + shelfLocStr); htmlStr += '
' + callNoStr + ' | '; htmlStr += shelfLocStr + ' |
' + LIBSEARCH_LINK_PRE + ' href="' + getLibTitleUrl(keyword) + '" >> '+ LIBSEARCH_LINK_SUF + '
'; $(".aside h2:last").before(htmlStr); } function appendDoubanInSearchPage() { try { var keyword = $("span.fbold").text(); if (isEmptyStr(keyword)) return ; if (fDebug) console.log('keyword: [' + keyword + ']'); var rsltSearchBtn = $("div.books_sel input:last"); if (fDebug) console.log('find search in result button'); var dbSearchBtn = rsltSearchBtn.clone(); var dbSearchUrl = getDoubanSearchUrl(keyword); if (fDebug) console.log('copy it, new dbSearchBtn, dbSearchUrl: ' + dbSearchUrl); dbSearchBtn.attr('value','在豆瓣搜索'); dbSearchBtn.attr('onclick', null); dbSearchBtn.click(function() {window.open(dbSearchUrl);}); if (fDebug) console.log('created douban search button'); $("div.books_sel").append(dbSearchBtn); } catch(ex) { console.log('In Library search page, exception: ' + ex.message); console.log('In Library search page, cannot find keyword, page struct may changed'); } } function appendListBooksLibLink() { // eg, book.douban.com/doulist/232705/ (div.pl2 a), // book.douban.com/doulist/531890/ (div.title a), var fChecked = false; $('div.article table').each(function(){ var keyword = ''; if (!fChecked) { fChecked = true; GM_addStyle(".libSearch{\ float:left;display: inline-block;\ background: #eef9eb;border: 1px solid #2F7B4B;\ padding: 1px 10px;border-radius:3px;margin-right: 8px;}\ "); if (fDebug) console.log(' tag/doulist 1: fChecked[' + fChecked + '] '); } keyword = $('div.pl2 a', this).text(); if (isEmptyStr(keyword)) return ; keyword = keyword.trim(); if (fDebug) console.log(' tag/doulist page: [' + keyword + ']'); var htmlStr = LIBSEARCH_LINK_PRE + ' class="libSearch" href="' + getLibTitleUrl(keyword) + '" >' + LIBSEARCH_LINK_SUF; $('td > span.rr', this).append(htmlStr); }); } function appendTagBooksLibLink() { // eg, book.douban.com/tag/web , book.douban.com/people/qibadao/collect // book.douban.com/chart $('div.article ul li').each(function(){ var keyword = ''; keyword = $('h2 a', this).text(); if (isEmptyStr(keyword)) return ; keyword = keyword.trim(); if (fDebug) console.log(' tag page: [' + keyword + ']'); var htmlStr = LIBSEARCH_LINK_PRE + ' class="j a_add2cart add2cart" href="' + getLibTitleUrl(keyword) + '">' + LIBSEARCH_LINK_SUF; $('span.cart-info span', this).first().append(htmlStr); }); } (function() { var thisScript = { name: "douban_shenzhenLib", id: "116332", version:"1.24.9" }; if (typeof(Updater)!='undefined') { var updater = new Updater(thisScript); updater.check(24); } if (fDebug) console.log('url host:' + document.URL); var vUrl = document.URL; if (vUrl.indexOf("douban.com/subject/") > 0) { if (fDebug) console.log('in douban page'); appendLibraryLink(); } else if (vUrl.indexOf("douban.com/subject_search") > 0) { appendLibraryInSearchPage(); } else if (vUrl.indexOf("/Search/searchdetail.jsp") > 0) { if (fDebug) console.log('in shenzhen library page'); appendDoubanLink(); } else if (vUrl.indexOf("/Search/searchshow.jsp") > 0) { appendDoubanInSearchPage(); } else if(vUrl.indexOf('/top250') > 0 || vUrl.indexOf('/doulist/') > 0) { appendListBooksLibLink(); } else if (vUrl.indexOf('/tag/') > 0 || /\/people\/.+\/collect/.test(vUrl) || /\/chart(.*)$/.test(vUrl)) { appendTagBooksLibLink(); } })();