User:Stumblean/common.js: Difference between revisions

Stumblean (talk | contribs)
No edit summary
Tags: Mobile edit Mobile web edit Advanced mobile edit
Stumblean (talk | contribs)
No edit summary
Tags: Mobile edit Mobile web edit Advanced mobile edit
Line 9: Line 9:
     iconSize: 15,
     iconSize: 15,
     minimizedSize: 30
     minimizedSize: 30
  };
  const defaultPrefs = {
    showEncouragement: true,
    showWatermark: true
   };
   };


   const settings = JSON.parse(localStorage.getItem("mahitoMenuSettings")) || defaultSettings;
   const settings = JSON.parse(localStorage.getItem("mahitoMenuSettings")) || defaultSettings;
  const prefs = JSON.parse(localStorage.getItem("mahitoMenuPrefs")) || defaultPrefs;
   function saveSettings() {
   function saveSettings() {
     localStorage.setItem("mahitoMenuSettings", JSON.stringify(settings));
     localStorage.setItem("mahitoMenuSettings", JSON.stringify(settings));
  }
  function savePrefs() {
    localStorage.setItem("mahitoMenuPrefs", JSON.stringify(prefs));
   }
   }


Line 167: Line 177:


   const btnExplain = makeButton("Open Explanation", () => {
   const btnExplain = makeButton("Open Explanation", () => {
     alert("This would explain how Mahito works. You can hook this later.");
     window.open("https://hpd0v2.mimo.run/index.html", "_blank");
   });
   });


Line 182: Line 192:
     minimizedIcon.remove();
     minimizedIcon.remove();
     ytContainer.remove();
     ytContainer.remove();
    prefsPanel.remove();
    watermark.remove();
   });
   });


Line 212: Line 224:
   });
   });


  // New Preferences Button
  const btnPreferences = makeButton("Preferences", () => {
    if (prefsPanel.style.display === "block") {
      prefsPanel.style.display = "none";
    } else {
      prefsPanel.style.display = "block";
    }
  });
  // Preferences Panel
  const prefsPanel = document.createElement("div");
  Object.assign(prefsPanel.style, {
    backgroundColor: "#333a66",
    padding: "8px",
    borderRadius: "6px",
    marginTop: "10px",
    display: "none",
    color: "#eee",
    fontSize: "13px"
  });
  function createCheckbox(labelText, prefKey) {
    const label = document.createElement("label");
    label.style.display = "block";
    label.style.marginBottom = "6px";
    label.style.cursor = "pointer";
    const checkbox = document.createElement("input");
    checkbox.type = "checkbox";
    checkbox.checked = prefs[prefKey];
    checkbox.style.marginRight = "6px";
    checkbox.addEventListener("change", () => {
      prefs[prefKey] = checkbox.checked;
      savePrefs();
      applyPreferences();
    });
    label.appendChild(checkbox);
    label.appendChild(document.createTextNode(labelText));
    return label;
  }
  prefsPanel.appendChild(createCheckbox("Show Encouragement Button", "showEncouragement"));
  prefsPanel.appendChild(createCheckbox("Show Watermark Footer", "showWatermark"));
  function applyPreferences() {
    btnEncouragement.style.display = prefs.showEncouragement ? "block" : "none";
    watermark.style.display = prefs.showWatermark ? "block" : "none";
  }
  // Create YouTube encouragement container
   const ytContainer = document.createElement("div");
   const ytContainer = document.createElement("div");
   Object.assign(ytContainer.style, {
   Object.assign(ytContainer.style, {
Line 234: Line 298:
   ytIframe.allowFullscreen = true;
   ytIframe.allowFullscreen = true;
   ytContainer.appendChild(ytIframe);
   ytContainer.appendChild(ytIframe);
  // Add buttons to menu
  menu.appendChild(header);
  menu.appendChild(btnUndo);
  menu.appendChild(btnExplain);
  menu.appendChild(btnEncouragement);
  menu.appendChild(btnYujify);
  menu.appendChild(btnCustomize);
  menu.appendChild(btnReset);
  // Add everything to page
  document.body.appendChild(menu);
  document.body.appendChild(minimizedIcon);
  document.body.appendChild(ytContainer);


   // Transparent watermark footer
   // Transparent watermark footer
Line 263: Line 313:
     fontFamily: "monospace"
     fontFamily: "monospace"
   });
   });
  // Append buttons
  menu.appendChild(header);
  menu.appendChild(btnUndo);
  menu.appendChild(btnExplain);
  menu.appendChild(btnEncouragement);
  menu.appendChild(btnYujify);
  menu.appendChild(btnCustomize);
  menu.appendChild(btnReset);
  menu.appendChild(btnPreferences);
  menu.appendChild(prefsPanel);
  // Append everything to body
  document.body.appendChild(menu);
  document.body.appendChild(minimizedIcon);
  document.body.appendChild(ytContainer);
   document.body.appendChild(watermark);
   document.body.appendChild(watermark);
  // Apply preferences initially
  applyPreferences();
})();
})();