-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbilibili-optimizer.user.js
256 lines (239 loc) · 6.39 KB
/
bilibili-optimizer.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
// ==UserScript==
// @name B 站优化
// @homepage https://github.com/FirokOtaku/CandyPot
// @namespace http://tampermonkey.net/
// @version 0.8.0
// @description 优化 B 站布局, 清理部分广告和无用内容
// @author Firok
// @match *.bilibili.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
// @grant none
// ==/UserScript==
/*
* - 0.8.0
* - 移除更多标题栏广告
* */
(function() {
'use strict'
setTimeout(() => {
const domStyle = document.createElement('style')
domStyle.innerHTML = `
.v-popover-content.header-favorite-popover
{
height: calc(100vh - 80px) !important;
max-height: calc(100vh - 80px) !important;
}
.video-sections-content-list
{
height: 400px !important;
min-height: 400px !important;
max-height: 400px !important;
}
.feed-card
{
margin-top: 0 !important;
}
.bili-feed4-layout
{
padding-bottom: 160px;
}
#nav-searchform
{
background-color: rgba(255, 255, 255, 0.1) !important
}
#nav-searchform:focus-within
{
background-color: rgba(255, 255, 255, 0.35) !important
}
.nav-search-content
{
background-color: rgba(255, 255, 255, 0.2) !important;
color: black !important;
}
.nav-search-content:focus-within
{
background-color: rgba(255, 255, 255, 0.8) !important;
}
.nav-search-input
{
background-color: transparent !important;
}
.search-panel
{
background-color: rgba(255, 255, 255, 0.9) !important;
}
.history-item
{
border: rgba(0, 0, 0, 0.1) 1px solid
}
.trending-item:hover
{
background: transparent !important;
color: var(--text_link);
}
`
document.head.appendChild(domStyle)
}, 1000)
function remove(dom)
{
dom.parentElement.removeChild(dom)
}
function hide(dom)
{
if(dom.style.display !== 'none')
{
dom.style.display = 'none'
dom.style.width = '0'
dom.style.height = '0'
dom.style.maxWidth = '0'
dom.style.maxHeight = '0'
dom.style.maxInlineSize = '0'
dom.style.maxBlockSize = '0'
return true
}
return false
}
function collectRemovingHeader()
{
function shouldRemove(text = '')
{
const listTextToRemove = [
'游戏中心',
'创作中心',
'会员购',
'漫画',
'直播',
'赛事',
'大会员',
'下载客户端',
'这一年',
'世冠',
'推荐服务',
// '动态',
'投稿',
'百大',
'来唱歌',
'大会员',
'时光',
'BML',
]
for(const textToRemove of listTextToRemove)
{
if(text === textToRemove)
return true
}
if(text.includes('来跨年'))
return true
return false
}
const ret = []
const listPopWrap = [
...document.getElementsByClassName('v-popover-wrap'),
...document.getElementsByClassName('right-entry-item'),
...document.getElementsByClassName('nav-link-item'),
]
for(const elePopWrap of listPopWrap)
{
if(shouldRemove(elePopWrap.textContent.trim()) || shouldRemove(elePopWrap.innerText.trim()))
{
ret.push({
type: `header`,
dom: elePopWrap,
caption: `Header - ${elePopWrap.textContent} - ${elePopWrap.innerText}`,
})
}
}
return ret
}
function collectRemovingCard()
{
const ret = []
const listLivingCard = [
...document.getElementsByClassName('bili-live-card'),
...document.getElementsByClassName('floor-single-card'),
]
for(const card of listLivingCard)
{
ret.push({
type: 'living',
dom: card,
caption: `Card - ${card.textContent}`
})
}
const listEmptyCard = [
...document.getElementsByClassName('bili-video-card'),
...document.getElementsByClassName('feed-card'),
]
for(const card of listEmptyCard)
{
if(card.innerText === '')
{
ret.push({
type: 'empty',
dom: card,
caption: `Empty - ${card.textContent}`,
})
}
}
return ret
}
function collectRemovingCarousel()
{
const ret = []
const list = [
...document.getElementsByClassName('carousel-area'),
...document.getElementsByClassName('recommended-swipe-core'),
...document.getElementsByClassName('recommended-swipe'),
]
for(const ca of list)
{
ret.push({
type: 'carousel',
dom: ca,
caption: `Carousel`,
})
}
return ret
}
function collectRemovingAd()
{
const ret = []
const list = [
...document.getElementsByClassName('ad-report'),
...document.getElementsByClassName('ad-floor-exp'),
...document.getElementsByClassName('adblock-tips'),
]
for(const ad of list)
{
ret.push({
type: 'ad',
dom: ad,
caption: `Ad - ${ad.textContent}`,
})
}
return ret
}
function collectBlocked()
{
;
}
const threadRemoval = setInterval(() => {
for(let info of [
...collectRemovingHeader(),
...collectRemovingCard(),
...collectRemovingCarousel(),
...collectRemovingAd(),
])
{
try
{
// remove(info.dom)
// console.log(`移除元素: `, info.caption)
if(hide(info.dom))
console.log(`隐藏元素: `, info.caption)
}
catch (ignored) { }
}
}, 2000)
console.log(`启动页面检查清理循环完成. 如有需要手动停止维护页面请执行:\nclearInterval(${threadRemoval})`)
})();