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
 
(34 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);


  // === MENU CONTAINER ===
   const menu = document.createElement("div");
   const menu = document.createElement("div");
  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",
   });
   });


  // === MINIMIZED ICON ===
   const title = document.createElement("div");
   const minimizedIcon = document.createElement("img");
   title.textContent = "Delta Online";
   minimizedIcon.src = iconURL;
   Object.assign(title.style, {
  minimizedIcon.width = 30;
     textAlign: "center",
  minimizedIcon.height = 30;
     fontSize: "18px",
   Object.assign(minimizedIcon.style, {
     marginBottom: "10px",
     position: "fixed",
     userSelect: "text",
     top: "20px",
     cursor: "default",
     right: "20px",
     display: "none",
     cursor: "pointer",
    zIndex: "99999"
   });
   });


   minimizedIcon.addEventListener("click", () => {
   const textarea = document.createElement("textarea");
    menu.style.display = "block";
  textarea.placeholder = "Enter JavaScript...";
    minimizedIcon.style.display = "none";
  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",
   });
   });


  // === HEADER WITH MINIMIZE BUTTON ===
   const runBtn = document.createElement("button");
   const header = document.createElement("div");
   runBtn.textContent = "Run Code";
   header.style.display = "flex";
   Object.assign(runBtn.style, {
   header.style.alignItems = "center";
    marginTop: "10px",
  header.style.justifyContent = "space-between";
    width: "100%",
  header.style.marginBottom = "8px";
    padding: "10px",
  header.style.cursor = "grab";
    background: "#4caf50",
 
     color: "#fff",
  const titleWrap = document.createElement("div");
  titleWrap.style.display = "flex";
  titleWrap.style.gap = "6px";
  titleWrap.style.alignItems = "center";
 
  const img1 = document.createElement("img");
  img1.src = iconURL;
  img1.width = 15;
  img1.height = 15;
 
  const title = document.createElement("div");
  title.textContent = "Mahito Menu";
  title.style.fontWeight = "bold";
  title.style.color = "#fff";
 
  const img2 = document.createElement("img");
  img2.src = iconURL;
  img2.width = 15;
  img2.height = 15;
 
  titleWrap.appendChild(img1);
  titleWrap.appendChild(title);
  titleWrap.appendChild(img2);
 
  const minimizeBtn = document.createElement("button");
  minimizeBtn.textContent = "–";
  Object.assign(minimizeBtn.style, {
     background: "#45A8C5",
     border: "none",
     border: "none",
     color: "#fff",
     borderRadius: "6px",
     cursor: "pointer",
     cursor: "pointer",
    borderRadius: "5px",
    width: "25px",
    height: "25px",
    fontSize: "18px",
    lineHeight: "20px",
   });
   });


   minimizeBtn.addEventListener("click", () => {
   runBtn.onclick = () => {
     menu.style.display = "none";
     try {
     minimizedIcon.style.display = "block";
      eval(textarea.value);
   });
     } catch (e) {
      alert("Error: " + e.message);
    }
   };


   header.appendChild(titleWrap);
   function makeDraggable(element, excludeElements = [], onClick) {
  header.appendChild(minimizeBtn);
    let isDragging = false;
    let dragStartX = 0;
    let dragStartY = 0;
    let elemStartLeft = 0;
    let elemStartTop = 0;
    let moved = false;


  // === BUTTON FACTORY ===
    function onDragStart(x, y, target) {
  function makeButton(text, onclick) {
      if (excludeElements.includes(target)) return false;
    const btn = document.createElement("button");
      isDragging = true;
    btn.textContent = text;
      moved = false;
    btn.onclick = onclick;
       dragStartX = x;
    Object.assign(btn.style, {
       dragStartY = y;
       marginBottom: "6px",
       const rect = element.getBoundingClientRect();
       width: "100%",
       elemStartLeft = rect.left;
       cursor: "pointer",
       elemStartTop = rect.top;
       background: "#45A8C5",
       return true;
       color: "#fff",
     }
       border: "none",
      padding: "5px 10px",
      borderRadius: "5px",
    });
     return btn;
  }


  const btnUndo = makeButton("Mass undo", () => {
    function onDragMove(x, y) {
    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');");
      if (!isDragging) return;
  });
      const dx = x - dragStartX;
      const dy = y - dragStartY;
      if (Math.abs(dx) > 3 || Math.abs(dy) > 3) moved = true;


  const btnExplain = makeButton("Open Explanation", () => {
      let newLeft = elemStartLeft + dx;
    alert("Open Explanation clicked");
      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";
    }


  const btnEncourage = makeButton("Encouragement", () => {
    function onDragEnd() {
    if (ytContainer.style.display === "none") {
      if (!isDragging) return;
       ytContainer.style.display = "block";
       isDragging = false;
    } else {
       if (!moved && typeof onClick === "function") {
       ytContainer.style.display = "none";
        onClick();
       ytIframe.src = ytIframe.src;
       }
     }
     }
  });


  // === YOUTUBE CONTAINER ===
    element.addEventListener("mousedown", (e) => {
  const ytContainer = document.createElement("div");
      if (!onDragStart(e.clientX, e.clientY, e.target)) return;
  ytContainer.style.position = "fixed";
      e.preventDefault();
  ytContainer.style.right = "20px";
    });
  ytContainer.style.top = "150px";
    document.addEventListener("mousemove", (e) => onDragMove(e.clientX, e.clientY));
  ytContainer.style.zIndex = "99998";
    document.addEventListener("mouseup", onDragEnd);
  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");
    element.addEventListener("touchstart", (e) => {
  ytIframe.width = "280";
      if (!e.touches || !e.touches[0]) return;
  ytIframe.height = "157";
      if (!onDragStart(e.touches[0].clientX, e.touches[0].clientY, e.target)) return;
  ytIframe.src = "https://www.youtube.com/embed/VKfyq_hOL0c?autoplay=1";
      e.preventDefault();
  ytIframe.title = "Self Embodiment of Perfection OST - Mahito Theme";
    });
  ytIframe.frameBorder = "0";
    document.addEventListener(
  ytIframe.allow = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture";
      "touchmove",
  ytIframe.allowFullscreen = true;
      (e) => {
 
        if (!e.touches || !e.touches[0]) return;
  ytContainer.appendChild(ytIframe);
        onDragMove(e.touches[0].clientX, e.touches[0].clientY);
 
      },
  // === ASSEMBLE MENU ===
      { passive: false }
  menu.appendChild(header);
     );
  menu.appendChild(btnUndo);
     document.addEventListener("touchend", onDragEnd);
  menu.appendChild(btnExplain);
     document.addEventListener("touchcancel", onDragEnd);
  menu.appendChild(btnEncourage);
 
  document.body.appendChild(menu);
  document.body.appendChild(minimizedIcon);
  document.body.appendChild(ytContainer);
 
  // === DRAGGING SUPPORT (menu + icon) ===
  let isDragging = false;
  let offsetX = 0, offsetY = 0;
 
  function startDrag(x, y) {
     isDragging = true;
     const rect = menu.getBoundingClientRect();
    offsetX = x - rect.left;
    offsetY = y - rect.top;
    menu.style.left = rect.left + "px";
     menu.style.top = rect.top + "px";
    menu.style.right = "auto";
   }
   }


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


   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.addEventListener("mousemove", (e) => doDrag(e.clientX, e.clientY));
   document.body.appendChild(menu);
   document.addEventListener("mouseup", stopDrag);
  header.addEventListener("touchstart", (e) => {
    const t = e.touches[0];
    startDrag(t.clientX, t.clientY);
    e.preventDefault();
  });
   document.addEventListener("touchmove", (e) => {
    if (!isDragging) return;
    const t = e.touches[0];
    doDrag(t.clientX, t.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.