Last active
December 14, 2015 10:49
-
-
Save holys/5074554 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name GDUFS library helper | |
// @namespace http://library.gdufs.edu.cn | |
// @version 0.1.0 | |
// @description Show the available books amount in GDUFS library. | |
// @match http://book.douban.com/* | |
// @match http://opac.gdufs.edu.cn:8118/apsm/recommend/recommend_nobor.jsp* | |
// @copyright 2012-2013, Link, hbc,cdh(later) | |
// @require http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js | |
// @require http://isbn.jpn.org/js/isbn.js | |
// @require http://isbn.jpn.org/js/isbn-groups.js | |
// ==/UserScript== | |
// @grant GM_xmlhttpRequest | |
var helper = { | |
pages: { | |
subject: {}, | |
subject_search: {} | |
}, | |
utils: {}, | |
tpl: {}, | |
parser: {}, | |
main: {} | |
}; | |
/*utils*/ | |
// parser | |
helper.parser.book_meta = function (raw){ | |
var author = $('#info a ', raw).html(); | |
if (author !== null){ | |
author = author.trim(); | |
} | |
var publisher = /出版社: (.*)/.exec($('#info', raw).text()); | |
if (publisher !== null){ | |
publisher = publisher[1].trim(); | |
} | |
var pubdate = /出版年: (.*)/.exec($('#info', raw).text()); | |
if (pubdate !== null){ | |
pubdate = /[\d]+/.exec(pubdate[1].trim()); | |
pubdate = pubdate[0]; | |
} | |
var price = /定价: (.*)/.exec($('#info', raw).text()); | |
if (price !== null){ | |
price = price[1].trim(); | |
} | |
var isbn = /ISBN: (.*)/.exec($('#info', raw).text()); | |
if (isbn !== null){ | |
isbn = isbn[1].trim(); | |
} | |
console.log('book_meta begin to work'); | |
return{ | |
title: $('h1 span', raw).html(), | |
author: author, | |
publisher: publisher, | |
pubdate: pubdate, | |
price: price, | |
isbn: isbn | |
}; | |
}; | |
// recommend buying books | |
helper.pages.recommend = function (){ | |
var book = /douban_ref=(.*)+/.exec(document.URL); | |
if(!book){ | |
return; | |
} | |
GM_xmlhttpRequest({ | |
method: 'GET', | |
url: book[1], | |
onload: function(resp){ | |
var book_meta; | |
if (resp.status !== 200){ | |
return; | |
} | |
// console.log(resp.status); | |
book_meta = helper.parser.book_meta( | |
$(resp.response).filter('div#wrapper') | |
); | |
// console.log($(resp.response).filter('div#wrapper')); | |
$('[name="Z13_TITLE"]').val (book_meta.title); | |
$('[name="Z13_AUTHOR"]').val(book_meta.author); | |
console.log(book_meta.author); | |
$('[name="Z13_IMPRINT"]').val(book_meta.publisher); | |
$('[name="Z13_YEAR"]').val( book_meta.pubdate); | |
$('[name="Z13_ISBN_ISSN"]').val (book_meta.isbn); | |
$('[name="Z13_PRICE"]').val (book_meta.price); | |
} | |
}); | |
}; | |
helper.main = function() { | |
var type = /[com,8118]\/([\w]+)\/*/.exec(document.URL); | |
type = (type !== null)?(type[1].trim()):('index'); | |
if(type==='subject') { | |
helper.pages.subject(); | |
}else if(type==='subject_search') { | |
helper.pages.subject_search(); | |
}else if(type==='apsm') { | |
helper.pages.recommend(); | |
}else { | |
console.log(type); | |
} | |
}; | |
helper.main(); |
Author
holys
commented
Mar 7, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment