-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgdut-library-helper.gm.js
781 lines (681 loc) · 23.1 KB
/
gdut-library-helper.gm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
(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;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
module.exports = {
libraryBaseUrl: 'http://222.200.98.171:81',
localCacheLife: 5,
localCacheKeyPrefix: 'gdut_library_helper_'
};
},{}],2:[function(require,module,exports){
var helper, pages, utils;
utils = require('./utils');
pages = require('./pages');
module.exports = helper = {
options: {
libraryUrl: 'http://222.200.98.171:81',
localCacheLife: 5
},
dispatch: function() {
var matched, pageName;
matched = /[com, 81]\/([\w]+)\/*/.exec(document.URL);
pageName = matched === null ? 'index' : matched[1].trim();
utils.log("Processing " + pageName + ".");
switch (pageName) {
case 'subject':
return this.page.doubanBookItem();
case 'subject_search':
return this.page.doubanBooksSearch();
case 'doulist':
return this.page.doubanBooksList();
case 'readerrecommend':
return this.page.libraryReaderRecommend();
default:
return utils.errLog("Unable to find page handler for " + pageName + ".");
}
},
page: {
doubanBookItem: function() {
return pages.douban.item.handle();
},
doubanBooksSearch: function() {
return pages.douban.search.handle();
},
doubanBooksList: function() {
return pages.douban.list.handle();
},
libraryReaderRecommend: function() {
return pages.library.recommend.handle();
}
}
};
},{"./pages":6,"./utils":18}],3:[function(require,module,exports){
// ==UserScript==
// @name GDUT library helper
// @namespace http://library.gdut.edu.cn
// @version 0.5.0
// @description Show the available books amount in GDUT library.
// @match http://book.douban.com/*
// @match http://222.200.98.171:81/*
// @match http://www.baidu.com/*
// @copyright 2012, Link, hbc
// @require http://cdn.staticfile.org/jquery/2.1.1-rc2/jquery.min.js
// @require http://isbn.jpn.org/js/isbn.js
// @require http://isbn.jpn.org/js/isbn-groups.js
// @grant GM_xmlhttpRequest
// ==/UserScript==
;
(require('./helper')).dispatch();
},{"./helper":2}],4:[function(require,module,exports){
var BasePageHandler;
BasePageHandler = (function() {
function BasePageHandler() {}
BasePageHandler.prototype.handle = function() {};
BasePageHandler.prototype.inject = function() {};
return BasePageHandler;
})();
module.exports = BasePageHandler;
},{}],5:[function(require,module,exports){
var BasePageHandler, BookItemHandler, DouListHandler, DoubanPageHandler, SearchHandler, parser, query, templates, utils,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
utils = require('../utils');
query = require('../query');
parser = (require('../parser')).douban;
templates = (require('../templates')).douban;
BasePageHandler = require('./_base');
DoubanPageHandler = (function(_super) {
__extends(DoubanPageHandler, _super);
function DoubanPageHandler() {
return DoubanPageHandler.__super__.constructor.apply(this, arguments);
}
DoubanPageHandler.prototype.itemKey = function(bookMeta) {
return "douban_" + bookMeta.id;
};
return DoubanPageHandler;
})(BasePageHandler);
BookItemHandler = (function(_super) {
__extends(BookItemHandler, _super);
function BookItemHandler() {
return BookItemHandler.__super__.constructor.apply(this, arguments);
}
BookItemHandler.prototype.inject = function(bookInfos, bookMeta) {
($('#info')).append(templates.subject.bookInfos(bookInfos));
return utils.cache.writeBookInfos(this.itemKey(bookMeta), bookInfos);
};
BookItemHandler.prototype.injectFail = function(bookInfos, bookMeta) {
var $info;
$info = $('#info');
if (bookInfos) {
return $info.append(templates.subject.foundMultiple(bookInfos));
} else {
return $info.append(templates.subject.notFound(bookMeta));
}
};
BookItemHandler.prototype.handle = function() {
var bookMeta, inject;
bookMeta = parser.parseBookItemPage($('body'));
inject = (function(_this) {
return function(bookInfos) {
return query.library.ctrlNo(bookInfos).always(function(updatedBookInfos) {
return _this.inject(updatedBookInfos, bookMeta);
});
};
})(this);
return query.local.bookId(this.itemKey(bookMeta)).then(function() {
return query.library.isbn(bookMeta);
}).then(function() {
return query.library.title(bookMeta);
}).then((function(_this) {
return function(bookInfos) {
return _this.injectFail(bookInfos, bookMeta);
};
})(this)).fail(inject);
};
return BookItemHandler;
})(DoubanPageHandler);
SearchHandler = (function(_super) {
__extends(SearchHandler, _super);
function SearchHandler() {
return SearchHandler.__super__.constructor.apply(this, arguments);
}
SearchHandler.prototype.inject = function(infos) {
var tmpl;
if (infos) {
tmpl = templates.subjectSearch.result(infos);
} else {
tmpl = templates.subjectSearch.notFound();
}
return $(tmpl).insertBefore($('#content .aside .mb20'));
};
SearchHandler.prototype.handle = function() {
var keyword;
keyword = parser.parseSearchPage($('body'));
return query.library.keyword(keyword).always(this.inject);
};
return SearchHandler;
})(DoubanPageHandler);
DouListHandler = (function(_super) {
__extends(DouListHandler, _super);
function DouListHandler() {
return DouListHandler.__super__.constructor.apply(this, arguments);
}
DouListHandler.prototype.inject = function(bookInfos, bookMeta) {
if (!bookMeta.$item) {
return;
}
($('p.pl', bookMeta.$item)).append(templates.douList.bookInfos(bookInfos));
return utils.cache.writeBookInfos(this.itemKey(bookMeta), bookInfos);
};
DouListHandler.prototype.handleBook = function(bookMeta) {
return query.local.bookId(this.itemKey(bookMeta)).then(function() {
return query.library.title(bookMeta);
}).fail((function(_this) {
return function(bookInfos) {
return _this.inject(bookInfos, bookMeta);
};
})(this));
};
DouListHandler.prototype.handle = function() {
var book, _i, _len, _ref, _results;
_ref = parser.parseListPage($('body'));
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
book = _ref[_i];
_results.push(this.handleBook(book));
}
return _results;
};
return DouListHandler;
})(DoubanPageHandler);
module.exports = {
item: new BookItemHandler,
search: new SearchHandler,
list: new DouListHandler
};
},{"../parser":9,"../query":12,"../templates":16,"../utils":18,"./_base":4}],6:[function(require,module,exports){
module.exports = {
douban: require('./douban'),
library: require('./library')
};
},{"./douban":5,"./library":7}],7:[function(require,module,exports){
var BasePageHandler, RecommendHandler, doubanQuery, parser,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
parser = (require('../parser')).library;
doubanQuery = (require('../query')).douban;
BasePageHandler = require('./_base');
RecommendHandler = (function(_super) {
__extends(RecommendHandler, _super);
function RecommendHandler() {
return RecommendHandler.__super__.constructor.apply(this, arguments);
}
RecommendHandler.prototype.inject = function(bookMeta) {
($('#ctl00_ContentPlaceHolder1_titletb')).val(bookMeta.title);
($('#ctl00_ContentPlaceHolder1_authortb')).val(bookMeta.author);
($('#ctl00_ContentPlaceHolder1_isbntb')).val(bookMeta.isbn);
($('#ctl00_ContentPlaceHolder1_publisherb')).val(bookMeta.publisher);
return ($('#ctl00_ContentPlaceHolder1_publishdatetb')).val(bookMeta.publishYear);
};
RecommendHandler.prototype.handle = function() {
var doubanBookId;
doubanBookId = parser.parseDoubanReference();
if (!doubanBookId) {
return;
}
return doubanQuery.queryItem(doubanBookId).fail(this.inject);
};
return RecommendHandler;
})(BasePageHandler);
module.exports = {
recommend: new RecommendHandler
};
},{"../parser":9,"../query":12,"./_base":4}],8:[function(require,module,exports){
var R_AUTHOR, R_BOOK_ID, R_ISBN, R_PUBLISHER, R_PUBLISH_YEAR, matchFirstOrNull, utils;
utils = require('../utils');
R_BOOK_ID = /subject\/(\d+)/;
R_ISBN = /ISBN:\s*(.*)/;
R_AUTHOR = /作者\s*:\s*(.*)/;
R_PUBLISHER = /出版社\s*:\s*(.*)/;
R_PUBLISH_YEAR = /出版年:\s*(.*)/;
matchFirstOrNull = function(pattern, haystack) {
var rv;
rv = pattern.exec(haystack);
if (rv !== null) {
rv = rv[1].trim();
}
return rv;
};
module.exports = {
parseBookItemPage: function(content) {
var bookInfoContent, bookMeta, isbn, m;
bookInfoContent = ($('#info', content)).text();
m = function(pattern) {
return matchFirstOrNull(pattern, bookInfoContent);
};
isbn = m(R_ISBN);
bookMeta = {
id: matchFirstOrNull(R_BOOK_ID, location.href),
title: $('h1 span', content).text().trim(),
author: m(R_AUTHOR),
publisher: m(R_PUBLISHER),
publishYear: m(R_PUBLISH_YEAR),
isbn: isbn,
isbn10: utils.convertISBN(isbn, 10),
isbn13: utils.convertISBN(isbn, 13)
};
return bookMeta;
},
parseSearchPage: function(content) {
var $input;
$input = $('#inp-query', content);
return $input.val();
},
parseDouListItem: function($item) {
var $link, bookMeta, content;
$link = $(($('.pl2 a', $item))[1]);
content = ($('p.pl', $item)).text();
bookMeta = {
id: matchFirstOrNull(R_BOOK_ID, $link.attr('href')),
title: $link.text().trim(),
author: matchFirstOrNull(R_AUTHOR, content),
publisher: matchFirstOrNull(R_PUBLISHER, content),
$item: $item
};
return bookMeta;
},
parseListPage: function(content) {
var $i;
return (function() {
var _i, _len, _ref, _results;
_ref = $('.doulist_item', content);
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
$i = _ref[_i];
_results.push(this.parseDouListItem($i));
}
return _results;
}).call(this);
}
};
},{"../utils":18}],9:[function(require,module,exports){
arguments[4][6][0].apply(exports,arguments)
},{"./douban":8,"./library":10}],10:[function(require,module,exports){
var query, templates, utils;
utils = require('../utils');
templates = (require('../templates')).library;
module.exports = query = {
parseBookInfo: function($content) {
var $books, book, bookInfos, isAvailable;
$books = $('#bardiv .tb tbody>tr', $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 "<span class=\"pl\">GDUT:</span> \n<a href=\"" + infos.url + "\" target=\"_blank\">还剩 " + infos.remains + " 本</a>\n<br />\n在 " + infos.location;
},
notFound: function(infos) {
var recommendUrl;
recommendUrl = libraryTmpl.recommendUrl(infos);
return "<span class=\"pl\">GDUT:</span> \n没有找到噢,<a href=\"" + recommendUrl + "\" target=\"_blank\">去荐购</a>";
},
foundMultiple: function(infos) {
return "<span class=\"pl\">GDUT:</span> \n<a href=\"" + infos.queryUrl + "\" target=\"_blank\">找到 " + infos.results.length + " 本类似的</a>";
}
},
subjectSearch: {
result: function(infos) {
return "<div class=\"mb20\">\n <div class=\"hd\">\n <h2>在广工图书馆 · · ·</h2>\n </div>\n <div class=\"bd\">\n <p class=\"pl\">\n <a href=\"" + infos.queryUrl + "\" target=\"_blank\">\n 找到 " + infos.results.length + " 本类似的\n </a>\n </p>\n </div>\n</div>";
},
notFound: function() {
return "<div class=\"mb20\">\n <div class=\"hd\">\n <h2>在广工图书馆 · · ·</h2>\n </div>\n <div class=\"bd\">\n <p class=\"pl\">没有找到噢</p>\n </div>\n</div>";
}
},
douList: {
bookInfos: function(infos) {
return "<br />\nGDUT: <a href=\"" + infos.url + "\" target=\"_blank\">还剩 " + infos.remains + " 本</a>\n<br />\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 = [/<img.*>/gi, /<script.*>.*<\/script>/gi, /<link.*>.*<\/link>/gi, /<style.*>.*<\/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]);