Ver código fonte

refresh icon

Sv443 3 anos atrás
pai
commit
76590db6c7
3 arquivos alterados com 40 adições e 7 exclusões
  1. 37 5
      BetterYTM.user.js
  2. 3 2
      README.md
  3. 0 0
      resources/external/genius.png

+ 37 - 5
BetterYTM.user.js

@@ -13,12 +13,14 @@
 // @icon            https://www.google.com/s2/favicons?domain=music.youtube.com
 // @run-at          document-start
 // @connect         self
-// @connect         *.youtube.com
+// @connect         youtube.com
+// @connect         github.com
+// @connect         githubusercontent.com
 // @downloadURL     https://raw.githubusercontent.com/Sv443/BetterYTM/main/BetterYTM.user.js
 // @updateURL       https://raw.githubusercontent.com/Sv443/BetterYTM/main/BetterYTM.user.js
 // ==/UserScript==
 
-/* Disclaimer: I am not affiliated with YouTube, Google, Alphabet or anyone else */
+/* Disclaimer: I am not affiliated with YouTube, Google, Alphabet, Genius or anyone else */
 /* C&D this, Susan 🖕 */
 
 (() => {
@@ -42,12 +44,14 @@ const features = Object.freeze({
     /** Whether to remove the "Upgrade" / YT Music Premium tab */
     removeUpgradeTab: true,
 
-        // --- Extra Features ---
+    // --- Extra Features ---
     /** Whether to add a button or key combination (TODO) to switch between the YT and YTM sites on a video */
     switchBetweenSites: true,
+    /** Adds a button to the media controls bar to open the current song's genius.com lyrics in a new tab */
+    geniusLyrics: true,
 
     // --- Other ---
-    /** Set to true to remove the watermark next to the YTM logo */
+    /** Set to true to remove the watermark under the YTM logo */
     removeWatermark: false,
 
     // /** The theme color - accepts any CSS color value - default is "#ff0000" */
@@ -57,7 +61,7 @@ const features = Object.freeze({
 
 
 /** Set to true to enable debug mode for more output in the JS console */
-const dbg = false;
+const dbg = true;
 
 
 
@@ -125,6 +129,9 @@ function onDomLoad()
 
             if(!features.removeWatermark)
                 addWatermark();
+
+            if(features.geniusLyrics)
+                addGeniusButton();
         }
 
         // Both YTM and YT
@@ -357,6 +364,31 @@ function addWatermark()
     dbg && console.info(`BetterYTM: Added watermark element:`, watermark);
 }
 
+//#SECTION genius.com lyrics button
+
+function addGeniusButton()
+{
+    const menuElem = document.querySelector(".middle-controls-buttons tp-yt-paper-icon-button.dropdown-trigger");
+    if(!menuElem)
+        return setTimeout(addGeniusButton, 250);
+
+    const linkElem = document.createElement("a");
+    linkElem.id = "betterytm-genius-button";
+    linkElem.href = getGeniusUrl();
+    linkElem.target = "_blank";
+    linkElem.rel = "noopener noreferrer";
+
+    const imgElem = document.createElement("img");
+    imgElem.src = "https://raw.githubusercontent.com/Sv443/BetterYTM/develop/resources/external/genius.png";
+    imgElem.style = "z-index: 10; width: 24px; height: 24px; padding: 8px; padding-left: 16px;";
+
+    linkElem.appendChild(imgElem);
+
+    dbg && console.info(`BetterYTM: Inserted genius button:`, linkElem);
+
+    menuElem.parentNode.insertBefore(linkElem, menuElem.nextSibling);
+}
+
 
 //#MARKER other
 

+ 3 - 2
README.md

@@ -5,6 +5,7 @@ Userscript that improves [YouTube Music](https://music.youtube.com/)
 
 ## Features:
 - Use arrow keys to skip forward or backward by 10 seconds
+- Open the current song's lyrics on genius.com
 - Switch between YouTube and YouTube Music on a video by pressing a hotkey (F9 by default)
 - Disable the "Upgrade" / YT Music Premium tab in the title bar
 
@@ -18,7 +19,7 @@ Once this script is more finished, I might add a menu to toggle these more easil
 <br><br>
 
 ## Install:
-- Install a userscript manager
+- Install a userscript manager extension
     > Firefox: [GreaseMonkey](https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/)  
     > Chrome: [TamperMonkey](https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=en)  
     > Edge: [TamperMonkey](https://microsoftedge.microsoft.com/addons/detail/tampermonkey/iikmkjmpaadaobahmlepeloendndfphd)
@@ -29,7 +30,7 @@ Once this script is more finished, I might add a menu to toggle these more easil
 ### Disclaimers:
 - I am not affiliated with YouTube, Google, Alphabet, or anyone else
 - I do not intend to ever collect any data about you, everything in this script is done and stored locally on your device or on YouTube's servers
-- I can't guarantee this software is without flaws. If something bad happens, I don't accept blame. I do however accept [bug reports.](https://github.com/Sv443/BetterYTM/issues/new)
+- I can't guarantee this software is without flaws. If something bad happens, I don't accept blame. I do however accept [bug reports and feature requests.](https://github.com/Sv443/BetterYTM/issues/new)
 
 <br><br><br><br><br><br>
 

+ 0 - 0
resources/external/geniusx.png → resources/external/genius.png