(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;otr', $content); isAvailable = function(col) { return ($('td:nth(5)', col)).text().trim() === '可供出借'; }; bookInfos = { remains: ((function() { var _i, _len, _results; _results = []; for (_i = 0, _len = $books.length; _i < _len; _i++) { book = $books[_i]; if (isAvailable(book)) { _results.push(book); } } return _results; })()).length, total: $books.length }; return bookInfos; }, parseQueryResult: function($content) { var $cols, bookInfos, ctrlno, getColText, i; $cols = (function() { var _i, _len, _ref, _results; _ref = $content.children; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { i = _ref[_i]; _results.push($(i)); } return _results; })(); if ($cols.length < 9) { return; } getColText = function(idx) { return $cols[idx].text().trim(); }; ctrlno = $('input', $cols[0]).attr('value').trim(); bookInfos = { title: getColText(1), ctrlno: ctrlno, author: getColText(2), publisher: getColText(3), location: getColText(5), url: templates.bookUrl(ctrlno), remains: parseInt(getColText(7), 10), total: parseInt(getColText(6), 10) }; return bookInfos; }, parseQueryResults: function(rawContent) { var $page, content, result; content = utils.clean(rawContent); $page = function(selector) { return $(selector, content); }; if ($page('#searchnotfound').length !== 0) { return; } return (function() { var _i, _len, _ref, _results; _ref = $page('tbody tr'); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { result = _ref[_i]; _results.push(query.parseQueryResult(result)); } return _results; })(); }, parseDoubanReference: function() { var bookId; bookId = /douban_ref=(.*)/.exec(document.URL); if (bookId) { return bookId[1]; } } }; },{"../templates":16,"../utils":18}],11:[function(require,module,exports){ var parser, templates, utils; utils = require('../utils'); parser = (require('../parser')).douban; templates = (require('../templates')).douban; module.exports = { queryItem: function(bookId) { var dfd; dfd = new $.Deferred; GM_xmlhttpRequest({ method: 'GET', url: templates.queryItem(bookId), onload: function(resp) { var bookMeta, content; if (resp.status !== 200) { dfd.resolve; return; } content = utils.clean(resp.responseText); bookMeta = parser.parseBookItemPage($(content).filter('div#wrapper')); return dfd.reject(bookMeta); } }); return dfd.promise(); } }; },{"../parser":9,"../templates":16,"../utils":18}],12:[function(require,module,exports){ module.exports = { douban: require('./douban'), library: require('./library'), local: require('./local') }; },{"./douban":11,"./library":13,"./local":14}],13:[function(require,module,exports){ var alwaysFailFilter, alwaysSuccessFilter, parser, publisherFilterFactory, queryFactory, templates, utils; parser = (require('../parser')).library; templates = (require('../templates')).library; utils = require('../utils'); queryFactory = function(queryUrlBuilder, filter, respParser) { if (respParser == null) { respParser = null; } if (!respParser) { respParser = parser.parseQueryResults; } return function(queryValue) { var dfd, queryUrl; dfd = new $.Deferred; queryUrl = queryUrlBuilder(queryValue); GM_xmlhttpRequest({ method: 'GET', url: queryUrl, onload: function(resp) { var parsedResults, result; parsedResults = respParser(resp.responseText); if (!parsedResults) { dfd.resolve(parsedResults); return; } result = filter(queryValue, parsedResults); if (result) { return dfd.reject(result); } else { return dfd.resolve({ queryUrl: queryUrl, results: parsedResults }); } } }); return dfd.promise(); }; }; publisherFilterFactory = function(bookMeta) { return function(value, results) { var result, _i, _len; for (_i = 0, _len = results.length; _i < _len; _i++) { result = results[_i]; if (result.publisher === bookMeta.publisher) { return result; } } return null; }; }; alwaysSuccessFilter = function(base, candidate) { return candidate; }; alwaysFailFilter = function() { return null; }; module.exports = { keyword: function(keyword) { var dfd, keywordQuery; dfd = new $.Deferred; keywordQuery = queryFactory(templates.queryKeywordURLBuilder, alwaysFailFilter); utils.convertGB2312(keyword).then(keywordQuery).always(dfd.resolve); return dfd.promise(); }, title: function(bookMeta) { var dfd, titleQuery; dfd = new $.Deferred; titleQuery = queryFactory(templates.queryTitleURLBuilder, publisherFilterFactory(bookMeta)); utils.convertGB2312(bookMeta.title).then(titleQuery).then(dfd.resolve).fail(dfd.reject); return dfd.promise(); }, isbn: function(bookMeta) { var dfd, isbnQuery; dfd = new $.Deferred; isbnQuery = queryFactory(templates.queryISBNURLBuilder, publisherFilterFactory(bookMeta)); isbnQuery(bookMeta.isbn10).then(function() { return isbnQuery(bookMeta.isbn13); }).then(dfd.resolve).fail(dfd.reject); return dfd.promise(); }, ctrlNo: function(bookMeta) { var ctrlNoQuery, dfd, mergeCollection; dfd = new $.Deferred; if (!bookMeta.ctrlno) { dfd.reject(bookMeta); } ctrlNoQuery = queryFactory(templates.queryCtrlNoURLBuilder, alwaysSuccessFilter, parser.parseBookInfo); mergeCollection = function(bookColl) { return $.extend({}, bookMeta, bookColl); }; ctrlNoQuery(bookMeta.ctrlno).then(function() { return dfd.resolve(bookMeta); }).fail(function(bookColl) { return dfd.reject(mergeCollection(bookColl)); }); return dfd.promise(); } }; },{"../parser":9,"../templates":16,"../utils":18}],14:[function(require,module,exports){ var config, utils; utils = require('../utils'); config = require('../config'); module.exports = { bookId: function(id) { var bookInfos, dfd; dfd = new $.Deferred; bookInfos = utils.cache.read(id); if (bookInfos === null) { utils.errLog("" + id + " not found from cache."); dfd.resolve(bookInfos); } else { if (bookInfos._viewTimes == null) { bookInfos._viewTimes = 0; } if (bookInfos._viewTimes > config.localCacheLife) { utils.errLog("" + id + " hits too many times from cache, throw it."); dfd.resolve(bookInfos); } else { utils.log("Found " + id + " from cache."); dfd.reject(bookInfos); } } return dfd.promise(); } }; },{"../config":1,"../utils":18}],15:[function(require,module,exports){ var libraryTmpl; libraryTmpl = require('./library'); module.exports = { subject: { bookInfos: function(infos) { return "GDUT: \n还剩 " + infos.remains + " 本\n
\n在 " + infos.location; }, notFound: function(infos) { var recommendUrl; recommendUrl = libraryTmpl.recommendUrl(infos); return "GDUT: \n没有找到噢,去荐购"; }, foundMultiple: function(infos) { return "GDUT: \n找到 " + infos.results.length + " 本类似的"; } }, subjectSearch: { result: function(infos) { return "
\n
\n

在广工图书馆 · · ·

\n
\n \n
"; }, notFound: function() { return "
\n
\n

在广工图书馆 · · ·

\n
\n
\n

没有找到噢

\n
\n
"; } }, douList: { bookInfos: function(infos) { return "
\nGDUT: 还剩 " + infos.remains + " 本\n
\n地点: 在 " + infos.location; } }, queryItem: function(bookId) { return "http://book.douban.com/subject/" + bookId + "/"; } }; },{"./library":17}],16:[function(require,module,exports){ module.exports = { library: require('./library'), douban: require('./douban') }; },{"./douban":15,"./library":17}],17:[function(require,module,exports){ var config; config = require('../config'); module.exports = { queryCtrlNoURLBuilder: function(ctrlNo) { return "" + config.libraryBaseUrl + "/bookinfo.aspx?ctrlno=" + ctrlNo; }, queryISBNURLBuilder: function(isbn) { return "" + config.libraryBaseUrl + "/searchresult.aspx?dp=50&isbn_f=" + isbn; }, queryTitleURLBuilder: function(title) { return "" + config.libraryBaseUrl + "/searchresult.aspx?dp=50&title=" + title; }, queryKeywordURLBuilder: function(keyword) { return "" + config.libraryBaseUrl + "/searchresult.aspx?dp=50&anywords=" + keyword; }, bookUrl: function(ctrlno) { return "" + config.libraryBaseUrl + "/bookinfo.aspx?ctrlno=" + ctrlno; }, recommendUrl: function(infos) { return "" + config.libraryBaseUrl + "/readerrecommend.aspx?douban_ref=" + infos.id; } }; },{"../config":1}],18:[function(require,module,exports){ var config, utils; config = require('./config'); module.exports = utils = { log: function(something) { return console.log(something); }, errLog: function(something) { return console.error(something); }, convertISBN: function(isbn, length) { var parsedISBN; parsedISBN = ISBN.parse(isbn); switch (length) { case 10: return parsedISBN.asIsbn10(true); case 13: return parsedISBN.asIsbn13(true); } }, convertGB2312: function(keyword) { var dfd, encodedKeyword; dfd = new $.Deferred; encodedKeyword = encodeURIComponent(keyword); GM_xmlhttpRequest({ method: 'GET', url: "http://www.baidu.com/s?ie=utf-8&wd=" + encodedKeyword, overrideMimeType: 'text/xml; charset=gb2312', onload: function(resp) { var gb2312Keyword; if (resp.status < 200 || resp.status > 300) { utils.errLog("Failed to convert " + keyword + " to gb2312."); dfd.reject(keyword); return; } gb2312Keyword = String(resp.responseText.match(/word=[^'"&]+['"&]/i)).replace(/word=|['"&]/ig, ''); return dfd.resolve(gb2312Keyword); }, onerror: function() { return utils.errLog("Failed to convert " + keyword + " to gb2312."); } }); return dfd.promise(); }, cache: { read: function(key) { var item, realKey; realKey = "" + config.localCacheKeyPrefix + key; item = localStorage.getItem(realKey); return JSON.parse(localStorage.getItem(realKey)); }, write: function(key, value) { var realKey; realKey = "" + config.localCacheKeyPrefix + key; return localStorage.setItem(realKey, JSON.stringify(value)); }, writeBookInfos: function(key, bookInfos) { if (bookInfos._viewTimes == null) { bookInfos._viewTimes = 0; } bookInfos._viewTimes = bookInfos._viewTimes + 1; return utils.cache.write(key, bookInfos); } }, clean: function(content) { var pattern, tags, _i, _len; tags = [//gi, /.*<\/script>/gi, /.*<\/link>/gi, /.*<\/style>/gi]; for (_i = 0, _len = tags.length; _i < _len; _i++) { pattern = tags[_i]; content = content.replace(pattern, ''); } return content; } }; },{"./config":1}]},{},[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]);