Skip to content

Commit 45e5bc7

Browse files
MiepHDJellyBrick
andauthored
Skip Disliked Songs (#1505)
* Added skip-disliked-songs * Changed it to activate and deactivate without restart * Added waiter for Element * MutationObserver can be null Co-authored-by: JellyBrick <[email protected]> * MutationObserver could not exist Co-authored-by: JellyBrick <[email protected]> * Update src/plugins/skip-disliked-songs/index.ts Co-authored-by: JellyBrick <[email protected]> * Replaced double quotes with single quotes --------- Co-authored-by: JellyBrick <[email protected]>
1 parent a81cb95 commit 45e5bc7

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/i18n/resources/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,10 @@
589589
"visualizer-type": "Visualizer Type"
590590
},
591591
"name": "Visualizer"
592+
},
593+
"skip-disliked-songs": {
594+
"description": "Skips disliked songs",
595+
"name": "Skip Disliked Songs"
592596
}
593597
}
594598
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { t } from '@/i18n';
2+
import { createPlugin } from '@/utils';
3+
4+
export default createPlugin({
5+
name: () => t('plugins.skip-disliked-songs.name'),
6+
description: () => t('plugins.skip-disliked-songs.description'),
7+
restartNeeded: false,
8+
renderer: {
9+
observer: null as MutationObserver | null,
10+
start() {
11+
this.waitForElem('#like-button-renderer').then((likeBtn) => {
12+
this.observer = new MutationObserver(() => {
13+
if (likeBtn?.getAttribute('like-status') == 'DISLIKE') {
14+
document
15+
.querySelector('tp-yt-paper-icon-button.next-button')
16+
?.click();
17+
}
18+
});
19+
this.observer.observe(likeBtn, {
20+
attributes: true,
21+
childList: false,
22+
subtree: false,
23+
});
24+
});
25+
},
26+
stop() {
27+
this.observer?.disconnect();
28+
},
29+
waitForElem(selector) {
30+
return new Promise((resolve) => {
31+
const interval = setInterval(() => {
32+
const elem = document.querySelector(selector);
33+
if (!elem) return;
34+
35+
clearInterval(interval);
36+
resolve(elem);
37+
});
38+
});
39+
},
40+
},
41+
});

0 commit comments

Comments
 (0)