Jump to content

User:Stumblean/common.js: Difference between revisions

From Domination Earth
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 17: Line 17:
     zIndex: "99999",
     zIndex: "99999",
     boxShadow: "0 0 10px black",
     boxShadow: "0 0 10px black",
     width: "180px"
     width: "180px",
    cursor: "move", // show dragging cursor
    userSelect: "none" // avoid selecting text while dragging
   });
   });


Line 166: Line 168:
   document.body.appendChild(minimizedIcon);
   document.body.appendChild(minimizedIcon);
   document.body.appendChild(ytContainer);
   document.body.appendChild(ytContainer);
  // === Dragging logic ===
  let posX = 0, posY = 0, startX = 0, startY = 0;
  let dragging = false;
  function onDragStart(e) {
    dragging = true;
    startX = e.type === "touchstart" ? e.touches[0].clientX : e.clientX;
    startY = e.type === "touchstart" ? e.touches[0].clientY : e.clientY;
    posX = parseInt(menu.style.right);
    posY = parseInt(menu.style.top);
    e.preventDefault();
  }
  function onDragMove(e) {
    if (!dragging) return;
    const clientX = e.type === "touchmove" ? e.touches[0].clientX : e.clientX;
    const clientY = e.type === "touchmove" ? e.touches[0].clientY : e.clientY;
    const dx = startX - clientX;
    const dy = clientY - startY;
    let newRight = posX + dx;
    let newTop = posY + dy;
    // keep inside viewport horizontally
    newRight = Math.max(0, Math.min(window.innerWidth - menu.offsetWidth, window.innerWidth - newRight - menu.offsetWidth));
    // keep inside viewport vertically
    newTop = Math.max(0, Math.min(window.innerHeight - menu.offsetHeight, newTop));
    menu.style.right = newRight + "px";
    menu.style.top = newTop + "px";
    e.preventDefault();
  }
  function onDragEnd() {
    dragging = false;
  }
  // Attach events to header for dragging
  header.style.touchAction = "none"; // prevent default gestures on mobile
  header.addEventListener("mousedown", onDragStart);
  header.addEventListener("touchstart", onDragStart);
  window.addEventListener("mousemove", onDragMove);
  window.addEventListener("touchmove", onDragMove);
  window.addEventListener("mouseup", onDragEnd);
  window.addEventListener("touchend", onDragEnd);
})();
})();

Revision as of 21:31, 27 June 2025

(function () {
  const iconURL = "https://files.catbox.moe/wk78nl.jpg";

  // === MENU ===
  const menu = document.createElement("div");
  menu.id = "mahitoMenu";
  Object.assign(menu.style, {
    position: "fixed",
    top: "20px",
    right: "20px",
    background: "#7889B2",
    color: "#fff",
    border: "2px solid #fff",
    borderRadius: "10px",
    padding: "10px",
    fontFamily: "monospace",
    zIndex: "99999",
    boxShadow: "0 0 10px black",
    width: "180px",
    cursor: "move", // show dragging cursor
    userSelect: "none" // avoid selecting text while dragging
  });

  // === HEADER WITH ICONS AND MINIMIZE BUTTON ===
  const header = document.createElement("div");
  header.style.display = "flex";
  header.style.justifyContent = "space-between";
  header.style.alignItems = "center";
  header.style.marginBottom = "8px";

  const titleWrap = document.createElement("div");
  titleWrap.style.display = "flex";
  titleWrap.style.alignItems = "center";
  titleWrap.style.gap = "6px";

  const leftIcon = document.createElement("img");
  leftIcon.src = iconURL;
  leftIcon.width = 15;
  leftIcon.height = 15;

  const title = document.createElement("div");
  title.textContent = "Mahito Menu";
  title.style.fontWeight = "bold";
  title.style.color = "#fff";

  const rightIcon = document.createElement("img");
  rightIcon.src = iconURL;
  rightIcon.width = 15;
  rightIcon.height = 15;

  titleWrap.appendChild(leftIcon);
  titleWrap.appendChild(title);
  titleWrap.appendChild(rightIcon);

  const minimizeBtn = document.createElement("button");
  minimizeBtn.textContent = "–";
  Object.assign(minimizeBtn.style, {
    background: "#45A8C5",
    border: "none",
    color: "#fff",
    cursor: "pointer",
    borderRadius: "5px",
    width: "25px",
    height: "25px"
  });

  header.appendChild(titleWrap);
  header.appendChild(minimizeBtn);

  // === MINIMIZED ICON ===
  const minimizedIcon = document.createElement("img");
  minimizedIcon.src = iconURL;
  minimizedIcon.width = 30;
  minimizedIcon.height = 30;
  Object.assign(minimizedIcon.style, {
    position: "fixed",
    top: "20px",
    right: "20px",
    zIndex: "99999",
    display: "none",
    cursor: "pointer",
    borderRadius: "6px", // rounded square
    width: "30px",
    height: "30px"
  });

  minimizedIcon.addEventListener("click", () => {
    minimizedIcon.style.display = "none";
    menu.style.display = "block";
  });

  minimizeBtn.addEventListener("click", () => {
    menu.style.display = "none";
    minimizedIcon.style.display = "block";
  });

  // === Button creator
  function makeButton(text, action) {
    const btn = document.createElement("button");
    btn.textContent = text;
    btn.onclick = action;
    Object.assign(btn.style, {
      marginBottom: "6px",
      width: "100%",
      cursor: "pointer",
      background: "#45A8C5",
      color: "#fff",
      border: "none",
      padding: "5px 10px",
      borderRadius: "5px"
    });
    return btn;
  }

  // === All buttons
  const btnUndo = makeButton("Mass undo", () => {
    navigator.clipboard.writeText(
      "mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Alexis_Jazz/Kill-It-With-Fire.js&action=raw&ctype=text/javascript');"
    );
    alert("Go to your common.js and paste what was just copied!");
  });

  const btnExplain = makeButton("Open Explanation", () => {
    alert("This would explain how Mahito works. You can hook this later.");
  });

  const btnEncouragement = makeButton("Encouragement", () => {
    if (ytContainer.style.display === "none") {
      ytContainer.style.display = "block";
    } else {
      ytContainer.style.display = "none";
      ytIframe.src = ytIframe.src; // reset video
    }
  });

  // === YouTube iframe container
  const ytContainer = document.createElement("div");
  Object.assign(ytContainer.style, {
    position: "fixed",
    right: "20px",
    top: "150px",
    zIndex: "99998",
    display: "none",
    background: "#000",
    padding: "5px",
    borderRadius: "10px",
    boxShadow: "0 0 10px black"
  });

  const ytIframe = document.createElement("iframe");
  ytIframe.width = "280";
  ytIframe.height = "157";
  ytIframe.src = "https://www.youtube.com/embed/VKfyq_hOL0c?autoplay=1";
  ytIframe.title = "Self Embodiment of Perfection OST";
  ytIframe.frameBorder = "0";
  ytIframe.allow =
    "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture";
  ytIframe.allowFullscreen = true;

  ytContainer.appendChild(ytIframe);

  // === Final Assembly
  menu.appendChild(header);
  menu.appendChild(btnUndo);
  menu.appendChild(btnExplain);
  menu.appendChild(btnEncouragement);
  document.body.appendChild(menu);
  document.body.appendChild(minimizedIcon);
  document.body.appendChild(ytContainer);

  // === Dragging logic ===
  let posX = 0, posY = 0, startX = 0, startY = 0;
  let dragging = false;

  function onDragStart(e) {
    dragging = true;
    startX = e.type === "touchstart" ? e.touches[0].clientX : e.clientX;
    startY = e.type === "touchstart" ? e.touches[0].clientY : e.clientY;
    posX = parseInt(menu.style.right);
    posY = parseInt(menu.style.top);
    e.preventDefault();
  }

  function onDragMove(e) {
    if (!dragging) return;
    const clientX = e.type === "touchmove" ? e.touches[0].clientX : e.clientX;
    const clientY = e.type === "touchmove" ? e.touches[0].clientY : e.clientY;
    const dx = startX - clientX;
    const dy = clientY - startY;

    let newRight = posX + dx;
    let newTop = posY + dy;

    // keep inside viewport horizontally
    newRight = Math.max(0, Math.min(window.innerWidth - menu.offsetWidth, window.innerWidth - newRight - menu.offsetWidth));
    // keep inside viewport vertically
    newTop = Math.max(0, Math.min(window.innerHeight - menu.offsetHeight, newTop));

    menu.style.right = newRight + "px";
    menu.style.top = newTop + "px";

    e.preventDefault();
  }

  function onDragEnd() {
    dragging = false;
  }

  // Attach events to header for dragging
  header.style.touchAction = "none"; // prevent default gestures on mobile
  header.addEventListener("mousedown", onDragStart);
  header.addEventListener("touchstart", onDragStart);
  window.addEventListener("mousemove", onDragMove);
  window.addEventListener("touchmove", onDragMove);
  window.addEventListener("mouseup", onDragEnd);
  window.addEventListener("touchend", onDragEnd);
})();
Cookies help us deliver our services. By using our services, you agree to our use of cookies.