Skip to content

Commit

Permalink
支持替换 BiliComments 为翻页评论区 (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
MotooriKashin authored Sep 7, 2024
1 parent 44da421 commit 24dcbfd
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 8 deletions.
43 changes: 42 additions & 1 deletion src/core/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export class Comment {
events = {};
this.bbComment();
this.initComment();
this.BiliComments();
this.pageCount();
this.jump();
}
/** 捕获评论组件 */
protected bbComment() {
const that = this;
Reflect.defineProperty(window, "bbComment", {
configurable: true,
set: v => {
Expand Down Expand Up @@ -106,6 +106,42 @@ export class Comment {
}
});
}

protected BiliComments() {
Reflect.defineProperty(self, 'BiliComments', {
configurable: true,
set: v => true,
get: () => {
return class extends EventTarget {
constructor(private arg: IBiliComments) {
super();
}

mount(parent: HTMLElement) {
if (load) {
const [type, oid] = this.arg.params.split(",");
new Feedback(parent, oid, type, undefined, this.arg.seekId);
setTimeout(() => {
this.dispatchEvent(new Event('inited'));
this.dispatchEvent(new Event('expand'));
// this.dispatchEvent(new Event('seek'));
});
} else {
if (!loading) {
loadScript(`//s1.hdslb.com/bfs/seed/jinkela/commentpc/comment.min.js`).then(() => {
load = true;
})
}
loading = true;
setTimeout(() => this.mount(parent), 100);
}
return this;
}
}
}
});
}

/** 修复按时间排序评论翻页数 */
protected pageCount() {
jsonpHook("api.bilibili.com/x/v2/reply?", undefined, (res, url) => {
Expand Down Expand Up @@ -573,3 +609,8 @@ export class Comment {
}
}
}

interface IBiliComments {
params: string;
seekId?: number;
}
39 changes: 36 additions & 3 deletions tampermonkey/comment/main.user.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tampermonkey/comment/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Bilibili 翻页评论区",
"namespace": "MotooriKashin",
"version": "2.2.7",
"version": "2.2.8",
"description": "恢复评论区翻页功能。",
"author": "MotooriKashin",
"homepage": "https://github.com/MotooriKashin/Bilibili-Old",
Expand Down
37 changes: 35 additions & 2 deletions tampermonkey/main.user.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tampermonkey/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Bilibili 旧播放页",
"namespace": "MotooriKashin",
"version": "10.8.3",
"version": "10.8.4",
"description": "恢复Bilibili旧版页面,为了那些念旧的人。",
"author": "MotooriKashin, wly5556",
"homepage": "https://github.com/MotooriKashin/Bilibili-Old",
Expand Down

0 comments on commit 24dcbfd

Please sign in to comment.