forked from MotooriKashin/Bilibili-Old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.user.js
212 lines (206 loc) · 11 KB
/
module.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
// ==UserScript==
// @name Bilibili 旧版界面
// @namespace MotooriKashin
// @version 1.0.1
// @description Bilibili 播放页的模块化版本,可能不支持版本太低的浏览器。
// @author MotooriKashin, wly5556
// @supportURL https://github.com/MotooriKashin/Bilibili-Old/issues
// @match *://*.bilibili.com/*
// @connect bilibili.com
// @connect *
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/protobuf.min.js
// @icon https://static.hdslb.com/images/favicon.ico
// @resource av https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/av.html
// @resource watchlater https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/watchlater.html
// @resource bangumi https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/bangumi.html
// @resource cinema https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/cinema.html
// @resource playlist https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/playlist.html
// @resource playlistdetail https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/playlistdetail.html
// @resource index https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/index.html
// @resource ranking https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/ranking.html
// @resource css https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/ui.css
// @resource crc https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/crc.js
// @resource md5 https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/md5.js
// @resource iniState https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/__INITIAL_STATE__.js
// @resource ui https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/ui.js
// @resource debug https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/debug.js
// @resource xhr https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/xhr.js
// @resource download https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/download.js
// @resource rewrite https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/rewrite.js
// @resource define https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/define.js
// @resource reset https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/reset.js
// @resource xhrhook https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/xhrhook.js
// @resource config https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/config.json
// @resource playlistjson https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/playlist.json
// @resource sort https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/sort.json
// @resource search https://raw.githubusercontent.com/MotooriKashin/Bilibili-Old/master/src/search.json
// @grant GM_xmlhttpRequest
// @grant GM_getResourceText
// @grant GM_getResourceURL
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @run-at document-start
// @license MIT License
// ==/UserScript==
(function () {
'use strict';
// 获取默认设置
const config = JSON.parse(GM_getResourceText("config"));
// 暴露protobuf接口
unsafeWindow.protobuf = window.protobuf;
let aid, cid, bvid;
// 暴露顶层接口
const BLOD = unsafeWindow.BLOD = {
xmlhttpRequest: GM_xmlhttpRequest,
setValue: GM_setValue,
getValue: GM_getValue,
getResourceText: GM_getResourceText,
getResourceURL: GM_getResourceURL,
deleteValue: GM_deleteValue,
aid: aid,
cid: cid,
bvid: bvid,
hash: [],
ids: [],
bloburl: {}
}
// 导入全局模块,其他模块按需加载
new Function(GM_getResourceText("debug"))();
new Function(GM_getResourceText("xhr"))();
new Function(GM_getResourceText("define"))();
new Function(GM_getResourceText("iniState"))();
const debug = BLOD.debug;
const xhr = BLOD.xhr;
// 修复退出登录功能
if (location.href.includes("bilibili.com/login?act=exit")) {
(async () => {
let refer = document.referrer;
await xhr.post("https://passport.bilibili.com/login/exit/v2", "", "biliCSRF=" + BLOD.getCookies().bili_jct);
location.href = refer;
})();
}
// 初始化配置数据
let localConfig = BLOD.getValue("config");
let configSort = ["rewrite", "reset"];
BLOD.defaultConfig = JSON.parse(JSON.stringify(config));
for (let key in config) if (configSort.indexOf(key) < 0) delete config[key];
if (localConfig) {
configSort.forEach(x => {
for (let key in localConfig[x]) if (key in config[x]) config[x][key] = localConfig[x][key];
})
} else {
configSort.forEach(x => {
for (let key in config[x]) config[x][key] = config[x][key][0];
})
BLOD.setValue("config", config);
}
BLOD.config = config;
new Function(GM_getResourceText("reset"))();
// 处理参数及BV号
BLOD.reset.parameterTrim();
BLOD.uid = BLOD.getCookies().DedeUserID;
BLOD.path = document.location.href.split('/');
// 捕获window属性
BLOD.reset.getVariable();
if (BLOD.uid) {
let offset = BLOD.getCookies()["bp_video_offset_" + BLOD.uid];
if (offset) document.cookie = "bp_t_offset_" + BLOD.uid + "=" + offset + "; domain=bilibili.com; expires=Aug, 18 Dec 2038 18:00:00 GMT; BLOD.path=/";
}
// 页面分离
if (BLOD.path[3]) {
if (BLOD.path[3] == 'video' && (BLOD.path[4].toLowerCase().startsWith('av') || BLOD.path[4].toLowerCase().startsWith('bv'))) {
if (!BLOD.rewrite) new Function(GM_getResourceText("rewrite"))();
BLOD.rewrite.av();
}
if (BLOD.path[3] == 'watchlater') {
if (!BLOD.rewrite) new Function(GM_getResourceText("rewrite"))();
BLOD.rewrite.watchlater();
}
if (BLOD.path[3] == 'bangumi' && BLOD.path[4] == 'play') {
if (!BLOD.rewrite) new Function(GM_getResourceText("rewrite"))();
BLOD.rewrite.bangumi();
}
if (BLOD.path[3] == 'blackboard' && BLOD.path[4]) {
if (!BLOD.rewrite) new Function(GM_getResourceText("rewrite"))();
BLOD.rewrite.blackboard();
}
if (BLOD.path[3] == 'playlist' && BLOD.path[5].startsWith('pl')) {
if (!BLOD.rewrite) new Function(GM_getResourceText("rewrite"))();
BLOD.rewrite.playlist();
}
if (BLOD.path[3] == 'medialist' && BLOD.path[4] == 'play') {
if (!BLOD.rewrite) new Function(GM_getResourceText("rewrite"))();
BLOD.rewrite.medialist();
}
if (BLOD.path[3] == 's' && (BLOD.path[5].toLowerCase().startsWith('av') || BLOD.path[5].toLowerCase().startsWith('bv'))) {
if (!BLOD.rewrite) new Function(GM_getResourceText("rewrite"))();
BLOD.rewrite.s();
}
if (BLOD.path[2] == 'space.bilibili.com') {
if (!BLOD.rewrite) new Function(GM_getResourceText("rewrite"))();
BLOD.rewrite.space();
}
if (BLOD.path[2] == 'www.bilibili.com' && (BLOD.path[3].startsWith('\?') || BLOD.path[3].startsWith('\#') || BLOD.path[3].startsWith('index.'))) {
if (!BLOD.rewrite) new Function(GM_getResourceText("rewrite"))();
BLOD.rewrite.index();
}
if (BLOD.path[3] == 'v' && BLOD.path[4] == "popular") {
if (!BLOD.rewrite) new Function(GM_getResourceText("rewrite"))();
BLOD.rewrite.rank();
}
} else {
if (BLOD.path[2] == 'www.bilibili.com') {
if (!BLOD.rewrite) new Function(GM_getResourceText("rewrite"))();
BLOD.rewrite.index();
}
if (BLOD.path[2] == 'live.bilibili.com') {
if (!BLOD.rewrite) new Function(GM_getResourceText("rewrite"))();
BLOD.path.name = "live";
}
}
// 写入全局样式
BLOD.addCss(BLOD.getResourceText("css"));
new Function(GM_getResourceText("ui"))();
new Function(GM_getResourceText("xhrhook"))();
document.addEventListener("DOMNodeInserted", (msg) => {
// 去除预览提示框
if (/bilibili-player-video-toast-pay/.test(msg.target.className)) BLOD.reset.removePreview(msg.target);
// 版面替换
if (msg.target.id == "internationalHeader") BLOD.reset.resetSction();
if (msg.target.id == "bili-header-m") if (document.getElementById("internationalHeader")) document.getElementById("internationalHeader").remove();
// 切p监听
if (/bilibili-player-video-btn-start/.test(msg.target.className)) BLOD.reset.switchVideo();
// 创建播放器右键下载菜单
if (/bilibili-player-context-menu-container black/.test(msg.target.className)) {
if (!BLOD.download) new Function(GM_getResourceText("download"))();
BLOD.download.init(msg.target);
}
// 捕获评论链接
if (msg.target.src && msg.target.src.startsWith('https://api.bilibili.com/x/v2/reply') && msg.target.src.includes("oid")) BLOD.src = msg.target.src;
// 捕获频道视频链接
if (msg.target.src && msg.target.src.includes("//api.bilibili.com/x/space/channel/video?")) BLOD.src = msg.target.src;
// 修复失效频道视频
if (msg.relatedNode.getAttribute("class") == "row video-list clearfix") BLOD.reset.fixVideoLost.channel(BLOD.src);
// 修复失效收藏视频
if (msg.target.className == "small-item disabled") BLOD.reset.fixVideoLost.favlist(msg);
// 刷新番剧分集数据
if (msg.relatedNode.className == "info-sec-av") BLOD.reset.setBangumi.episodeData("", msg);
// 失效分区转换
if (msg.target.id == "bili_ad" || msg.target.className == "report-wrap-module elevator-module" || msg.target.id == "bili-header-m" || msg.target.className == "no-data loading") BLOD.reset.fixnews(msg.target);
// 修复评论楼层&修复评论空降坐标
if (BLOD.src && (/l_id/.test(msg.target.id) || /reply-wrap/.test(msg.target.className))) { BLOD.reset.setReplyFloor.init(BLOD.src); BLOD.reset.fixVideoSeek(msg.target.parentNode); }
// 修复分区排行
if (msg.target.id == "bili_movie" || msg.target.id == "bili_teleplay" || msg.target.id == "bili_documentary") BLOD.reset.fixrank(msg.target);
// 弹幕哈希反查
if (/danmaku-info-row/.test(msg.target.className)) BLOD.reset.danmkuHashId(msg.target);
// 其他节点监听
BLOD.reset.resetNodes();
// 收藏页切p监听
BLOD.reset.setMediaList.fixvar();
// 修复空间主页失效视频
BLOD.reset.fixVideoLost.home(msg);
// bv号转超链接
BLOD.reset.avdesc();
});
})();