From 640ba26d55df81b5f9b7eba1761f5887511a0624 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Thu, 16 Mar 2023 18:58:52 +0200 Subject: [PATCH] add option to hide the like buttons fix #1075 --- config/store.js | 5 +++++ menu.js | 33 +++++++++++++++++++++++++++------ preload.js | 14 ++++++++++---- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/config/store.js b/config/store.js index 07984820..1ba8ce26 100644 --- a/config/store.js +++ b/config/store.js @@ -19,6 +19,11 @@ const migrations = { ...pluginOptions, }); } + + if (store.get("options.ForceShowLikeButtons")) { + store.delete("options.ForceShowLikeButtons"); + store.set("options.likeButtons", 'force'); + } }, ">=1.17.0": (store) => { setDefaultPluginOptions(store, "picture-in-picture"); diff --git a/menu.js b/menu.js index a741cd5d..d35d8252 100644 --- a/menu.js +++ b/menu.js @@ -93,12 +93,33 @@ const mainMenuTemplate = (win) => { }, }, { - label: "Force show like buttons", - type: "checkbox", - checked: config.get("options.ForceShowLikeButtons"), - click: (item) => { - config.set("options.ForceShowLikeButtons", item.checked); - }, + label: "Like buttons", + submenu: [ + { + label: "Default", + type: "radio", + checked: !config.get("options.likeButtons"), + click: () => { + config.set("options.likeButtons", ''); + }, + }, + { + label: "Force show", + type: "radio", + checked: config.get("options.likeButtons") === 'force', + click: () => { + config.set("options.likeButtons", 'force'); + } + }, + { + label: "Hide", + type: "radio", + checked: config.get("options.likeButtons") === 'hide', + click: () => { + config.set("options.likeButtons", 'hide'); + } + }, + ], }, { label: "Theme", diff --git a/preload.js b/preload.js index 492f3192..e956effa 100644 --- a/preload.js +++ b/preload.js @@ -135,11 +135,17 @@ function onApiLoaded() { } } - // Force show like buttons - if (config.get("options.ForceShowLikeButtons")) { - const likeButtons = document.querySelector('ytmusic-like-button-renderer') + + // Hide / Force show like buttons + const likeButtonsOptions = config.get("options.likeButtons"); + if (likeButtonsOptions) { + const likeButtons = document.querySelector("ytmusic-like-button-renderer"); if (likeButtons) { - likeButtons.style.display = 'inherit'; + likeButtons.style.display = + { + hide: "none", + force: "inherit", + }[likeButtonsOptions] || ""; } } }