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
 
(49 intermediate revisions by the same user not shown)
Line 1: Line 1:
(function () {
(function () {
   const iconURL = "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",
     padding: "10px",
     width: "300px",
     backgroundColor: "#111",
     background: "#2b2b2b",
     color: "#fff",
     color: "#fff",
    border: "2px solid #666",
    zIndex: "9999",
    fontFamily: "monospace",
     borderRadius: "10px",
     borderRadius: "10px",
    padding: "15px",
     boxShadow: "0 0 10px rgba(0,0,0,0.5)",
     boxShadow: "0 0 10px rgba(0,0,0,0.5)",
    zIndex: 9999,
    fontFamily: "monospace",
    cursor: "move",
     userSelect: "none",
     userSelect: "none",
    touchAction: "none",
   });
   });


   const header = document.createElement("div");
   const title = document.createElement("div");
   Object.assign(header.style, {
  title.textContent = "Delta Online";
     display: "flex",
   Object.assign(title.style, {
    justifyContent: "center",
     textAlign: "center",
     alignItems: "center",
     fontSize: "18px",
     gap: "6px",
     marginBottom: "10px",
     marginBottom: "8px",
     userSelect: "text",
     fontWeight: "bold",
     cursor: "default",
   });
   });


   const leftIcon = document.createElement("img");
   const textarea = document.createElement("textarea");
   leftIcon.src = iconURL;
   textarea.placeholder = "Enter JavaScript...";
   leftIcon.width = 15;
   Object.assign(textarea.style, {
   leftIcon.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",
   });


   const rightIcon = document.createElement("img");
   const runBtn = document.createElement("button");
   rightIcon.src = iconURL;
   runBtn.textContent = "Run Code";
   rightIcon.width = 15;
   Object.assign(runBtn.style, {
  rightIcon.height = 15;
    marginTop: "10px",
 
    width: "100%",
  const title = document.createElement("span");
    padding: "10px",
  title.textContent = "Mahito Menu";
    background: "#4caf50",
    color: "#fff",
    border: "none",
    borderRadius: "6px",
    cursor: "pointer",
  });


   header.appendChild(leftIcon);
   runBtn.onclick = () => {
  header.appendChild(title);
  header.appendChild(rightIcon);
  menu.appendChild(header);
 
  const undoBtn = document.createElement("button");
  undoBtn.textContent = "Mass undo";
  undoBtn.onclick = async () => {
    const text = "mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Alexis_Jazz/Kill-It-With-Fire.js&action=raw&ctype=text/javascript');";
     try {
     try {
       await navigator.clipboard.writeText(text);
       eval(textarea.value);
      alert("Go to your common.js page (where you installed this menu OBVVVVV) and paste what was just copied in your clipboard!");
     } catch (e) {
     } catch (e) {
       alert("Clipboard failed: " + e.message);
       alert("Error: " + e.message);
     }
     }
   };
   };


   const explanationBtn = document.createElement("button");
   function makeDraggable(element, excludeElements = [], onClick) {
  explanationBtn.textContent = "Open Explanation";
    let isDragging = false;
  explanationBtn.onclick = () => alert("Explanation placeholder!");
    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";
  }


   undoBtn.style.marginBottom = "6px";
   makeDraggable(toggle, [], toggleMenu);
  menu.appendChild(undoBtn);
   makeDraggable(menu, [textarea, runBtn]);
   menu.appendChild(explanationBtn);


  menu.appendChild(title);
  menu.appendChild(textarea);
  menu.appendChild(runBtn);
  document.body.appendChild(toggle);
   document.body.appendChild(menu);
   document.body.appendChild(menu);
})();
})();