From 45e5bc7df5d45b8e2099513c0b07503a85d7dcc9 Mon Sep 17 00:00:00 2001 From: Yazazuyo <63968466+MiepHD@users.noreply.github.com> Date: Sat, 9 Dec 2023 02:37:17 +0100 Subject: [PATCH] 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 * MutationObserver could not exist Co-authored-by: JellyBrick * Update src/plugins/skip-disliked-songs/index.ts Co-authored-by: JellyBrick * Replaced double quotes with single quotes --------- Co-authored-by: JellyBrick --- src/i18n/resources/en.json | 4 +++ src/plugins/skip-disliked-songs/index.ts | 41 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/plugins/skip-disliked-songs/index.ts 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