forked from andy071001/nightfall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
localmembers.js
286 lines (240 loc) · 9.46 KB
/
localmembers.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
/**
* content scripts
*
* @author : [email protected]
* @license : GPLv3
*/
(function($) {
// dom elements
var j_tab_nav,
j_topics,
j_pg,
j_topic_paginator,
j_members_handle,
j_topics_handle,
j_members_bd = $('<div id="n-memberCtn" class="n-empty">loading</div>'),
j_switches = $('<div class="n-switches pl2">'+
'<div class="n-only_new on">'+
'Show only new members <a class="on" href="#">on</a><span class="on">on</span> | <a class="off" href="#">off</a><span class="off">off</span>'+
'</div>'+
'<div class="n-only_local on">'+
'Show only local members <a class="on" href="#">on</a><span class="on">on</span> | <a class="off" href="#">off</a><span class="off">off</span>'+
'</div>'+
'</div>'),
last_members = {},
loading_queue = [];
n.load_data('last_members', function(data){
last_members = data;
});
// dom templates
var tpl = {};
tpl.group_li = $('<div class="n-groupLi n-li n-empty">' +
'<div class="hd">' +
'<a class="n-subject" target="_blank"/>' +
'<div class="n-toggle">' +
'<a class="n-expand">+</a>' +
'<a class="n-collapse">-</a>' +
'</div>' +
'<div class="c" />' +
'</div>' +
'<div class="n-newMembers" />' +
'<div class="bd n-box" />' +
'</div>');
function show_members_tab(force_load){
j_topics.detach();
j_members_bd.appendTo(j_pg);
j_topic_paginator.hide();
j_members_handle.addClass(n.C_ON);
j_topics_handle.removeClass(n.C_ON);
j_switches.prependTo($('.aside'));
if(j_members_bd.hasClass(n.C_EMPTY) || true === force_load)
{
$.each(loading_queue, function(idx ,el){
clearTimeout(el);
});
load_groups();
}
}
function load_groups(){
$('<div />').load('/group/mine .article .indent:last', function() {
j_members_bd.empty().removeClass(n.C_EMPTY);
$.each($(this).find('dl'), function(idx, el) {
var j_link = $('dd a', this),
name = j_link.text(),
uri = j_link.attr('href');
tpl.group_li.clone().find('.n-subject').
text(name).attr('href', uri).end().appendTo(j_members_bd);
});
j_members_bd.find('.n-groupLi:first').addClass(n.C_CUR);
$.each(j_members_bd.find('.n-groupLi'), function(idx, el) {
var j_t = $(el),
j_bd = j_t.find('.bd'),
url = j_t.find('.hd a').attr('href');
//url = j_t.find('.hd a').attr('href') + 'members';
if(n.show_only_local_members){
url += 'member_search?search_text=' + n.LOCATION +
'&cat=1005';
} else {
url += 'members';
}
loading_queue.push(setTimeout(load_members,
1000 * idx, j_bd, url));
});
});
}
function load_members(j_container, url){
if(j_container.hasClass(n.C_ING)) {
return;
}
j_container.text('loading...').addClass(n.C_ING);
j_container.load(url + ' .obss:last, .paginator', function() {
var g_url = url,
gid = /www\.douban\.com\/group\/(.+)\//.exec(g_url)[1],
new_last_members = [],
matched_index = 0;
if('undefined' === typeof last_members[gid]){
_last_members = [];
} else {
_last_members = last_members[gid];
}
$.each(j_container.find('dl.obu:lt(2)'), function(idx, el) {
var j_t = $(el),
j_link = j_t.find('dd a'),
uid = /www\.douban.com\/people\/(.+)\//.
exec(j_link.attr('href'))[1];
new_last_members.push(uid);
});
$.each(j_container.find('dl.obu'), function(idx, el) {
var j_t = $(el),
j_link = j_t.find('dd a'),
uid = /www\.douban.com\/people\/(.+)\//.
exec(j_link.attr('href'))[1];
username = j_link.text();
if(n.show_only_new_members){
if(1 < matched_index){
j_t.remove();
return;
} else {
if(_last_members[matched_index] &&
(uid == _last_members[matched_index])){
matched_index++;
j_t.remove();
return;
}
}
}
if(-1 < $.inArray(username, n.blacklist_names)) {
j_t.remove();
}
});
last_members[gid] = new_last_members;
n.save_data('last_members', last_members);
var j_group = j_container.closest('.n-groupLi');
if(0 === j_container.find('dl.obu').length){
j_group.remove();
} else if(j_group.hasClass(n.C_EMPTY)) {
j_container.prev('.n-newMembers').
append(j_container.find('dl.obu:lt(14)').clone()).
append('<div class="c" />');
j_group.removeClass(n.C_EMPTY);
}
j_container.removeClass(n.C_ING);
});
}
function expand(j_t) {
var j_preview = j_t.find('.n-newMembers');
j_preview.hide();
j_t.find('.bd').show();
j_t.siblings('.' + n.C_ON).trigger(n.E_COLLAPSE);
j_t.addClass(n.C_ON).trigger(n.E_SCROLL);
}
function collapse(j_t) {
j_t.find('.bd').hide();
j_t.find('.n-newMembers').show();
j_t.removeClass(n.C_ON);
}
function process_tabs()
{
j_members_handle = j_tab_nav.find('a:first').clone().
attr('href','javascript:void(0)').
attr('id','#n-memberTabHandler').text('Group Members');
j_topics_handle = j_members_handle.clone().
addClass(n.C_ON).attr('id','#n-topicTabHandler').text('Topics');
j_members_handle.appendTo(j_tab_nav),
j_topics_handle.replaceAll(j_tab_nav.find('.now'));
j_members_handle.click(function(evt)
{
evt.preventDefault();
show_members_tab();
});
j_topics_handle.click(function()
{
j_members_bd.detach();
j_switches.detach();
j_topics.appendTo(j_pg);
j_topic_paginator.show();
j_topics_handle.addClass(n.C_ON);
j_members_handle.removeClass(n.C_ON);
});
}
function bind_handlers(){
j_members_bd.delegate(n.S_LI, n.E_EXPAND, function(e){
expand($(this));
}).
delegate(n.S_LI, n.E_COLLAPSE, function(e){
collapse($(this));
}).
delegate('.n-groupLi .n-toggle', 'click', function(e) {
var j_group = $(this).closest('.n-groupLi');
if(!j_group.hasClass(n.C_CUR)) {
j_members_bd.find(n.S_CUR).removeClass(n.C_CUR);
j_group.addClass(n.C_CUR);
}
j_group.trigger(n.E_TOGGLE);
}).delegate('.n-groupLi .paginator a', 'click', function(e) {
e.preventDefault();
var j_link = $(this);
load_members(j_link.closest('.bd'), j_link.attr('href'));
});
var j_only_new = j_switches.find('.n-only_new'),
j_only_local = j_switches.find('.n-only_local');
j_switches.on('click', '.n-only_new a.on', function(evt){
evt.preventDefault();
j_only_new.addClass('on');
n.show_only_new_members = true;
show_members_tab(true);
}).
on('click', '.n-only_new a.off', function(evt){
evt.preventDefault();
j_only_new.removeClass('on');
n.show_only_new_members = false;
show_members_tab(true);
}).
on('click', '.n-only_local a.on', function(evt){
evt.preventDefault();
j_only_local.addClass('on');
n.show_only_local_members = true;
show_members_tab(true);
}).
on('click', '.n-only_local a.off', function(evt){
evt.preventDefault();
j_only_local.removeClass('on');
n.show_only_local_members = false;
show_members_tab(true);
});
}
function init(){
j_tab_nav = $('.zbar>div');
j_topics = $('.olt');
j_pg = j_topics.closest('.indent');
j_topic_paginator = $('.paginator');
process_tabs();
bind_handlers();
n.bind_handlers(j_members_bd);
}
if(n.is_initialized){
init();
} else {
n.j_doc.bind(n.E_INIT_DONE, init);
}
})(jQuery);