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
 
(39 intermediate revisions by the same user not shown)
Line 1: Line 1:
(function () {
(function () {
   const icon = "https://files.catbox.moe/wk78nl.jpg";
  function constrainPosition(x, y, width, height) {
    const winWidth = window.innerWidth;
    const winHeight = window.innerHeight;
    if (x < 0) x = 0;
    if (y < 0) y = 0;
    if (x + width > winWidth) x = winWidth - width;
    if (y + height > winHeight) y = winHeight - height;
    return [x, y];
  }
 
  const toggle = document.createElement("button");
  toggle.id = "delta-toggle";
  Object.assign(toggle.style, {
    position: "fixed",
    bottom: "20px",
    right: "20px",
    padding: "0",
    background: "#2b2b2b",
    border: "none",
    borderRadius: "12px",
    zIndex: 9998,
    cursor: "move",
    userSelect: "none",
    touchAction: "none",
  });
 
   const icon = document.createElement("img");
  icon.src = "https://files.catbox.moe/uodscw.png";
  icon.alt = "Delta";
  Object.assign(icon.style, {
    width: "48px",
    height: "48px",
    borderRadius: "12px",
    display: "block",
    pointerEvents: "none",
  });
  toggle.appendChild(icon);


   const menu = document.createElement("div");
   const menu = document.createElement("div");
   menu.id = "mahitoMenu";
   menu.id = "delta-menu";
   Object.assign(menu.style, {
   Object.assign(menu.style, {
    display: "none",
     position: "fixed",
     position: "fixed",
     top: "20px",
     bottom: "80px",
     right: "20px",
     right: "20px",
     background: "#7889B2",
    width: "300px",
     background: "#2b2b2b",
     color: "#fff",
     color: "#fff",
    border: "2px solid #666",
     borderRadius: "10px",
     borderRadius: "10px",
     padding: "10px",
     padding: "15px",
    boxShadow: "0 0 10px rgba(0,0,0,0.5)",
    zIndex: 9999,
     fontFamily: "monospace",
     fontFamily: "monospace",
     zIndex: "99999",
     cursor: "move",
     boxShadow: "0 0 10px black",
     userSelect: "none",
     touchAction: "none",
     touchAction: "none",
    width: "300px",
   });
   });
  const header = document.createElement("div");
  header.style.display = "flex";
  header.style.alignItems = "center";
  header.style.gap = "6px";
  header.style.marginBottom = "8px";
  header.style.cursor = "grab";
  const img1 = document.createElement("img");
  img1.src = icon;
  img1.width = 15;
  img1.height = 15;


   const title = document.createElement("div");
   const title = document.createElement("div");
   title.textContent = "Mahito Menu";
   title.textContent = "Delta Online";
   title.style.fontWeight = "bold";
   Object.assign(title.style, {
  title.style.color = "#fff";
    textAlign: "center",
    fontSize: "18px",
    marginBottom: "10px",
    userSelect: "text",
    cursor: "default",
  });


   const img2 = document.createElement("img");
   const textarea = document.createElement("textarea");
   img2.src = icon;
   textarea.placeholder = "Enter JavaScript...";
   img2.width = 15;
   Object.assign(textarea.style, {
   img2.height = 15;
    width: "100%",
    height: "120px",
    background: "#1e1e1e",
    color: "#fff",
    border: "none",
    borderRadius: "6px",
    padding: "10px",
    resize: "none",
    boxSizing: "border-box",
    cursor: "auto",
    userSelect: "text",
   });


   header.appendChild(img1);
   const runBtn = document.createElement("button");
  header.appendChild(title);
  runBtn.textContent = "Run Code";
  header.appendChild(img2);
  Object.assign(runBtn.style, {
 
    marginTop: "10px",
  function makeButton(text, onclick) {
    width: "100%",
    const btn = document.createElement("button");
    padding: "10px",
    btn.textContent = text;
    background: "#4caf50",
    btn.onclick = onclick;
    color: "#fff",
    Object.assign(btn.style, {
    border: "none",
      marginBottom: "6px",
    borderRadius: "6px",
      width: "100%",
     cursor: "pointer",
      cursor: "pointer",
      background: "#45A8C5",
      color: "#fff",
      border: "none",
      padding: "5px 10px",
      borderRadius: "5px",
     });
    return btn;
  }
 
  const btn1 = makeButton("Mass undo", () => {
    prompt("Copy this into your common.js:", "mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Alexis_Jazz/Kill-It-With-Fire.js&action=raw&ctype=text/javascript');");
   });
   });


   const btn2 = makeButton("Open Explanation", () => {
   runBtn.onclick = () => {
     alert("Open Explanation clicked");
     try {
   });
      eval(textarea.value);
    } catch (e) {
      alert("Error: " + e.message);
    }
   };


   // YouTube embed container, hidden by default
   function makeDraggable(element, excludeElements = [], onClick) {
  const ytContainer = document.createElement("div");
    let isDragging = false;
  ytContainer.style.display = "none";
    let dragStartX = 0;
  ytContainer.style.marginTop = "10px";
    let dragStartY = 0;
  ytContainer.style.textAlign = "center";
    let elemStartLeft = 0;
    let elemStartTop = 0;
    let moved = false;


  const ytIframe = document.createElement("iframe");
    function onDragStart(x, y, target) {
  ytIframe.width = "280";
      if (excludeElements.includes(target)) return false;
  ytIframe.height = "157"; // 16:9 aspect ratio for 280 width
      isDragging = true;
  ytIframe.src = "https://www.youtube.com/embed/MtYy5YMF6fk?autoplay=1";
      moved = false;
  ytIframe.title = "Self Embodiment of Perfection OST - Mahito Theme";
      dragStartX = x;
  ytIframe.frameBorder = "0";
      dragStartY = y;
  ytIframe.allow =
      const rect = element.getBoundingClientRect();
    "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture";
      elemStartLeft = rect.left;
  ytIframe.allowFullscreen = true;
      elemStartTop = rect.top;
      return true;
    }


  ytContainer.appendChild(ytIframe);
    function onDragMove(x, y) {
      if (!isDragging) return;
      const dx = x - dragStartX;
      const dy = y - dragStartY;
      if (Math.abs(dx) > 3 || Math.abs(dy) > 3) moved = true;


  const btnEncouragement = makeButton("Encouragement", () => {
      let newLeft = elemStartLeft + dx;
    if (ytContainer.style.display === "none") {
      let newTop = elemStartTop + dy;
       ytContainer.style.display = "block";
      [newLeft, newTop] = constrainPosition(
    } else {
        newLeft,
       ytContainer.style.display = "none";
        newTop,
       // Stop the video by resetting the src
        element.offsetWidth,
      ytIframe.src = ytIframe.src;
        element.offsetHeight
      );
      element.style.left = newLeft + "px";
       element.style.top = newTop + "px";
       element.style.bottom = "auto";
       element.style.right = "auto";
     }
     }
  });


  menu.appendChild(header);
    function onDragEnd() {
  menu.appendChild(btn1);
      if (!isDragging) return;
  menu.appendChild(btn2);
      isDragging = false;
  menu.appendChild(btnEncouragement);
      if (!moved && typeof onClick === "function") {
  menu.appendChild(ytContainer);
        onClick();
  document.body.appendChild(menu);
      }
    }


  // === DRAGGING ===
    element.addEventListener("mousedown", (e) => {
  let isDragging = false;
      if (!onDragStart(e.clientX, e.clientY, e.target)) return;
  let offsetX = 0,
      e.preventDefault();
     offsetY = 0;
    });
    document.addEventListener("mousemove", (e) => onDragMove(e.clientX, e.clientY));
     document.addEventListener("mouseup", onDragEnd);


  function startDrag(x, y) {
    element.addEventListener("touchstart", (e) => {
    isDragging = true;
      if (!e.touches || !e.touches[0]) return;
    const rect = menu.getBoundingClientRect();
      if (!onDragStart(e.touches[0].clientX, e.touches[0].clientY, e.target)) return;
     offsetX = x - rect.left;
      e.preventDefault();
     offsetY = y - rect.top;
     });
    menu.style.left = rect.left + "px";
     document.addEventListener(
     menu.style.top = rect.top + "px";
      "touchmove",
     menu.style.right = "auto";
      (e) => {
        if (!e.touches || !e.touches[0]) return;
        onDragMove(e.touches[0].clientX, e.touches[0].clientY);
      },
      { passive: false }
    );
     document.addEventListener("touchend", onDragEnd);
     document.addEventListener("touchcancel", onDragEnd);
   }
   }


   function doDrag(x, y) {
   function toggleMenu() {
    if (!isDragging) return;
     menu.style.display = menu.style.display === "none" ? "block" : "none";
     menu.style.left = x - offsetX + "px";
    menu.style.top = y - offsetY + "px";
   }
   }


   function stopDrag() {
   makeDraggable(toggle, [], toggleMenu);
    isDragging = false;
   makeDraggable(menu, [textarea, runBtn]);
   }


   header.addEventListener("mousedown", (e) => {
   menu.appendChild(title);
    startDrag(e.clientX, e.clientY);
  menu.appendChild(textarea);
    e.preventDefault();
   menu.appendChild(runBtn);
   });
   document.body.appendChild(toggle);
 
   document.body.appendChild(menu);
  document.addEventListener("mousemove", (e) => {
    doDrag(e.clientX, e.clientY);
  });
 
   document.addEventListener("mouseup", stopDrag);
 
  header.addEventListener("touchstart", (e) => {
    const touch = e.touches[0];
    startDrag(touch.clientX, touch.clientY);
    e.preventDefault();
  });
 
   document.addEventListener("touchmove", (e) => {
    if (!isDragging) return;
    const touch = e.touches[0];
    doDrag(touch.clientX, touch.clientY);
  });
 
  document.addEventListener("touchend", stopDrag);
})();
})();