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
 
(63 intermediate revisions by the same user not shown)
Line 1: Line 1:
(function() {
(function () {
    // Create a container
  function constrainPosition(x, y, width, height) {
    const menu = document.createElement("div");
     const winWidth = window.innerWidth;
     menu.id = "mahitoMenu";
     const winHeight = window.innerHeight;
    menu.style.position = "fixed";
     if (x < 0) x = 0;
     menu.style.top = "20px";
     if (y < 0) y = 0;
    menu.style.right = "20px";
     if (x + width > winWidth) x = winWidth - width;
     menu.style.padding = "10px";
     if (y + height > winHeight) y = winHeight - height;
     menu.style.backgroundColor = "#111";
     return [x, y];
     menu.style.color = "#fff";
  }
     menu.style.border = "2px solid #666";
     menu.style.zIndex = "9999";
    menu.style.fontFamily = "monospace";
    menu.style.borderRadius = "10px";
    menu.style.boxShadow = "0 0 10px rgba(0,0,0,0.5)";


    // Title
  const toggle = document.createElement("button");
    const title = document.createElement("div");
  toggle.id = "delta-toggle";
    title.textContent = "💀 Mahito Menu 💀";
  Object.assign(toggle.style, {
    title.style.fontWeight = "bold";
    position: "fixed",
     title.style.marginBottom = "8px";
    bottom: "20px",
     menu.appendChild(title);
    right: "20px",
    padding: "0",
    background: "#2b2b2b",
    border: "none",
    borderRadius: "12px",
    zIndex: 9998,
    cursor: "move",
     userSelect: "none",
     touchAction: "none",
  });


    // Add a button (example)
  const icon = document.createElement("img");
    const btn = document.createElement("button");
  icon.src = "https://files.catbox.moe/uodscw.png";
    btn.textContent = "Transfigure Stuff";
  icon.alt = "Delta";
    btn.style.background = "#444";
  Object.assign(icon.style, {
    btn.style.color = "#fff";
    width: "48px",
     btn.style.border = "none";
     height: "48px",
     btn.style.padding = "5px 10px";
     borderRadius: "12px",
     btn.style.cursor = "pointer";
     display: "block",
     btn.onclick = function() {
     pointerEvents: "none",
        alert("You have been transfigured 💀");
  });
    };
  toggle.appendChild(icon);
    menu.appendChild(btn);


     // Add the menu to the page
  const menu = document.createElement("div");
    document.body.appendChild(menu);
  menu.id = "delta-menu";
  Object.assign(menu.style, {
    display: "none",
    position: "fixed",
    bottom: "80px",
    right: "20px",
    width: "300px",
    background: "#2b2b2b",
    color: "#fff",
    borderRadius: "10px",
    padding: "15px",
    boxShadow: "0 0 10px rgba(0,0,0,0.5)",
    zIndex: 9999,
    fontFamily: "monospace",
    cursor: "move",
    userSelect: "none",
    touchAction: "none",
  });
 
  const title = document.createElement("div");
  title.textContent = "Delta Online";
  Object.assign(title.style, {
    textAlign: "center",
    fontSize: "18px",
    marginBottom: "10px",
    userSelect: "text",
    cursor: "default",
  });
 
  const textarea = document.createElement("textarea");
  textarea.placeholder = "Enter JavaScript...";
  Object.assign(textarea.style, {
    width: "100%",
    height: "120px",
    background: "#1e1e1e",
    color: "#fff",
    border: "none",
    borderRadius: "6px",
    padding: "10px",
    resize: "none",
    boxSizing: "border-box",
    cursor: "auto",
    userSelect: "text",
  });
 
  const runBtn = document.createElement("button");
  runBtn.textContent = "Run Code";
  Object.assign(runBtn.style, {
    marginTop: "10px",
    width: "100%",
    padding: "10px",
    background: "#4caf50",
    color: "#fff",
    border: "none",
    borderRadius: "6px",
    cursor: "pointer",
  });
 
  runBtn.onclick = () => {
    try {
      eval(textarea.value);
    } catch (e) {
      alert("Error: " + e.message);
    }
  };
 
  function makeDraggable(element, excludeElements = [], onClick) {
    let isDragging = false;
    let dragStartX = 0;
    let dragStartY = 0;
    let elemStartLeft = 0;
    let elemStartTop = 0;
    let moved = false;
 
    function onDragStart(x, y, target) {
      if (excludeElements.includes(target)) return false;
      isDragging = true;
      moved = false;
      dragStartX = x;
      dragStartY = y;
      const rect = element.getBoundingClientRect();
      elemStartLeft = rect.left;
      elemStartTop = rect.top;
      return true;
    }
 
    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;
 
      let newLeft = elemStartLeft + dx;
      let newTop = elemStartTop + dy;
      [newLeft, newTop] = constrainPosition(
        newLeft,
        newTop,
        element.offsetWidth,
        element.offsetHeight
      );
      element.style.left = newLeft + "px";
      element.style.top = newTop + "px";
      element.style.bottom = "auto";
      element.style.right = "auto";
    }
 
    function onDragEnd() {
      if (!isDragging) return;
      isDragging = false;
      if (!moved && typeof onClick === "function") {
        onClick();
      }
    }
 
    element.addEventListener("mousedown", (e) => {
      if (!onDragStart(e.clientX, e.clientY, e.target)) return;
      e.preventDefault();
    });
    document.addEventListener("mousemove", (e) => onDragMove(e.clientX, e.clientY));
    document.addEventListener("mouseup", onDragEnd);
 
    element.addEventListener("touchstart", (e) => {
      if (!e.touches || !e.touches[0]) return;
      if (!onDragStart(e.touches[0].clientX, e.touches[0].clientY, e.target)) return;
      e.preventDefault();
    });
    document.addEventListener(
      "touchmove",
      (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 toggleMenu() {
     menu.style.display = menu.style.display === "none" ? "block" : "none";
  }
 
  makeDraggable(toggle, [], toggleMenu);
  makeDraggable(menu, [textarea, runBtn]);
 
  menu.appendChild(title);
  menu.appendChild(textarea);
  menu.appendChild(runBtn);
  document.body.appendChild(toggle);
  document.body.appendChild(menu);
})();
})();