mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 01:01:55 +01:00
Make category pill work on invidious and mobile youtube
This commit is contained in:
parent
388b9179ac
commit
040bce2638
2 changed files with 26 additions and 5 deletions
|
@ -647,7 +647,7 @@ function setupCategoryPill() {
|
|||
categoryPill = new CategoryPill();
|
||||
}
|
||||
|
||||
categoryPill.attachToPage();
|
||||
categoryPill.attachToPage(onMobileYouTube);
|
||||
}
|
||||
|
||||
async function sponsorsLookup(id: string, keepOldSubmissions = true) {
|
||||
|
|
|
@ -9,15 +9,19 @@ export class CategoryPill {
|
|||
ref: React.RefObject<CategoryPillComponent>;
|
||||
|
||||
unsavedState: CategoryPillState;
|
||||
|
||||
mutationObserver?: MutationObserver;
|
||||
|
||||
constructor() {
|
||||
this.ref = React.createRef();
|
||||
}
|
||||
|
||||
async attachToPage(): Promise<void> {
|
||||
// TODO: Mobile and invidious
|
||||
const referenceNode = await GenericUtils.wait(() => document.querySelector(".ytd-video-primary-info-renderer.title") as HTMLElement);
|
||||
|
||||
async attachToPage(onMobileYouTube: boolean): Promise<void> {
|
||||
const referenceNode =
|
||||
await GenericUtils.wait(() =>
|
||||
// YouTube, Mobile YouTube, Invidious
|
||||
document.querySelector(".ytd-video-primary-info-renderer.title, .slim-video-information-title, #player-container + .h-box > h1") as HTMLElement);
|
||||
|
||||
if (referenceNode && !referenceNode.contains(this.container)) {
|
||||
this.container = document.createElement('span');
|
||||
this.container.id = "categoryPill";
|
||||
|
@ -26,6 +30,10 @@ export class CategoryPill {
|
|||
referenceNode.prepend(this.container);
|
||||
referenceNode.style.display = "flex";
|
||||
|
||||
if (this.ref.current) {
|
||||
this.unsavedState = this.ref.current.state;
|
||||
}
|
||||
|
||||
ReactDOM.render(
|
||||
<CategoryPillComponent ref={this.ref} />,
|
||||
this.container
|
||||
|
@ -35,6 +43,19 @@ export class CategoryPill {
|
|||
this.ref.current?.setState(this.unsavedState);
|
||||
this.unsavedState = null;
|
||||
}
|
||||
|
||||
if (onMobileYouTube) {
|
||||
if (this.mutationObserver) {
|
||||
this.mutationObserver.disconnect();
|
||||
}
|
||||
|
||||
this.mutationObserver = new MutationObserver(() => this.attachToPage(onMobileYouTube));
|
||||
|
||||
this.mutationObserver.observe(referenceNode, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue