-
Notifications
You must be signed in to change notification settings - Fork 477
/
wb_ad.js
293 lines (278 loc) · 9.34 KB
/
wb_ad.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
/*
README:https://github.com/yichahucha/surge/tree/master
*/
const path1 = "/groups/timeline";
const path2 = "/statuses/unread";
const path3 = "/statuses/extend";
const path4 = "/comments/build_comments";
const path5 = "/photo/recommend_list";
const path6 = "/stories/video_stream";
const path7 = "/statuses/positives/get";
const path8 = "/stories/home_list";
const path9 = "/profile/statuses";
const path10 = "/statuses/friends/timeline";
const path11 = "/service/picfeed";
const path12 = "/fangle/timeline";
const path13 = "/searchall";
const path14 = "/cardlist";
const path15 = "/statuses/video_timeline";
const path16 = "/page";
const path17 = "/statuses/friends_timeline";
const path18 = "/!/photos/pic_recommend_status";
const path19 = "/statuses/video_mixtimeline";
const path20 = "/video/tiny_stream_video_list";
const path21 = "/photo/info";
const path22 = "/live/media_homelist";
const path23 = "/remind/unread_count";
const path24 = "/search/container_timeline"
const path25 = "/messageflow/notice"
const path26 = "/statuses/container_timeline_hot"
const path27 = "/search/finder"
const path28 = "/statuses/container_timeline_unread"
const path29 = "/statuses/container_timeline"
const path30 = "/profile/container_timeline"
const url = $request.url;
let body = $response.body;
if (
url.indexOf(path1) != -1 ||
url.indexOf(path2) != -1 ||
url.indexOf(path10) != -1 ||
url.indexOf(path15) != -1 ||
url.indexOf(path17) != -1 ||
url.indexOf(path20) != -1
) {
let obj = JSON.parse(body);
if (obj.statuses) obj.statuses = filter_timeline_statuses(obj.statuses);
if (obj.advertises) obj.advertises = [];
if (obj.ad) obj.ad = [];
if (obj.num) obj.num = obj.original_num;
if (obj.trends) obj.trends = [];
body = JSON.stringify(obj);
} else if (url.indexOf(path3) != -1) {
let obj = JSON.parse(body);
if (obj.trend) delete obj.trend;
body = JSON.stringify(obj);
} else if (url.indexOf(path4) != -1) {
let obj = JSON.parse(body);
obj.recommend_max_id = 0;
if (obj.status) {
if (obj.top_hot_structs) {
obj.max_id = obj.top_hot_structs.call_back_struct.max_id;
delete obj.top_hot_structs;
}
if (obj.datas) obj.datas = filter_comments(obj.datas);
} else {
obj.datas = [];
}
body = JSON.stringify(obj);
} else if (url.indexOf(path5) != -1 || url.indexOf(path18) != -1) {
let obj = JSON.parse(body);
obj.data = {};
body = JSON.stringify(obj);
} else if (url.indexOf(path6) != -1) {
let obj = JSON.parse(body);
let segments = obj.segments;
if (segments && segments.length > 0) {
let i = segments.length;
while (i--) {
const element = segments[i];
let is_ad = element.is_ad;
if (is_ad && is_ad == true) segments.splice(i, 1);
}
}
body = JSON.stringify(obj);
} else if (url.indexOf(path7) != -1) {
let obj = JSON.parse(body);
obj.datas = [];
body = JSON.stringify(obj);
} else if (url.indexOf(path8) != -1) {
let obj = JSON.parse(body);
obj.story_list = [];
body = JSON.stringify(obj);
} else if (url.indexOf(path11) != -1 || url.indexOf(path22) != -1) {
let obj = JSON.parse(body);
obj.data = [];
body = JSON.stringify(obj);
} else if (
url.indexOf(path9) != -1 ||
url.indexOf(path12) != -1 ||
url.indexOf(path13) != -1 ||
url.indexOf(path14) != -1 ||
url.indexOf(path16) != -1
) {
let obj = JSON.parse(body);
if (obj.cards) obj.cards = filter_timeline_cards(obj.cards);
body = JSON.stringify(obj);
} else if (url.indexOf(path19) != -1) {
let obj = JSON.parse(body);
delete obj.expandable_view;
if (obj.hasOwnProperty("expandable_views")) delete obj.expandable_views;
body = JSON.stringify(obj);
} else if (url.indexOf(path21) != -1) {
if (body.indexOf("ad_params") != -1) {
body = JSON.stringify({});
}
} else if (url.indexOf(path23) != -1) {
let obj = JSON.parse(body);
obj.video = {};
body = JSON.stringify(obj);
} else if (url.indexOf(path24) != -1) {
let obj = JSON.parse(body);
filter_items_feed(obj)
body = JSON.stringify(obj);
} else if (url.indexOf(path25) != -1) {
let obj = JSON.parse(body);
filter_messageflow_notice(obj)
body = JSON.stringify(obj);
} else if ( url.indexOf(path30) != -1 || url.indexOf(path26) != -1 || url.indexOf(path28) != -1 || url.indexOf(path29) != -1) {
let obj = JSON.parse(body);
filter_items_feed(obj)
body = JSON.stringify(obj);
} else if (url.indexOf(path27) != -1) {
let obj = JSON.parse(body);
filter_search_finder(obj)
body = JSON.stringify(obj);
}
$done({ body });
function filter_search_finder(data) {
channels = data["channelInfo"]["channels"]
for (let index = 0; index < channels.length; index++) {
const element = channels[index];
if (element["en_name"] == "Discover") {
filter_finder_items(element["payload"])
}
}
}
function filter_finder_items(data) {
items = data["items"]
for (let index = items.length-1; index >= 0; index--) {
const item = items[index];
if (item["category"] == "card") {
type = item["data"]["card_type"]
if (type == 118) {
items.splice(index,1)
}
}else if (item["category"] == "feed") {
type = item["data"]["mblogtype"]
if (type == 1) {
items.splice(index,1)
}
}
}
}
function filter_messageflow_notice(data) {
items = data["messages"]
for (let index = items.length-1; index >= 0; index--) {
const item = items[index];
if (item["isrecommend"] == true) {
items.splice(index,1)
}
}
}
function filter_items_feed(data) {
items = data["items"]
for (let index = items.length-1; index >= 0; index--) {
const item = items[index];
if (item["category"] == "feed") {
type = item["data"]["mblogtype"]
if (type == 1) {
items.splice(index,1)
}
}
}
}
function filter_timeline_statuses(statuses) {
if (statuses && statuses.length > 0) {
let i = statuses.length;
while (i--) {
let element = statuses[i];
if (
is_timeline_likerecommend(element.title) ||
is_timeline_ad(element) ||
is_stream_video_ad(element)
) {
statuses.splice(i, 1);
}
}
}
return statuses;
}
function filter_comments(datas) {
if (datas && datas.length > 0) {
let i = datas.length;
while (i--) {
const element = datas[i];
const type = element.type;
if (type == 5 || type == 1 || type == 6) datas.splice(i, 1);
}
}
return datas;
}
function filter_timeline_cards(cards) {
if (cards && cards.length > 0) {
let j = cards.length;
while (j--) {
let item = cards[j];
let card_group = item.card_group;
if (card_group && card_group.length > 0) {
if (item.itemid && item.itemid == "hotword") {
filter_top_search(card_group);
} else {
let i = card_group.length;
while (i--) {
let card_group_item = card_group[i];
let card_type = card_group_item.card_type;
if (card_type) {
if (card_type == 9) {
if (is_timeline_ad(card_group_item.mblog))
card_group.splice(i, 1);
} else if (card_type == 118 || card_type == 89) {
card_group.splice(i, 1);
} else if (card_type == 42) {
if (
card_group_item.desc ==
"\u53ef\u80fd\u611f\u5174\u8da3\u7684\u4eba"
) {
cards.splice(j, 1);
break;
}
} else if (card_type == 17) {
filter_top_search(card_group_item.group);
}
}
}
}
} else {
let card_type = item.card_type;
if (card_type && card_type == 9) {
if (is_timeline_ad(item.mblog)) cards.splice(j, 1);
}
}
}
}
return cards;
}
function filter_top_search(group) {
if (group && group.length > 0) {
let k = group.length;
while (k--) {
let group_item = group[k];
if (group_item.hasOwnProperty("promotion")) {
group.splice(k, 1);
}
}
}
}
function is_timeline_ad(mblog) {
if (!mblog) return false;
let promotiontype =
mblog.promotion && mblog.promotion.type && mblog.promotion.type == "ad";
let mblogtype = mblog.mblogtype && mblog.mblogtype == 1;
return promotiontype || mblogtype ? true : false;
}
function is_timeline_likerecommend(title) {
return title && title.type && title.type == "likerecommend" ? true : false;
}
function is_stream_video_ad(item) {
return item.ad_state && item.ad_state == 1;
}