-
Notifications
You must be signed in to change notification settings - Fork 1
/
bilibili-out-of-sight-out-of-mind.user.js
417 lines (399 loc) · 20.7 KB
/
bilibili-out-of-sight-out-of-mind.user.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
// ==UserScript==
// @name 哔哩哔哩 - 眼不见心不烦
// @namespace https://laji.blog
// @downloadURL https://github.com/xiaomai0830/bilibili-out-of-sight-out-of-mind/raw/master/dist/bilibili-out-of-sight-out-of-mind.user.js
// @updateURL https://github.com/xiaomai0830/bilibili-out-of-sight-out-of-mind/raw/master/dist/bilibili-out-of-sight-out-of-mind.user.js
// @version 0.1
// @description 根据关键词屏蔽b站首页或视频页的封面及标题
// @author MARV1N
// @match *://*.bilibili.com/
// @match *://*.bilibili.com/video/*
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @resource jquery-tagify https://cdn.jsdelivr.net/npm/@yaireo/[email protected]/dist/tagify.css
// @require https://cdn.jsdelivr.net/npm/@yaireo/[email protected]/dist/jQuery.tagify.min.js
// @resource jquery-modal https://cdn.jsdelivr.net/npm/[email protected]/jquery.modal.min.css
// @require https://cdn.jsdelivr.net/npm/[email protected]/jquery.modal.min.js
// @grant GM_getValue
// @grant GM_setValue
// @grant GM.info
// @grant GM_addStyle
// @grant GM_getResourceText
// @run-at document-end
// @icon https://i0.hdslb.com/bfs/album/e6a300cda376c01a948abbad9f19a14ccb6e488d.png
// ==/UserScript==
const jqueryTagifyCss = GM_getResourceText ("jquery-tagify");
const jqueryModalCss = GM_getResourceText ("jquery-modal");
GM_addStyle (jqueryTagifyCss);
GM_addStyle (jqueryModalCss);
GM_addStyle('\
.bilibili-out-of-sight-out-of-mind{\
-webkit-filter: grayscale(100%);\
-moz-filter: grayscale(100%);\
-ms-filter: grayscale(100%);\
-o-filter: grayscale(100%);\
filter: grayscale(100%);\
filter: gray;\
/*opacity: 0.4;*/\
cursor: no-drop;\
pointer-events: none;\
}\
.bilibili-out-of-sight-out-of-mind img{\
content: url("https://i0.hdslb.com/bfs/archive/be27fd62c99036dce67efface486fb0a88ffed06.jpg");\
}\
.recommend-box .video-card-reco.bilibili-out-of-sight-out-of-mind .info-box .info .title,\
.extension .ext-box .video-card-common.ex-card-common.bilibili-out-of-sight-out-of-mind .card-pic .ex-title,\
#bili_report_live .live-list .zone-list-box .live-card.bilibili-out-of-sight-out-of-mind .up .txt .desc,\
.card-list .zone-list-box .video-card-common.bilibili-out-of-sight-out-of-mind .title,\
.manga-list-box .manga-card.bilibili-out-of-sight-out-of-mind .manga-title,\
.article-list .zone-list-box .article-card.bilibili-out-of-sight-out-of-mind .title,\
.rank-list .rank-wrap.bilibili-out-of-sight-out-of-mind p[title],\
.pgc-rank .pgc-rank-wrap.bilibili-out-of-sight-out-of-mind .txt .title,\
.manga-rank .manga-rank-wrap .manga-rank-list .manga-rank-item.bilibili-out-of-sight-out-of-mind .title,\
#bili_read .rank-list .rank-wrap.bilibili-out-of-sight-out-of-mind .preview .txt p[title],\
#bili_read .rank-list .rank-wrap.bilibili-out-of-sight-out-of-mind .title,\
#reco_list .rec-list .video-page-card.bilibili-out-of-sight-out-of-mind .card-box .info .title{\
visibility: hidden;\
/*display: inline-block;*/\
}\
.recommend-box .video-card-reco.bilibili-out-of-sight-out-of-mind .info-box .info .title:before,\
.extension .ext-box .video-card-common.ex-card-common.bilibili-out-of-sight-out-of-mind .card-pic .ex-title:before,\
#bili_report_live .live-list .zone-list-box .live-card.bilibili-out-of-sight-out-of-mind .up .txt .desc:before,\
.card-list .zone-list-box .video-card-common.bilibili-out-of-sight-out-of-mind .title:before,\
.manga-list-box .manga-card.bilibili-out-of-sight-out-of-mind .manga-title:before,\
.article-list .zone-list-box .article-card.bilibili-out-of-sight-out-of-mind .title:before,\
.rank-list .rank-wrap.bilibili-out-of-sight-out-of-mind p[title]:before,\
.pgc-rank .pgc-rank-wrap.bilibili-out-of-sight-out-of-mind .txt .title:before,\
.manga-rank .manga-rank-wrap .manga-rank-list .manga-rank-item.bilibili-out-of-sight-out-of-mind .title:before,\
#bili_read .rank-list .rank-wrap.bilibili-out-of-sight-out-of-mind .preview .txt p[title]:before,\
#bili_read .rank-list .rank-wrap.bilibili-out-of-sight-out-of-mind .title:before,\
#reco_list .rec-list .video-page-card.bilibili-out-of-sight-out-of-mind .card-box .info .title:before{\
content:"已屏蔽该内容";\
visibility: visible;\
}\
.recommend-box .video-card-reco.bilibili-out-of-sight-out-of-mind .info-box .info .up,\
.extension .ext-box .video-card-common.ex-card-common.bilibili-out-of-sight-out-of-mind .ex-up,\
#bili_report_live .live-list .zone-list-box .live-card.bilibili-out-of-sight-out-of-mind .up .txt .name,\
.card-list .zone-list-box .video-card-common.bilibili-out-of-sight-out-of-mind .up,\
.article-list .zone-list-box .article-card.bilibili-out-of-sight-out-of-mind .up,\
.rank-list .rank-wrap.bilibili-out-of-sight-out-of-mind .popover-video-card .content .info .subtitle .name,\
#reco_list .rec-list .video-page-card.bilibili-out-of-sight-out-of-mind .card-box .info .up{\
visibility: hidden;\
/*display: inline-block;*/\
/*display: block;*/\
display: grid;\
}\
.recommend-box .video-card-reco.bilibili-out-of-sight-out-of-mind .info-box .info .up:before,\
.extension .ext-box .video-card-common.ex-card-common.bilibili-out-of-sight-out-of-mind .ex-up:before,\
#bili_report_live .live-list .zone-list-box .live-card.bilibili-out-of-sight-out-of-mind .up .txt .name:before,\
.card-list .zone-list-box .video-card-common.bilibili-out-of-sight-out-of-mind .up:before,\
.article-list .zone-list-box .article-card.bilibili-out-of-sight-out-of-mind .up:before,\
.rank-list .rank-wrap.bilibili-out-of-sight-out-of-mind .popover-video-card .content .info .subtitle .name:before,\
#reco_list .rec-list .video-page-card.bilibili-out-of-sight-out-of-mind .card-box .info .up:before{\
//content:"已屏蔽该UP主";\
//visibility: visible;\
}\
.bilibili-out-of-sight-out-of-mind-setting-modal{\
display: none;\
vertical-align: middle;\
position: relative;\
z-index: 2;\
max-width: 500px;\
box-sizing: border-box;\
width: 90%;\
background: #fff;\
padding: 15px 30px;\
-webkit-border-radius: 8px;\
-moz-border-radius: 8px;\
-o-border-radius: 8px;\
-ms-border-radius: 8px;\
border-radius: 8px;\
-webkit-box-shadow: 0 0 10px #000;\
-moz-box-shadow: 0 0 10px #000;\
-o-box-shadow: 0 0 10px #000;\
-ms-box-shadow: 0 0 10px #000;\
box-shadow: 0 0 10px #000;\
text-align: left;\
}\
');
(function() {
'use strict';
let blocking = false;
let blockTitleKeywordsList = [];
let blockUpNameKeywordsList = [];
let resetSelectorList1 = [
".video-card-reco", // 推荐
];
let resetSelectorList2 = [
".video-card-reco", // 推荐
".video-card-common.ex-card-common", // 推广
".live-card", // 直播
".video-card-common", // 普通视频
".manga-card", // 漫画
".article-card", // 专栏
".rank-list .rank-wrap", // 排行榜-普通视频
".pgc-rank-wrap", // 排行榜-PGC
".manga-rank-item", // 排行榜-漫画
"#bili_read .rank-wrap", // 排行榜-专栏
"#reco_list .rec-list .video-page-card", // 视频详情页-推荐
];
let titleSelectorList = [
{selector:".recommend-box .video-card-reco .info-box .info p[title]", closest:".video-card-reco", up:".info-box .info .up" }, // 推荐
{selector:".extension .ext-box .video-card-common.ex-card-common .card-pic .ex-title", closest:".video-card-common.ex-card-common", up:".ex-up"}, // 推广
{selector:"#bili_report_live .live-list .zone-list-box .live-card .up .txt .desc", closest:".live-card", up:".up .txt .name"}, // 直播
{selector:".card-list .zone-list-box .video-card-common .title", closest:".video-card-common", up:".up"}, // 普通视频
{selector:".manga-list-box .manga-card .manga-title", closest:".manga-card"}, // 漫画
{selector:".article-list .zone-list-box .article-card .title", closest:".article-card", up:".up"}, // 专栏
{selector:".rank-list .rank-wrap p[title]", closest:".rank-wrap", up:".info .subtitle .name"}, // 排行榜-普通视频
//{selector:".rank-list .rank-wrap .popover-video-card .content .info .f-title", closest:".rank-wrap", up:".info .subtitle .name"}, // 排行榜-普通视频
{selector:".pgc-rank .pgc-rank-wrap .txt .title", closest:".pgc-rank-wrap"}, // 排行榜-PGC
{selector:".manga-rank .manga-rank-wrap .manga-rank-list .manga-rank-item .title", closest:".manga-rank-item"}, // 排行榜-漫画
{selector:"#bili_read .rank-list .rank-wrap .preview .txt p[title],#bili_read .rank-list .rank-wrap .title", closest:".rank-wrap"}, // 排行榜-专栏
{selector:"#reco_list .rec-list .video-page-card .card-box .info .title", closest:".video-page-card", up:".card-box .info .up" }, // 视频详情页-推荐
];
let upSelectorList = [
{selector:".recommend-box .video-card-reco .info-box .info .up", closest:".video-card-reco", title:".info-box .info p[title]"}, // 推荐
{selector:".extension .ext-box .video-card-common.ex-card-common .ex-up", closest:".video-card-common.ex-card-common", title:".ex-title"}, // 推广
{selector:"#bili_report_live .live-list .zone-list-box .live-card .up .txt .name", closest:".live-card", title:".up .txt .desc"}, // 直播
{selector:".card-list .zone-list-box .video-card-common .up", closest:".video-card-common", title:".title"}, // 普通视频
{selector:".article-list .zone-list-box .article-card .up", closest:".article-card", title:".title"}, // 专栏
{selector:".rank-list .rank-wrap .popover-video-card .content .info .subtitle .name", closest:".rank-wrap", title:".info .f-title"}, // 排行榜-普通视频
{selector:"#reco_list .rec-list .video-page-card .card-box .info .up", closest:".video-page-card", title:".card-box .info .title" }, // 视频详情页-推荐
];
function resetBlock(list=resetSelectorList1){
// 重置
$.each(list, function(rs_index, rs_item){
if($(rs_item).hasClass("bilibili-out-of-sight-out-of-mind")){
$(rs_item).removeClass("bilibili-out-of-sight-out-of-mind");
}
});
}
function runBlock(){
//console.log("开始屏蔽");
blocking = true;
// 标题
$.each(titleSelectorList, function(ts_index, ts_item){
$(ts_item.selector).each(function(td_index,td_item){
const titleText = td_item.innerText
//console.log(titleText);
$.each(blockTitleKeywordsList,function(bt_index,bt_item){
if($(td_item.closest(ts_item.closest)).hasClass("bilibili-out-of-sight-out-of-mind")){
$(td_item.closest(ts_item.closest)).remove("bilibili-out-of-sight-out-of-mind");
}
if(titleText.search(bt_item) !== -1){
if(!$(td_item.closest(ts_item.closest)).hasClass("bilibili-out-of-sight-out-of-mind")){
$(td_item.closest(ts_item.closest)).addClass("bilibili-out-of-sight-out-of-mind");
}
}else{
}
});
});
});
// up主
$.each(upSelectorList, function(us_index, us_item){
$(us_item.selector).each(function(ud_index,ud_item){
const upNameText = ud_item.innerText
//console.log(upNameText);
$.each(blockUpNameKeywordsList,function(bu_index,bu_item){
if(upNameText.search(bu_item) !== -1){
if(!$(ud_item.closest(us_item.closest)).hasClass("bilibili-out-of-sight-out-of-mind")){
$(ud_item.closest(us_item.closest)).addClass("bilibili-out-of-sight-out-of-mind");
}
}else {
}
});
});
});
blocking = false;
//console.log("屏蔽结束");
}
let observer = new MutationObserver(function (mutationsList) {
// mutationsList参数是个MutationRecord对象数组,描述了每个发生的变化
if(blocking) return;
mutationsList.forEach(function (mutation) {
//console.log(mutation);
// 变化的类型
switch(mutation.type) {
case "childList":
// 子节点的变动
resetBlock();
runBlock();
break;
case 'characterData':
// 文本内容变化
resetBlock();
runBlock();
break;
case "subtree":
// 所有后代节点的变动
resetBlock();
runBlock();
break;
}
});
});
// 观察除了特性之外的所有变动
//observer.observe(document.body, {
//observer.observe(document.querySelectorAll(".first-screen.b-wrap,.storey-box.b-wrap"), {
let watchingDom = undefined;
if(document.querySelectorAll(".international-home")[0] != undefined){
watchingDom = document.querySelectorAll(".international-home")[0];
}else if(document.querySelectorAll("#reco_list")[0] != undefined){
watchingDom = document.querySelectorAll("#reco_list")[0];
}
observer.observe(watchingDom, {
childList: true, // Boolean 观察子节点的变动
//attributes: true, // Boolean 观察属性的变动
characterData: true, // Boolean 观察节点内容或节点文本的变动
subtree: true, // Boolean 观察所有后代节点的变动
//attributeOldValue: true, // Boolean 当观察到attributes变动时,是否记录变动前的属性值
//characterDataOldValue: true, // Boolean 当观察到characterData变动时,是否记录变动前的属性值
//attributeFilter: ["src"], // Array 指定需要观察的特定属性(比如[‘src’, ‘rows’]),不在此数组中的属性变化时将被忽略
});
// 停止跟踪变动
// observer.disconnect();
// 处理未处理的变动
// let mutationRecords = observer.takeRecords();
$(".international-footer .link-box .link-item.link-a ul").append('<a href="javascript:void(0);" style="margin-top: 3px;" class="setting-button-bilibili-out-of-sight-out-of-mind">设置黑名单</a>');
$("body").append('<div class="bilibili-out-of-sight-out-of-mind-setting-modal"><p>双击编辑,回车保存。</p><br><p>标题关键词:</p><input id="bilibili-out-of-sight-out-of-mind-tags-input-title" value="" /><p><br>up主关键词:</p><input id="bilibili-out-of-sight-out-of-mind-tags-input-up-name" value="" /></div>')
$(".setting-button-bilibili-out-of-sight-out-of-mind").on("click",function(){$(".bilibili-out-of-sight-out-of-mind-setting-modal").modal({fadeDuration: 100});});
$(".bilibili-out-of-sight-out-of-mind-setting-modal").on($.modal.BEFORE_OPEN, function(event, modal) {
//console.log("before open modal");
//GM_getValue("bilibili_out_of_sight_out_of_mind_block_title_keywords")
//GM_getValue("bilibili_out_of_sight_out_of_mind_block_up_name_keywords")
//tagifyTitle.removeAllTags();
//tagifyUpName.removeAllTags();
//tagifyTitle.addTags(JSON.parse(GM_getValue("bilibili_out_of_sight_out_of_mind_block_title_keywords")));
//tagifyUpName.addTags(JSON.parse(GM_getValue("bilibili_out_of_sight_out_of_mind_block_up_name_keywords")));
});
$(".bilibili-out-of-sight-out-of-mind-setting-modal").on($.modal.CLOSE, function(event, modal) {
//console.log("close modal");
//console.log(blockTitleKeywordsList);
//console.log(blockUpNameKeywordsList);
blocking = false;
resetBlock(resetSelectorList2);
runBlock();
});
//function onAddTag(e, tagData){
// console.log("e: ", e);
// console.log("onAddTag: ", e.detail);
// console.log("original input value: ", tagInputElm.value)
//}
//function onRemoveTag(e){
// console.log("e: ", e);
// console.log("onRemoveTag:", e.detail, "tagify instance value:", tagify.value)
// console.log("original input value: ", tagInputElm.value)
//}
//function onTagEdit(e){
// console.log("e: ", e);
// console.log("onTagEdit: ", e.detail);
// console.log("original input value: ", tagInputElm.value)
//}
function onTagTitleChange(e){
//console.log("title~");
//console.log("e: ", e);
//console.log("onTagChange: ", e.detail);
//console.log("original input value: ", tagInputTitleElm.value);
GM_setValue("bilibili_out_of_sight_out_of_mind_block_title_keywords",tagInputTitleElm.value);
//console.log("bilibili_out_of_sight_out_of_mind_block_title_keywords:", GM_getValue("bilibili_out_of_sight_out_of_mind_block_title_keywords"));
if(tagInputTitleElm.value != ""){
const arrValue = JSON.parse(tagInputTitleElm.value);
let _temp = [];
try{
$.each(arrValue, function(index,item){
_temp.push(item.value);
});
}catch(e){
_temp = [];
}
blockTitleKeywordsList = _temp;
}else{
blockTitleKeywordsList = [];
}
}
function onTagUpNameChange(e){
//console.log("up name~");
//console.log("e: ", e);
//console.log("onTagChange: ", e.detail);
//console.log("original input value: ", tagInputUpNameElm.value);
GM_setValue("bilibili_out_of_sight_out_of_mind_block_up_name_keywords",tagInputUpNameElm.value);
if(tagInputUpNameElm.value != ""){
const arrValue = JSON.parse(tagInputUpNameElm.value);
let _temp = [];
try{
$.each(arrValue, function(index,item){
_temp.push(item.value);
});
}catch(e){
_temp = [];
}
blockUpNameKeywordsList = _temp;
}else{
blockUpNameKeywordsList = [];
}
}
let tagInputTitleElm = document.querySelector('#bilibili-out-of-sight-out-of-mind-tags-input-title');
let tagInputUpNameElm = document.querySelector('#bilibili-out-of-sight-out-of-mind-tags-input-up-name');
let tagifyTitle = new Tagify(tagInputTitleElm, {});
let tagifyUpName = new Tagify(tagInputUpNameElm, {});
//tagify.on('add', onAddTag);
//tagify.on('remove', onRemoveTag);
//tagify.on('edit:updated', onTagEdit);
tagifyTitle.on('change', onTagTitleChange);
tagifyUpName.on('change', onTagUpNameChange);
const blockTitleKeywordsListValue = GM_getValue("bilibili_out_of_sight_out_of_mind_block_title_keywords");
//console.log("blockTitleKeywordsListValue:",blockTitleKeywordsListValue);
if(blockTitleKeywordsListValue) {
if(blockTitleKeywordsListValue != ""){
const arrValue = JSON.parse(blockTitleKeywordsListValue);
let _temp = [];
try{
$.each(arrValue, function(index,item){
_temp.push(item.value);
});
tagifyTitle.removeAllTags();
tagifyTitle.addTags(arrValue);
}catch(e){
//console.log(e);
GM_setValue("bilibili_out_of_sight_out_of_mind_block_title_keywords","");
_temp = [];
}
blockTitleKeywordsList = _temp;
resetBlock();
runBlock();
//console.log("blockTitleKeywordsList:",blockTitleKeywordsList);
}else{
GM_setValue("bilibili_out_of_sight_out_of_mind_block_title_keywords","");
blockTitleKeywordsList = [];
}
}else {
GM_setValue("bilibili_out_of_sight_out_of_mind_block_title_keywords","");
blockTitleKeywordsList = [];
}
const blockUpNameKeywordsListValue = GM_getValue("bilibili_out_of_sight_out_of_mind_block_up_name_keywords");
//console.log("blockUpNameKeywordsListValue:",blockUpNameKeywordsListValue);
if(blockUpNameKeywordsListValue) {
if(blockUpNameKeywordsListValue != ""){
const arrValue = JSON.parse(blockUpNameKeywordsListValue);
let _temp = [];
try{
$.each(arrValue, function(index,item){
_temp.push(item.value);
});
tagifyUpName.removeAllTags();
tagifyUpName.addTags(arrValue);
}catch(e){
GM_setValue("bilibili_out_of_sight_out_of_mind_block_up_name_keywords","");
_temp = [];
}
blockUpNameKeywordsList = _temp;
resetBlock();
runBlock();
}else{
GM_setValue("bilibili_out_of_sight_out_of_mind_block_up_name_keywords","");
blockUpNameKeywordsList = [];
}
}else {
GM_setValue("bilibili_out_of_sight_out_of_mind_block_up_name_keywords","");
blockUpNameKeywordsList = [];
}
})();