-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
130 lines (127 loc) · 3.76 KB
/
script.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
// ==UserScript==
// @name bilibili视频选集拉长-删去前缀-tampermonkey-removePrefix-bilibili
// @namespace https://github.com/SoonIter/tampermonkey-removePrefix-bilibili
// @version 0.7
// @description 一个脚本解决bilibili视频分集的过长的问题
// @author SoonIter
// @match https://www.bilibili.com/video/**
// @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
// @grant none
// @license MIT
// ==/UserScript==
(function () {
//使用网站
let wrap = true; // 如果为true,则 “视频选集” 的文字换行
const configs = [
{
h1Title: '2022版Flink1.13实战教程', // 标题
reg: /\d{2,}_(第(.*)章_)?/, // 删除的前缀
},
{
h1Title: '尚硅谷Java入门视频教程',
reg: /\d{2,}\.尚硅谷\_/,
},
];
let flag = false; //是否已经执行
function modifyCss() {
let styleDom = document.createElement('style');
styleDom.innerHTML = `
.video-episode-card__info-title{
white-space:normal !important;
max-height:100px !important;
}
.video-episode-card {
height:auto !important;
min-height:auto !important;
}
.video-section-list{
height:auto !important;
min-height:auto !important;
}
.video-episode-card__info{
height:auto !important;
min-height:auto !important;
}
.video-sections-content-list{
height:auto !important;
max-height:500px !important;
}
/* 去广告 */
.vcd,#bannerAd,.video-page-special-card-small {
height: 0px !important;
width: 0px !important;
overflow: hidden;
}
`;
document.head.appendChild(styleDom);
document.querySelectorAll('span.part').forEach(ele => {
ele.style.whiteSpace = 'normal';
ele.style.lineHeight = '20px';
});
document
.querySelectorAll('.multi-page-v1 .cur-list .list-box li')
.forEach(ele => {
ele.style.height = 'auto';
});
}
function doIt() {
try {
flag === false &&
(function () {
wrap && modifyCss();
const title = document.querySelector('h1').title;
const item = configs.find(i => title.search(i.h1Title) !== -1);
if (item === undefined) {
return;
}
const { h1Title, reg } = item;
let arr = [];
const parts = document.querySelectorAll('div.link-content');
for (const parentDom of parts) {
const Px = parentDom.querySelector('span.page-num');
arr.push(Px.innerHTML);
arr.push(' ');
const dom = parentDom.querySelector('span.part');
const content = dom.innerHTML;
const newContent = content.replace(reg, '');
dom.innerHTML = newContent;
arr.push(newContent);
arr.push('\n');
}
console.log(
'%c tampermonkey-removePrefix-bilibili:执行脚本成功:',
'color:white;background:green;',
arr.join(''),
);
})();
flag = true;
} catch (err) {
console.log(
'%c tampermonkey-removePrefix-bilibili:发生未知错误:',
'color:white;background:red;',
err.message,
);
}
}
const callback = function (records) {
if (flag !== false) {
return;
}
records.forEach(function (record) {
const dom = record.target;
const { className } = dom;
if (
typeof className === 'string' &&
className.includes('right-container')
) {
doIt();
}
});
};
const observer = new MutationObserver(callback);
const observeDOM = document.body;
observer.observe(observeDOM, {
childList: true,
subtree: true,
});
})();