-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMonkeyBean.js
2741 lines (2496 loc) · 115 KB
/
MonkeyBean.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
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name MonkeyBean
// @namespace sunnylost
// @version 1.2
// @include http://*.douban.*/*
// @include http://douban.fm/*
// @require http://userscript-autoupdate-helper.googlecode.com/svn/trunk/autoupdatehelper.js
// @require http://code.jquery.com/jquery-1.7.2.min.js
/* @reason
@end*/
// ==/UserScript==
typeof Updater != 'undefined' && new Updater({
name: "MonkeyBean",
id: "124760",
version:"1.2"
}).check();
/**
* 说明:
* monkey-action:用于触发事件
* monkey-data:用于保存信息
* monkey-sign:标记的元素
*/
(function(window, undefined) {
if(window !== window.top) return false; //防止在iframe中执行
var $ = $ || unsafeWindow.$; //默认使用1.7.2版本的jQuery,如果不存在则使用豆瓣提供的,目前版本1.4.4
var body = $(document.body);
var startTime = new Date();
/*-------------------Begin--------------------*/
/**
* 静态变量
*/
var MonkeyBeanConst = {
PAGE_ITEM_COUNTS : 100, //每页显示条目
API_COUNT : 'MonkeyBean.API.count',
API_LAST_REQUEST_TIME : 'MonkeyBean.API.lastTime',
API_INTERVAL : 60000, //请求api的间隔
API_LIMIT : 10, //在以上间隔内,最多请求次数,默认10次
API : { //豆瓣API
'PEOPLE' : 'http://api.douban.com/people/{1}' //用户信息
},
DATA_SPLITER : '[-]', //monkey-data中的分隔符
DOUBAN_MAINPAGE : 'http://www.douban.com/', //豆瓣主页
MODULE_NAME_PREFIX : 'MonkeyBean.Module.',
HIGHLIGHT_COLOR : '#46A36A' , //高亮用户发言的颜色
BLANK_STR : '', //空字符串
SEARCH_INPUT : { //搜索框选项
'www' : {
'placeholder' : '成员、小组、音乐人、主办方',
'url' : 'http://www.douban.com/search',
'cat' : ''
},
'movie' : {
'placeholder' : '电影、影人、影院、电视剧',
'url' : 'http://movie.douban.com/subject_search',
'cat' : '1002'
},
'book' : {
'placeholder' : '书名、作者、ISBN',
'url' : 'http://book.douban.com/subject_search',
'cat' : '1001'
},
'music' : {
'placeholder' : '唱片名、表演者、条码、ISRC',
'url' : 'http://music.douban.com/subject_search',
'cat' : '1003'
},
'location' : {
'placeholder' : '活动名称、地点、介绍',
'url' : 'http://www.douban.com/event/search',
'cat' : ''
}
},
USER_NAME : 'monkey.username',
USER_LOCATION : 'monkey.location'
};
var hasOwn = Object.prototype.hasOwnProperty,
mine = /\/mine/,
people = /\/people\/(.*)\//,
//快捷键对应的code
keyCode = {
'enter' : 13
};
//-------------------------猴子工具箱----------------------------------
var monkeyToolBox = {
cookie : {
get : function(name) {
var start,
end,
len = document.cookie.length;
if(len > 0) {
start = document.cookie.indexOf(name + '=');
if(start != -1) {
start = start + name.length + 1;
end = document.cookie.indexOf(';', start);
if(end == -1) end = len;
return decodeURI(document.cookie.substring(start, end).replace(/"/g, ''));
}
}
return '';
}
},
//地址查询字符串搜索
locationQuery : function() {
if(location.search.length < 0) return {};
var queryarr = location.search.substring(1).split('&'),
len = queryarr.length,
item,
result = {};
while(len) {
item = queryarr[--len].split('=');
result[decodeURIComponent(item[0])] = decodeURIComponent(item[1]);
}
return result;
},
//让光标定位到文本框末尾,非浏览器兼容的代码
focusToTheEnd : function(el) {
var len = el.value.length;
el.setSelectionRange(len, len);
el.focus();
}
};
//shortcuts
var cookie = monkeyToolBox.cookie,
query = monkeyToolBox.locationQuery(),
focusToTheEnd = monkeyToolBox.focusToTheEnd;
var MonkeyBean = {
author : 'sunnylost',
updateTime : '20120527',
password : 'Ooo! Ooo! Aaa! Aaa! :(|)',
path : location.hostname + location.pathname,
//开启debug模式
debugMode : false,
log : function(msg) {
MonkeyBean.debugMode && typeof console !== 'undefined' && console.log(msg);
},
GUID : 0,
CommentId : function() {
return 'Monkey-Comment-' + (this.GUID++);
},
//TODO,使用豆瓣API有限制,每个IP每分钟10次,如果加上key的话是每分钟40次,如果超过限制会被封IP,因此要记录调用API次数及其间隔。
useAPI : function() {
},
getUserInfo : function(nickName) {
},
get : function(key, defaultVal) {
return GM_getValue(key, defaultVal);
},
set : function(key, value) {
GM_setValue(key, value);
},
del : function(key) {
GM_deletetValue(key);
},
//MonkeyBean初始化方法
init : function() {
var that = this;
this.MonkeyModuleManager.turnOn();
//注册全局click事件
body.delegate('[monkey-action]', 'click', function(e) {
var actionContext = this,
actionType = this.getAttribute('monkey-action'),
actionName = this.getAttribute('monkey-action-name');
console.log('actionType=' + actionType);
body.trigger(actionType, [actionName, actionContext]);
})
//loading动画
body.bind('loadingStart', function() {
$('.Monkey-Loading-stop').removeClass('Monkey-Loading-stop').addClass('Monkey-Loading');
})
body.bind('loadingStop', function() {
$('.Monkey-Loading').removeClass('Monkey-Loading').addClass('Monkey-Loading-stop');
})
},
//是否登录
isLogin : function() {
return (typeof this.login !== 'undefined' && this.login) || (this.login = !!this.getCk());
},
//TODO:获取用户ID,有问题
userId : function() {
var str = cookie.get('dbcl2');
return str && str.split(':')[0];
},
getCk : function(flag) {
return !flag ? (this.ck || (this.ck = cookie.get('ck'))) : cookie.get('ck');
},
//Mr.TM Tripple M;
MonkeyModuleManager : (function() {
var moduleTree = {}, //模块树,所有模块都生长在树上。
get, //根据名字获得对应模块
turnOn,
register;
get = function(moduleName) {
return moduleTree[moduleName];
};
register = function(moduleName, module) {
moduleTree[moduleName] = module;
};
turnOn = function() {
var m, tmpModule;
for(m in moduleTree) {
if(hasOwn.call(moduleTree, m)) {
tmpModule = moduleTree[m];
//log(tmpModule.name + ' 加载~');
tmpModule.fit() && tmpModule.load();
}
}
};
return {
get : get,
register : register,
turnOn : turnOn
}
})()
};
/**
TODO:需要重写
* 页面类型:
www : 我的豆瓣
book : 读书
movie : 电影
music : 音乐
location : 同城
9 : 9点
fm : FM
alpha : 阿尔法城
group : 小组
topic : 话题
category : 分类
discussion : 讨论
list : 包括豆列、搜索列表
update : 友邻广播
photo : 相册
*/
MonkeyBean.page = (function() {
var type = '',
turnType = '', //翻页类型
path = MonkeyBean.path,
hostname = location.hostname,
normalType = /(www|book|movie|music|9)\.douban\.com\/.*/,
list = /(book|movie|music)\.douban\.com\/(doulist\/\d+)|(subject_search)|(review\/best\/)/,
group = /www\.douban\.com\/group\/?/,
topic = /group\/topic\/\d+/,
discussion = /((group\/[^\/]+)|(subject\/\d+))\/discussion/,
category = /group\/category\/\d+\//,
update = /www\.douban\.com\/update\//,
photo = /^www\.douban\.com\/photos\/album\/\d+\/$/;
if(hostname == 'douban.fm') {
type = 'fm';
} else if(hostname == 'alphatown.com') {
type = 'alpha';
} else {
if(list.test(path)) {
turnType = 'list';
}
type = path.replace(normalType, '$1');
if(group.test(path)) {
(topic.test(path) && (turnType = 'topic')) ||
(discussion.test(path) && (turnType = 'discussion')) ||
(category.test(path) && (turnType = 'category'));
} else if(update.test(path)) {
turnType = 'update';
} else if(photo.test(path)) {
turnType = 'photo';
} else if(discussion.test(path)) {
turnType = 'discussion';
} else if(type.indexOf('douban.com') != -1) {
type = 'location';
}
}
return {
'type' : type,
'turnType' : turnType
};
})();
var log = MonkeyBean.log;
MonkeyBean.TM = MonkeyBean.MonkeyModuleManager;
var MonkeyModule = function(name, method) {
if(this.constructor != MonkeyModule) {
return new MonkeyModule(name, method);
}
this.name = name;
$.extend(this, method);
//this.on = MonkeyBean.get(moduleNamePrefix + name); //是否启动
this.on = true;
this.init();
};
MonkeyModule.prototype = {
constructor : MonkeyModule,
init : function() {
MonkeyBean.TM.register(this.name, this);
},
get : function(name) {
return this.attr[name];
},
set : function(key, value) {
this.attr = this.attr || {};
var attrs, attr;
if($.isPlainObject(key) || key == null) {
attrs = key;
} else {
attrs = {};
attrs[key] = value;
}
for(attr in attrs) {
this.attr[attr] = attrs[attr];
}
},
load : function() {
},
//检测是否适用于当前页面
fit : function() {
//如果不提供filter,默认全局开启。
return this.filter ? !$.isArray(this.filter) && (this.filter.test(MonkeyBean.path)) : true;
},
//TODO:一个简单的模板方法
template : function(key, value) {
},
toString : function() {
return 'This module\'s name is:' + this.name;
}
};
var userName = MonkeyBean.get(MonkeyBeanConst.USER_NAME),
userLocation = MonkeyBean.get(MonkeyBeanConst.USER_LOCATION);
//GM_deleteValue(cName);
//log('username=' + userName);
//获得用户ID与地址
(function () {
if (!userName) {
GM_xmlhttpRequest({
method:'GET',
url:'http://www.douban.com/mine',
onload:function (resp) {
//没有cookie~会自动跳转到登录页面
if (location.href.indexOf('www.douban.com/accounts/login') != -1) return;
//响应头部信息中,包含了最终的url,其中就有用户名
var arr = resp.finalUrl.split('/');
userName = arr[arr.length - 2];
MonkeyBean.set(MonkeyBeanConst.USER_NAME, userName);
}
})
}
if (!userLocation) {
GM_xmlhttpRequest({
method:'GET',
url:'http://www.douban.com/location',
onload:function (resp) {
if (location.href.indexOf('www.douban.com/accounts/login') != -1) return;
//响应头部信息中,包含了最终的url,其中就有地址
var arr = $.trim(resp.finalUrl).split('.');
userLocation = arr[0].slice(7);
MonkeyBean.set(MonkeyBeanConst.USER_LOCATION, userLocation);
}
})
}
})()
MonkeyBean.UI = {
css : {
'button' : '.Monkey-Button {\
color : #4F946E;\
background-color: #F2F8F2;\
border: 1px solid #E3F1ED;\
padding : 0 8px;\
border-radius : 3px 3px 3px;\
cursor : pointer;\
}\
.Monkey-Button a {\
color : #4F946E;\
background-color: #F2F8F2;\
}\
.Monkey-Button:hover, .Monkey-Button:hover a {\
background-color: #0C7823;\
border-color: #C4E2D8;\
color: #FFFFFF;\
}',
//只是向下的箭头
'arrow' : ' .Monkey-Pointer {\
position : absolute;\
height : 0;\
left : 50px;\
}\
.Monkey-Pointer-Border {\
border: 9px solid;\
}\
.Monkey-a {\
border-color: #BBBBBB transparent transparent;\
}\
.Monkey-b {\
border-color: #FFFFFF transparent transparent;\
top: -20px;\
position : relative;\
}',
//loading样式来源于http://www.alessioatzeni.com/blog/css3-loading-animation-loop/
'loading' : '.Monkey-Loading {\
background-color: rgba(0,0,0,0);\
border:5px solid rgba(255,255,255,0.9);\
opacity:.9;\
border-left:5px solid rgba(0,0,0,0);\
border-right:5px solid rgba(0,0,0,0);\
border-radius:50px;\
box-shadow: 0 0 15px #fff;\
width:10px;\
height:10px;\
margin:0 auto;\
position:relative;\
-moz-animation:spinoffPulse 1s infinite linear;\
-webkit-animation:spinoffPulse 1s infinite linear;\
}\
@-moz-keyframes spinoffPulse {\
0% { -moz-transform:rotate(0deg); }\
100% { -moz-transform:rotate(360deg); }\
}\
@-webkit-keyframes spinoffPulse {\
0% { -webkit-transform:rotate(0deg); }\
100% { -webkit-transform:rotate(360deg); }\
}\
.Monkey-Loading-stop {\
display : none;\
-moz-animation-play-state : paused;\
}'
},
html : {
'arrow' : '<div class="Monkey-Pointer">\
<div class="Monkey-a Monkey-Pointer-Border"></div>\
<div class="Monkey-b Monkey-Pointer-Border"></div>\
</div>'
}
};
/*********************************UI begin**************************************************************/
/**
* 提示便签
* TODO : 默认3秒的延迟消失,这里的时间应该可以配置
* updateTime : 2012-3-13
*/
MonkeyModule('tip', {
css : '#MonkeyUI-tip {\
background-color: #F9EDBE;\
border: 1px solid #F0C36D;\
-webkit-border-radius: 2px;\
-webkit-box-shadow: 0 2px 4px rgba(0,0,0,0.2);\
border-radius: 2px;\
box-shadow: 0 2px 4px rgba(0,0,0,0.2);\
font-size: 13px;\
line-height: 18px;\
padding: 16px;\
position: absolute;\
vertical-align: middle;\
width: 160px;\
z-index: 6000;\
border-image: initial;\
display:none;\
}\
#MonkeyUI-tip .Monkey-Pointer {\
top : 95px;\
}\
#MonkeyUI-tip .Monkey-a {\
border-color : #F0C36D transparent transparent;\
}\
#MonkeyUI-tip .Monkey-b {\
border-color : #F9EDBE transparent transparent;\
}',
html : '<div id="MonkeyUI-tip">\
<p name="MonkeyUI-tip-content"></p>\
<a href="javascript:void(0)" style="position:relative;left:45%;" monkey-action="TipClose" >关闭</a>\
' + MonkeyBean.UI.html.arrow +
'</div>',
load : function() {
var that = this;
this.render();
body.bind('TipClose', function() {
that.hide();
})
},
render : function() {
this.el = $(this.html);
this.content = this.el.find('p[name=MonkeyUI-tip-content]');
document.body.appendChild(this.el[0]);
GM_addStyle(this.css);
GM_addStyle(MonkeyBean.UI.css.arrow);
},
show : function(msg, pos) {
var that = this;
clearTimeout(this.timeoutId);
this.timeoutId = setTimeout(function() {
that.hide();
}, 3000);
this.content.html(msg);
this.el.css({
'left' : pos.left + 'px',
'top' : pos.top + 'px'
})
this.el.fadeIn();
},
hide : function() {
clearTimeout(this.timeoutId);
this.el.fadeOut();
}
});
/**
* 回复框
* updateTime : 2012-2-19
*/
MonkeyModule('reply', {
css : '#Monkey-ReplyForm{\
-moz-border-bottom-colors: none;\
-moz-border-image: none;\
-moz-border-left-colors: none;\
-moz-border-right-colors: none;\
-moz-border-top-colors: none;\
background-color: #FFFFFF;\
border-color: #ACACAC #ACACAC #999999;\
border-style: solid;\
border-width: 1px;\
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);\
color: #000000;\
outline: 0 none;\
z-index: 1101;\
display : none;\
height : 320px;\
width : 350px;\
position: fixed;\
left : 60%;\
top : 20%;\
}\
#Monkey-ReplyToolbox {\
position : absolute;\
margin-left : 15px;\
text-align : center;\
padding-bottom : 2px;\
left : 60px;\
bottom : 2px;\
height : 25px;\
}\
#Monkey-ReplyText {\
position : absolute;\
top : 2px;\
height : 85%;\
width : 99%;\
padding : 2px 3px 0 3px;\
}\
#Monkey-ReplyText textarea {\
font-size: 12px;\
width : 96%;\
height : 100%;\
padding : 2px;\
margin : 3px;\
}\
.Monkey-FormButton {\
background-color: #3FA156;\
border: 1px solid #528641;\
border-radius: 3px 3px 3px 3px;\
color: #FFFFFF;\
cursor: pointer;\
height: 25px;\
padding: 5px 10px 6px;\
}\
.Monkey-FormButton:hover {\
background-color: #4FCA6C;\
border-color: #6AAD54;\
}\
.Monkey-FormButton-flat {\
border-color: #BBBBBB #BBBBBB #999999;\
border-radius: 3px 3px 3px 3px;\
border-style: solid;\
border-width: 1px;\
color: #444444;\
display: inline-block;\
overflow: hidden;\
vertical-align: middle;\
}\
.Monkey-FormButton-flat input {\
background-image: -moz-linear-gradient(-90deg, #FCFCFC 0pt, #E9E9E9 100%);\
border: 0 none;\
border-radius: 2px 2px 2px 2px;\
color: #333333;\
cursor: pointer;\
font-size: 12px;\
height: 25px;\
margin: 0 !important;\
padding: 0 14px;\
}\
.Monkey-FormButton-flat:hover {\
border-color: #999999 #999999 #666666;\
color: #333333;\
}',
html : '<div id="Monkey-ReplyForm">\
<form name="comment_form" method="post" action="add_comment">\
<div style="display: none;">\
<input name="ck" value="' + MonkeyBean.getCk() + '" type="hidden">\
</div>\
<div id="Monkey-ReplyText">\
<textarea id="re_text" name="rv_comment" rows="10" cols="40">\
</textarea>\
</div>\
<div id="Monkey-ReplyToolbox">\
<input value="加上去" type="submit" monkey-action="submit" class="Monkey-FormButton">\
<span class="Monkey-FormButton-flat">\
<input value="清空" type="button" monkey-action="reset" class="Monkey-FormButton-flat">\
</span>\
<span class="Monkey-FormButton-flat">\
<input value="取消" type="button" monkey-action="cancel" class="Monkey-FormButton-flat">\
</span>\
</div>\
</form>\
</div>',
load : function() {
//log('loading reply');
this.render();
},
render : function() {
var that = this;
GM_addStyle(this.css);
this.form = $(this.html);
this.form.appendTo(document.body);
this.text = $('#Monkey-ReplyForm #re_text');
this.text.val(''); //默认光标会出现在textare的第一行正中间,手动清除一下
this.form.delegate('input[monkey-action]', 'click', function() {
that[this.getAttribute('monkey-action')]();
});
},
show : function() {
this.form.show();
focusToTheEnd(this.text[0]);
},
submit : function() {
//log('submit');
},
//清除回复框中的内容
reset : function() {
this.text.val('');
this.text.focus();
},
//隐藏回复框
cancel : function() {
this.reset();
this.form.hide();
},
//向文本框中输入内容,如果文本框中有内容,则增加一个换行,再添加新内容
setContent : function(content) {
this.show(); //如果不显示,那么执行focusToTheEnd会报错
var oldContent = this.text.val();
this.text.val(($.trim(oldContent) == '' ? '' : oldContent + '\n') + content);
focusToTheEnd(this.text[0]);
}
});
/*********************************UI end**************************************************************/
/*********************************Common Function****************************************************************/
/**
* 通用留言工具函数
* updateTime : 2012-2-21
*/
var monkeyCommentToolbox = {
//快捷回复
reply : function(data, el) {
var form = MonkeyBean.TM.get('reply');
form.show();
form.setContent('@' + data.split(MonkeyBeanConst.DATA_SPLITER)[1] + '\n');
},
//引用用户发言
quote : function(data) {
var commentId = data.split(MonkeyBeanConst.DATA_SPLITER)[2],
comment = null,
quoteHeader = '',
quoteContent = '',
spliter = '-------------------------------------------------------------------\n';
//log('-----=====' + commentId);
comment = $('#' + commentId);
quoteHeader = comment.find('h4').text().replace(/\s+/g, ' ') + '\n';
quoteContent = comment.find('.reply-doc p').text() + '\n';
//log(quoteHeader);
//log(quoteContent);
MonkeyBean.TM.get('reply').setContent(spliter + quoteHeader + quoteContent + spliter);
},
//只看该用户发言
only : function(data) {
var items = this.cache || (this.cache = $('[monkey-sign]')),
len = items.length,
i = 0,
tmp = null;
while(len--) {
tmp = items.eq(len);
tmp.attr('monkey-sign') != data.split(MonkeyBeanConst.DATA_SPLITER)[0] && tmp.hide();
}
},
//高亮该用户所有发言
highlight : function(data) {
var items = $('[monkey-sign=' + data.split(MonkeyBeanConst.DATA_SPLITER)[0] + ']'),
len = items.length,
tmpColor = '';
tmpColor = (this.clicked = !this.clicked) ? MonkeyBeanConst.HIGHLIGHT_COLOR : MonkeyBeanConst.BLANK_STR;
while(len--) {
items.eq(len).css('backgroundColor', tmpColor);
}
},
//忽略该用户所有发言
ignore : function(data) {
var items = $('[monkey-sign=' + data.split(MonkeyBeanConst.DATA_SPLITER)[0] + ']'),
len = items.length;
while(len--) {
items.eq(len).hide();
}
},
//还原为原始状态
reset : function(data) {
var items = this.cache || $('[monkey-sign]'),
len = items.length,
tmp = null;
this.clicked = false; //"高亮"里需要这个参数
while(len--) {
tmp = items.eq(len);
tmp.show();
tmp.css('backgroundColor', MonkeyBeanConst.BLANK_STR);
}
}
};
/*********************************Module begin**************************************************************/
/**
* 天气模块
* updateTime : 2012-3-10
*/
MonkeyModule('MonkeyWeather', {
attr : {
url : 'http://www.google.com/ig/api?weather={1}&hl=zh-cn'
},
filter : /www.douban.com\/(mine|(people\/.+\/)$)/,
css : '.Monkey-Weather{position:relative;top:10px;}',
html : '<div class="Monkey-Weather">\
<div style="float:left;margin-right:10px;">\
<img height="40" width="40" alt="{1}" src="http://g0.gstatic.com{2}">\
<br>\
</div>\
<span><strong>{3}</strong></span>\
<span>{4}℃</span>\
<div style="float:">当前: {1}\
</div>\
</div>',
el : $('#profile'),
load : function() {
this.fetch();
},
fetch : function() {
var place = $('.user-info > a'),
a,
that = this;
if(!place || !$.trim(place.text())) return;
a = place.attr('href').match(/http:\/\/(.*)\.douban\.com/);
place = place.text();
GM_xmlhttpRequest({
method : 'GET',
url : this.get('url').replace('{1}', RegExp.$1),
headers : {
Accept: 'text/xml'
},
onload : function(resp) {
var xml = $(resp.responseText);
that.set({
condition : xml.find('condition').attr('data'),
icon : xml.find('icon').attr('data'),
temp : xml.find('temp_c').attr('data'),
place : place
});
that.render();
}
});
},
render : function() {
if(!this.el) return;
GM_addStyle(this.css);
var container = $(this.html.replace(/\{1\}/g, this.get('condition'))
.replace('{2}', this.get('icon'))
.replace('{3}', this.get('place'))
.replace('{4}', this.get('temp')));
container.insertBefore(this.el);
}
});
/**
* 留言板,增加回复功能
* 适用页面:个人主页与留言板页
* updateTime : 2012-2-19
*/
//TODO:未完成
MonkeyModule('MonkeyMessageBoard', {
//TODO:<span class="gact">
html:{
'doumail' : ' <a href="/doumail/write?to={1}">回豆邮</a>',
'reply' : ' <a href="JavaScript:void(0);" monkey-data="{1}' + MonkeyBeanConst.DATA_SPLITER + '{2}" title="回复到对方留言板">回复</a>',
'form' : '<form style="margin-bottom:12px" id="fboard" method="post" name="bpform">\
<div style="display:none;"><input type="hidden" value="' + MonkeyBean.getCk() + '" name="ck"></div>\
<textarea style="width:97%;height:50px;margin-bottom:5px" name="bp_text"></textarea>\
<input type="submit" value=" 留言 " name="bp_submit">\
<a href="javascript:void(0);" id="monkey_resetBtn" style="float:right;display:none;">点击恢复原状</a>\
</form>'
},
filter : /www.douban.com\/(people\/.+\/)(board)$/,
el : $('ul.mbt'),
load : function () {
return true;
this.render();
},
render : function () {
this.form = $(this.html['form']);
this.form.insertBefore(this.el);
this.resetBtn = $('#monkey_resetBtn');
this.resetBtn.bind('click', $.proxy(this.reset, this));
this.bind('reply', this.reply, this);
if (!this.el || (this.el = this.el.find('li.mbtrdot')).length < 1) return;
var len = this.el.length,
i = 0,
that = this,
id,
nickName,
tmp;
for (; i < len; i++) {
tmp = this.el[i];
var tempVar = tmp.getElementsByTagName('a')[0];
nickName = tempVar.innerHTML;
tempVar.href.match(people);
id = RegExp.$1;
if (id != 'sunnylost') {
tmp = tmp.getElementsByTagName('span');
if (tmp.length == 1) {
tmp[0].parentNode.innerHTML += '<br/><br/><span class="gact">' + (this.html['doumail'] + this.html['reply']).replace(/\{1\}/g, id).replace('{2}', nickName) + '</span>';
} else if (tmp.length == 2) {
tmp[1].innerHTML += this.html['reply'].replace(/\{1\}/g, id).replace('{2}', nickName);
}
}
}
this.el.delegate('a[monkey-data]', 'click', function () {
that.trigger('reply', $(this).attr('monkey-data'));
});
},
//TODO:点击回复按钮时,应该可以回复到对方留言板
reply : function (userMsg) {
var tmpArr = userMsg.split(MonkeyBeanConst.DATA_SPLITER);
this.form.find('[type="submit"]').val('回复到的' + tmpArr[1] + '的留言板');
this.form.attr('action', 'http://www.douban.com/people/' + tmpArr[0] + '/board');
this.resetBtn.css('display', 'block');
},
reset : function () {
this.form.find('[type="submit"]').val('回复');
this.form.attr('action', '');
this.resetBtn.css('display', 'none');
}
});
var unreadDouMail = $('.top-nav-info em').html(); //未读豆邮
unreadDouMail = unreadDouMail == null ? '' : unreadDouMail;
/**
* 猴子导航栏——用于显示顶部导航栏的二级菜单
* updateTime : 2012-4-24
*/
MonkeyModule('MonkeyNavigator', {
css : '.Monkey-Nav-top {\
clear: both;\
color: #D4D4D4;\
height: 30px;\
margin-bottom: 20px;\
width: 100%;\
}\
.Monkey-Nav-top a:link, .Monkey-Nav-top a:visited, .Monkey-Nav-top a:hover, .Monkey-Nav-top a:active {\
color: #566D5E;\
}\
.Monkey-Nav-top a:hover {\
color : #566D5E;\
background-color : #fff;\
}\
.Monkey-Nav-top em {\
color: #1398B0;\
}\
.Monkey-Nav-bd {\
position : fixed;\
left : {left}px;\
height : 35px;\
width : 950px;\
z-index : 1000;\
padding-top : 7px;\
margin-top : -4px;\
background-color : #E9F4E9;\
border-radius : 3px;\
}\
.Monkey-Nav{\
display:block;\
font-size: 12px;\
margin-left : 15px;\
}\
.Monkey-Nav ul, .Monkey-Nav li {\
text-align : center;\
margin : 0;\
padding : 0;\
}\
.Monkey-Nav ul li ul li {\
text-align : center;\
width : 60px;\
}\
.Monkey-Nav:after .Monkey-Nav li ul:after{\
clear: both;\
content: " ";\
display: block;\
height: 0;\
}\
.Monkey-Nav ul li{\
float : left;\
height : 26px;\
line-height : 26px;\
width : 60px;\