Bläddra i källkod

lots of menu stuff

Sv443 3 år sedan
förälder
incheckning
1bd4ce87c8
1 ändrade filer med 42 tillägg och 16 borttagningar
  1. 42 16
      BetterYTM.user.js

+ 42 - 16
BetterYTM.user.js

@@ -35,9 +35,10 @@ const dbg = true;
 // const branch = "main";
 // const branch = "main";
 const branch = "develop"; // #DEBUG#
 const branch = "develop"; // #DEBUG#
 
 
+/** Contains all possible features with their default values and other config */
 const featInfo = {
 const featInfo = {
     arrowKeySupport: {
     arrowKeySupport: {
-        desc: "Arrow keys should skip forwards and backwards by 10 seconds?",
+        desc: "Should arrow keys skip forwards and backwards by 10 seconds?",
         type: "toggle",
         type: "toggle",
         default: true,
         default: true,
     },
     },
@@ -52,7 +53,7 @@ const featInfo = {
         default: true,
         default: true,
     },
     },
     geniusLyrics: {
     geniusLyrics: {
-        desc: "Add a button to the media controls bar to search for the current song's lyrics on genius.com in a new tab?",
+        desc: "Add a button to the media controls to open the current song's lyrics on genius.com in a new tab?",
         type: "toggle",
         type: "toggle",
         default: true,
         default: true,
     },
     },
@@ -62,11 +63,12 @@ const featInfo = {
         default: true,
         default: true,
     },
     },
     volumeSliderSize: {
     volumeSliderSize: {
-        desc: "The width of the volume slider in px",
+        desc: "The width of the volume slider in pixels",
         type: "number",
         type: "number",
         min: 10,
         min: 10,
         max: 1000,
         max: 1000,
-        default: 175,
+        step: 5,
+        default: 160,
     },
     },
     volumeSliderStep: {
     volumeSliderStep: {
         desc: "Volume slider sensitivity - the smaller this number, the finer the volume control",
         desc: "Volume slider sensitivity - the smaller this number, the finer the volume control",
@@ -75,10 +77,10 @@ const featInfo = {
         max: 20,
         max: 20,
         default: 2,
         default: 2,
     },
     },
-    removeWatermark: {
-        desc: "Remove the watermark under the YTM logo?",
+    watermarkEnabled: {
+        desc: "Enable the BetterYTM watermark under the YTM logo?",
         type: "toggle",
         type: "toggle",
-        default: false,
+        default: true,
     },
     },
 };
 };
 
 
@@ -167,7 +169,7 @@ async function onDomLoad()
             if(features.removeUpgradeTab)
             if(features.removeUpgradeTab)
                 removeUpgradeTab();
                 removeUpgradeTab();
 
 
-            if(!features.removeWatermark)
+            if(features.watermarkEnabled)
                 addWatermark();
                 addWatermark();
 
 
             if(features.geniusLyrics)
             if(features.geniusLyrics)
@@ -321,7 +323,7 @@ function addMenu()
         if(!ftInfo)
         if(!ftInfo)
             continue;
             continue;
 
 
-        const { desc, type, default: ftDef } = ftInfo;
+        const { desc, type, default: ftDef, step } = ftInfo;
         const val = features[key];
         const val = features[key];
 
 
         const initialVal = val || ftDef;
         const initialVal = val || ftDef;
@@ -365,9 +367,11 @@ function addMenu()
 
 
             const inputElem = document.createElement("input");
             const inputElem = document.createElement("input");
             inputElem.id = inputElemId;
             inputElem.id = inputElemId;
-            inputElem.style.marginRight = "20px";
+            inputElem.style.marginRight = "25px";
+            if(type === "toggle") inputElem.style.marginLeft = "5px";
             inputElem.type = inputType;
             inputElem.type = inputType;
             inputElem.value = initialVal;
             inputElem.value = initialVal;
+            if(type === "number" && step) inputElem.step = step;
 
 
             if(ftInfo.min && ftInfo.max)
             if(ftInfo.min && ftInfo.max)
             {
             {
@@ -379,18 +383,32 @@ function addMenu()
                 inputElem.checked = initialVal;
                 inputElem.checked = initialVal;
 
 
             const fmtVal = v => String(v);
             const fmtVal = v => String(v);
+            const toggleLabelText = toggled => toggled ? "On" : "Off";
 
 
             let labelElem;
             let labelElem;
             if(type === "slider")
             if(type === "slider")
             {
             {
                 labelElem = document.createElement("label");
                 labelElem = document.createElement("label");
+                labelElem.classList.add("bytm-ftconf-label");
                 labelElem.style.marginRight = "20px";
                 labelElem.style.marginRight = "20px";
                 labelElem.style.fontSize = "16px";
                 labelElem.style.fontSize = "16px";
-                labelElem["for"] = inputElemId;
+                labelElem.htmlFor = inputElemId;
                 labelElem.innerText = fmtVal(initialVal);
                 labelElem.innerText = fmtVal(initialVal);
 
 
                 inputElem.addEventListener("change", () => labelElem.innerText = fmtVal(parseInt(inputElem.value)));
                 inputElem.addEventListener("change", () => labelElem.innerText = fmtVal(parseInt(inputElem.value)));
             }
             }
+            else if(type === "toggle")
+            {
+                labelElem = document.createElement("label");
+                labelElem.classList.add("bytm-ftconf-label");
+                labelElem.style.paddingLeft = "10px";
+                labelElem.style.paddingRight = "5px";
+                labelElem.style.fontSize = "16px";
+                labelElem.htmlFor = inputElemId;
+                labelElem.innerText = toggleLabelText(initialVal);
+
+                inputElem.addEventListener("change", () => labelElem.innerText = toggleLabelText(inputElem.checked));
+            }
 
 
             inputElem.addEventListener("change", ({ currentTarget }) => {
             inputElem.addEventListener("change", ({ currentTarget }) => {
                 let v = parseInt(currentTarget.value);
                 let v = parseInt(currentTarget.value);
@@ -405,7 +423,12 @@ function addMenu()
                 inputElem[type !== "toggle" ? "value" : "checked"] = ftDef;
                 inputElem[type !== "toggle" ? "value" : "checked"] = ftDef;
 
 
                 if(labelElem)
                 if(labelElem)
-                    labelElem.innerText = fmtVal(parseInt(inputElem.value));
+                {
+                    if(type === "toggle")
+                        labelElem.innerText = toggleLabelText(inputElem.checked);
+                    else
+                        labelElem.innerText = fmtVal(parseInt(inputElem.value));
+                }
 
 
                 confChanged(key, initialVal, ftDef);
                 confChanged(key, initialVal, ftDef);
             });
             });
@@ -491,13 +514,17 @@ function addMenu()
         display: inline-block;
         display: inline-block;
     }
     }
 
 
-    .betterytm-menu-img {
+    /*.betterytm-menu-img {
 
 
-    }
+    }*/
 
 
     #betterytm-menu-close {
     #betterytm-menu-close {
         cursor: pointer;
         cursor: pointer;
     }
     }
+
+    .bytm-ftconf-label {
+        user-select: none;
+    }
     `;
     `;
 
 
     dbg && console.log("BetterYTM: Added menu elem:", backgroundElem);
     dbg && console.log("BetterYTM: Added menu elem:", backgroundElem);
@@ -693,12 +720,11 @@ function removeUpgradeTab()
  */
  */
 function addWatermark()
 function addWatermark()
 {
 {
-    const watermark = document.createElement("a");
+    const watermark = document.createElement("span");
     watermark.id = "betterytm-watermark";
     watermark.id = "betterytm-watermark";
     watermark.className = "style-scope ytmusic-nav-bar";
     watermark.className = "style-scope ytmusic-nav-bar";
     watermark.innerText = info.name;
     watermark.innerText = info.name;
     watermark.title = "Open menu";
     watermark.title = "Open menu";
-    watermark.href = "#";
 
 
     watermark.addEventListener("click", () => openMenu());
     watermark.addEventListener("click", () => openMenu());