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
 
(36 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 #fff",
     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: "180px"
   });
   });
  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",
  header.appendChild(img1);
    background: "#1e1e1e",
  header.appendChild(title);
    color: "#fff",
  header.appendChild(img2);
    border: "none",
 
    borderRadius: "6px",
   function makeButton(text, onclick) {
    padding: "10px",
    const btn = document.createElement("button");
    resize: "none",
    btn.textContent = text;
     boxSizing: "border-box",
    btn.onclick = onclick;
     cursor: "auto",
    Object.assign(btn.style, {
     userSelect: "text",
      marginBottom: "6px",
      width: "100%",
      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", () => {
   const runBtn = document.createElement("button");
     alert("Open Explanation clicked");
  runBtn.textContent = "Run Code";
  Object.assign(runBtn.style, {
     marginTop: "10px",
    width: "100%",
    padding: "10px",
    background: "#4caf50",
    color: "#fff",
    border: "none",
    borderRadius: "6px",
    cursor: "pointer",
   });
   });


   // YouTube embed container (floating below the menu)
   runBtn.onclick = () => {
  const ytContainer = document.createElement("div");
    try {
  ytContainer.style.position = "fixed";
      eval(textarea.value);
  ytContainer.style.right = "20px";
    } catch (e) {
  ytContainer.style.top = "150px"; // slightly below the menu
      alert("Error: " + e.message);
  ytContainer.style.zIndex = "99998";
    }
  ytContainer.style.display = "none";
   };
  ytContainer.style.background = "#000";
  ytContainer.style.padding = "5px";
  ytContainer.style.borderRadius = "10px";
   ytContainer.style.boxShadow = "0 0 10px black";


   const ytIframe = document.createElement("iframe");
   function makeDraggable(element, excludeElements = [], onClick) {
  ytIframe.width = "280";
    let isDragging = false;
  ytIframe.height = "157";
    let dragStartX = 0;
  ytIframe.src = "https://www.youtube.com/embed/VKfyq_hOL0c?autoplay=1";
    let dragStartY = 0;
  ytIframe.title = "Self Embodiment of Perfection OST - Mahito Theme";
    let elemStartLeft = 0;
  ytIframe.frameBorder = "0";
    let elemStartTop = 0;
  ytIframe.allow =
     let moved = false;
     "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture";
  ytIframe.allowFullscreen = true;


  ytContainer.appendChild(ytIframe);
    function onDragStart(x, y, target) {
 
      if (excludeElements.includes(target)) return false;
  const btnEncouragement = makeButton("Encouragement", () => {
      isDragging = true;
    if (ytContainer.style.display === "none") {
      moved = false;
       ytContainer.style.display = "block";
      dragStartX = x;
    } else {
       dragStartY = y;
       ytContainer.style.display = "none";
      const rect = element.getBoundingClientRect();
       ytIframe.src = ytIframe.src; // reset to stop
       elemStartLeft = rect.left;
       elemStartTop = rect.top;
      return true;
     }
     }
  });


  menu.appendChild(header);
    function onDragMove(x, y) {
  menu.appendChild(btn1);
      if (!isDragging) return;
  menu.appendChild(btn2);
      const dx = x - dragStartX;
  menu.appendChild(btnEncouragement);
      const dy = y - dragStartY;
  document.body.appendChild(menu);
      if (Math.abs(dx) > 3 || Math.abs(dy) > 3) moved = true;
  document.body.appendChild(ytContainer);


  // === DRAGGING ===
      let newLeft = elemStartLeft + dx;
  let isDragging = false;
      let newTop = elemStartTop + dy;
  let offsetX = 0,
      [newLeft, newTop] = constrainPosition(
     offsetY = 0;
        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 startDrag(x, y) {
    function onDragEnd() {
    isDragging = true;
      if (!isDragging) return;
    const rect = menu.getBoundingClientRect();
      isDragging = false;
    offsetX = x - rect.left;
      if (!moved && typeof onClick === "function") {
    offsetY = y - rect.top;
        onClick();
    menu.style.left = rect.left + "px";
      }
    menu.style.top = rect.top + "px";
     }
     menu.style.right = "auto";
  }


  function doDrag(x, y) {
    element.addEventListener("mousedown", (e) => {
    if (!isDragging) return;
      if (!onDragStart(e.clientX, e.clientY, e.target)) return;
    const left = x - offsetX;
      e.preventDefault();
     const top = y - offsetY;
     });
     menu.style.left = left + "px";
     document.addEventListener("mousemove", (e) => onDragMove(e.clientX, e.clientY));
     menu.style.top = top + "px";
     document.addEventListener("mouseup", onDragEnd);


     // Move video container along with menu
     element.addEventListener("touchstart", (e) => {
     ytContainer.style.right = "auto";
      if (!e.touches || !e.touches[0]) return;
     ytContainer.style.left = left + "px";
      if (!onDragStart(e.touches[0].clientX, e.touches[0].clientY, e.target)) return;
     ytContainer.style.top = top + menu.offsetHeight + 10 + "px";
      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 stopDrag() {
   function toggleMenu() {
     isDragging = false;
     menu.style.display = menu.style.display === "none" ? "block" : "none";
   }
   }


   header.addEventListener("mousedown", (e) => {
   makeDraggable(toggle, [], toggleMenu);
    startDrag(e.clientX, e.clientY);
  makeDraggable(menu, [textarea, runBtn]);
    e.preventDefault();
  });


   document.addEventListener("mousemove", (e) => {
   menu.appendChild(title);
    doDrag(e.clientX, e.clientY);
   menu.appendChild(textarea);
   });
   menu.appendChild(runBtn);
 
   document.body.appendChild(toggle);
  document.addEventListener("mouseup", stopDrag);
   document.body.appendChild(menu);
 
   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);
})();
})();

Latest revision as of 00:19, 29 June 2025

(function () {
  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");
  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);
})();
Cookies help us deliver our services. By using our services, you agree to our use of cookies.