mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 10:11:46 +00:00
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 <shlee1503@naver.com> * MutationObserver could not exist Co-authored-by: JellyBrick <shlee1503@naver.com> * Update src/plugins/skip-disliked-songs/index.ts Co-authored-by: JellyBrick <shlee1503@naver.com> * Replaced double quotes with single quotes --------- Co-authored-by: JellyBrick <shlee1503@naver.com>
This commit is contained in:
@ -589,6 +589,10 @@
|
||||
"visualizer-type": "Visualizer Type"
|
||||
},
|
||||
"name": "Visualizer"
|
||||
},
|
||||
"skip-disliked-songs": {
|
||||
"description": "Skips disliked songs",
|
||||
"name": "Skip Disliked Songs"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
41
src/plugins/skip-disliked-songs/index.ts
Normal file
41
src/plugins/skip-disliked-songs/index.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { t } from '@/i18n';
|
||||
import { createPlugin } from '@/utils';
|
||||
|
||||
export default createPlugin({
|
||||
name: () => t('plugins.skip-disliked-songs.name'),
|
||||
description: () => t('plugins.skip-disliked-songs.description'),
|
||||
restartNeeded: false,
|
||||
renderer: {
|
||||
observer: null as MutationObserver | null,
|
||||
start() {
|
||||
this.waitForElem('#like-button-renderer').then((likeBtn) => {
|
||||
this.observer = new MutationObserver(() => {
|
||||
if (likeBtn?.getAttribute('like-status') == 'DISLIKE') {
|
||||
document
|
||||
.querySelector('tp-yt-paper-icon-button.next-button')
|
||||
?.click();
|
||||
}
|
||||
});
|
||||
this.observer.observe(likeBtn, {
|
||||
attributes: true,
|
||||
childList: false,
|
||||
subtree: false,
|
||||
});
|
||||
});
|
||||
},
|
||||
stop() {
|
||||
this.observer?.disconnect();
|
||||
},
|
||||
waitForElem(selector) {
|
||||
return new Promise((resolve) => {
|
||||
const interval = setInterval(() => {
|
||||
const elem = document.querySelector(selector);
|
||||
if (!elem) return;
|
||||
|
||||
clearInterval(interval);
|
||||
resolve(elem);
|
||||
});
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user