diff --git a/src/i18n/resources/en.json b/src/i18n/resources/en.json index 2f89f79d..83139fc3 100644 --- a/src/i18n/resources/en.json +++ b/src/i18n/resources/en.json @@ -589,6 +589,10 @@ "visualizer-type": "Visualizer Type" }, "name": "Visualizer" + }, + "skip-disliked-songs": { + "description": "Skips disliked songs", + "name": "Skip Disliked Songs" } } } diff --git a/src/plugins/skip-disliked-songs/index.ts b/src/plugins/skip-disliked-songs/index.ts new file mode 100644 index 00000000..3e3143cb --- /dev/null +++ b/src/plugins/skip-disliked-songs/index.ts @@ -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); + }); + }); + }, + }, +}); \ No newline at end of file