Skip to content

Commit

Permalink
改进数据存储方式,适配脚本猫
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzen committed Feb 9, 2022
1 parent de63cfd commit 66b2215
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ github: <https://github.com/kuzen/Bili-Recommended-List-Blocker>

greasyfork: <https://greasyfork.org/zh-CN/scripts/437528>

![20211224212815](https://s2.loli.net/2021/12/24/E4HL193jXkcWsdn.gif)
![演示](./sample.gif)

<!-- ![演示](https://s2.loli.net/2022/02/09/8UJ9CNxeXBQ1sin.gif) -->

## PS

Expand All @@ -32,7 +34,7 @@ location.reload();
## TODO

- 添加屏蔽关键词
- 添加取消按钮
- 监听黑名单改变,无需刷新即可生效


## Reference
Expand All @@ -44,3 +46,7 @@ location.reload();
屏蔽图:<https://t.bilibili.com/482652949960802810>

头像:<https://t.bilibili.com/441451749597806568>

## 交流

QQ群:415399492
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@
// @name b站首页黑名单 屏蔽首页视频
// @description 屏蔽b站首页推荐中的指定up
// @namespace https://github.com/kuzen
// @version 1.7.4
// @version 1.8.0
// @author kuzen
// @icon https://www.google.com/s2/favicons?domain=bilibili.com
// @run-at document-start
// @include *://www.bilibili.com/
// @include *://www.bilibili.com/?*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_addStyle
// @grant GM_log
// @grant GM_addElement
// @license MIT
// ==/UserScript==

/* ==UserConfig==
blockList:
uid:
title: uid黑名单
description: uid黑名单,注意若格式填写有问题则会影响脚本运行!格式为 ["xxx", "xxx"]
default: s[]
==/UserConfig== */
(function() {
'use strict';

Expand Down Expand Up @@ -493,7 +501,7 @@
// TODO
const uid = event.currentTarget.parentElement.getElementsByClassName('brlb-block-string')[0].value;
if (uid.length > 0) {
console.log(uid);
GM_log(uid);
this.blockList.add('uid', uid);
this.addItems('uid', uid);
}
Expand Down Expand Up @@ -846,14 +854,14 @@
}
if (uid != null) {
if (cardView.parentElement.dataset.blocked == '1') {
console.log(`${uid} 取消屏蔽`);
GM_log(`${uid} 取消屏蔽`);
this.blockList.remove('uid', uid.toString());
cardView = this.unblockCardView(cardView, id);
this.addBlockBtn(cardView);
this.setCardViewEvent(cardView);
} else {
if (this.blockList.add('uid', uid.toString()) === true){
console.log(`${uid} 已屏蔽`);
GM_log(`${uid} 已屏蔽`);
cardView = this.blockCardView(cardView, uid);
this.addBlockBtn(cardView);
this.setCardViewEvent(cardView);
Expand Down Expand Up @@ -907,6 +915,7 @@
return cv;
}

// TODO: 合并广告链接检测
getUid(cardView) {
const owner = cardView.getElementsByClassName('bili-video-card__info--owner')[0].href;
if (owner.length > 0) {
Expand Down Expand Up @@ -965,17 +974,29 @@

class BlockList {
constructor() {
this.list = JSON.parse(GM_getValue('blockList') || '{"uid":[],"username":[],"title":[]}');
// 历史遗留问题(
if (this.list instanceof Array) {
this.list = {'uid': this.list, 'username': [], 'title': []};
// 处理历史遗留问题(逃
this.list = JSON.parse(GM_getValue('blockList') || null);
if (this.list != null) {
if (this.list instanceof Array) {
this.list = {'uid': this.list, 'username': [], 'title': []};
}
Object.entries(this.list).forEach(([key, value]) => {
this.list[key] = this.list[key].sort();
this.removeDuplicates(key);
GM_setValue(`blockList.${key}`, JSON.stringify(this.list[key]));
});
GM_deleteValue(`blockList`);
}

// 新版本读取
this.list = {'uid': [], 'username': [], 'title': []};
Object.entries(this.list).forEach(([key, value]) => {
this.list[key] = JSON.parse(GM_getValue(`blockList.${key}`) || '[]');
this.list[key] = this.list[key].sort();
this.removeDuplicates(key);
});
console.log(`黑名单列表:`);
console.log(this.list);

GM_log(`黑名单列表:${JSON.stringify(this.list)}`);
}

length(key) {
Expand All @@ -990,7 +1011,7 @@
const index = this.search(key, item);
if (this.list[key][index] !== item) {
this.list[key].splice(index, 0, item);
GM_setValue('blockList', JSON.stringify(this.list));
GM_setValue(`blockList.${key}`, JSON.stringify(this.list[key]));
return true;
}
return false;
Expand All @@ -1000,15 +1021,17 @@
const index = this.search(key, item);
if (this.list[key][index] === item) {
this.list[key].splice(index, 1);
GM_setValue('blockList', JSON.stringify(this.list));
GM_setValue(`blockList.${key}`, JSON.stringify(this.list[key]));
return true;
}
return false;
}

clr() {
console.log(`清空黑名单`);
GM_setValue('blockList', '{"uid":[],"username":[],"title":[]}');
GM_log(`清空黑名单`);
GM_setValue('blockList.uid', '[]');
GM_setValue('blockList.username', '[]');
GM_setValue('blockList.title', '[]');
this.list = {'uid': [], 'username': [], 'title': []};
}

Expand Down
Binary file added sample.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 66b2215

Please sign in to comment.