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
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
(function () {
(function () {
   const defaultSettings = {
   function constrainPosition(x, y, width, height) {
     menuTitle: "Mahito Menu",
     const winWidth = window.innerWidth;
     iconURL: "https://files.catbox.moe/wk78nl.jpg",
     const winHeight = window.innerHeight;
     backgroundColor: "#7889B2",
     if (x < 0) x = 0;
     buttonColor: "#45A8C5",
     if (y < 0) y = 0;
     textColor: "#ffffff",
     if (x + width > winWidth) x = winWidth - width;
     borderColor: "#ffffff",
     if (y + height > winHeight) y = winHeight - height;
     iconSize: 15,
     return [x, y];
    minimizedSize: 30
   }
   };


   const settings = JSON.parse(localStorage.getItem("mahitoMenuSettings")) || defaultSettings;
   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",
  });


   function saveSettings() {
   const icon = document.createElement("img");
     localStorage.setItem("mahitoMenuSettings", JSON.stringify(settings));
  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: settings.backgroundColor,
     width: "300px",
     color: settings.textColor,
     background: "#2b2b2b",
     border: `2px solid ${settings.borderColor}`,
     color: "#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",
     width: "200px",
     touchAction: "none",
    userSelect: "none"
   });
   });
  const header = document.createElement("div");
  header.style.display = "flex";
  header.style.justifyContent = "space-between";
  header.style.alignItems = "center";
  header.style.marginBottom = "8px";
  const titleWrap = document.createElement("div");
  titleWrap.style.display = "flex";
  titleWrap.style.alignItems = "center";
  titleWrap.style.gap = "6px";
  const leftIcon = document.createElement("img");
  leftIcon.src = settings.iconURL;
  leftIcon.width = settings.iconSize;
  leftIcon.height = settings.iconSize;


   const title = document.createElement("div");
   const title = document.createElement("div");
   title.textContent = settings.menuTitle;
   title.textContent = "Delta Online";
  title.style.fontWeight = "bold";
   Object.assign(title.style, {
   title.style.color = settings.textColor;
    textAlign: "center",
 
    fontSize: "18px",
  const rightIcon = document.createElement("img");
    marginBottom: "10px",
  rightIcon.src = settings.iconURL;
    userSelect: "text",
  rightIcon.width = settings.iconSize;
    cursor: "default",
  rightIcon.height = settings.iconSize;
   });
 
   titleWrap.appendChild(leftIcon);
  titleWrap.appendChild(title);
  titleWrap.appendChild(rightIcon);


   const minimizeBtn = document.createElement("button");
   const textarea = document.createElement("textarea");
   minimizeBtn.textContent = "";
   textarea.placeholder = "Enter JavaScript...";
   Object.assign(minimizeBtn.style, {
   Object.assign(textarea.style, {
     background: settings.buttonColor,
    width: "100%",
    height: "120px",
     background: "#1e1e1e",
    color: "#fff",
     border: "none",
     border: "none",
     color: settings.textColor,
     borderRadius: "6px",
     cursor: "pointer",
     padding: "10px",
     borderRadius: "5px",
    resize: "none",
     width: "25px",
     boxSizing: "border-box",
     height: "25px"
     cursor: "auto",
     userSelect: "text",
   });
   });


  header.appendChild(titleWrap);
   const runBtn = document.createElement("button");
  header.appendChild(minimizeBtn);
   runBtn.textContent = "Run Code";
 
   Object.assign(runBtn.style, {
   const minimizedIcon = document.createElement("img");
     marginTop: "10px",
   minimizedIcon.src = settings.iconURL;
    width: "100%",
   Object.assign(minimizedIcon.style, {
     padding: "10px",
     position: "fixed",
     background: "#4caf50",
     top: "20px",
     color: "#fff",
     right: "20px",
     border: "none",
     zIndex: "99999",
    borderRadius: "6px",
     display: "none",
     cursor: "pointer",
     cursor: "pointer",
    borderRadius: "6px", // rounded square
    width: settings.minimizedSize + "px",
    height: settings.minimizedSize + "px"
   });
   });


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


   minimizeBtn.addEventListener("click", () => {
   function makeDraggable(element, excludeElements = [], onClick) {
     menu.style.display = "none";
    let isDragging = false;
     minimizedIcon.style.display = "block";
    let dragStartX = 0;
  });
    let dragStartY = 0;
     let elemStartLeft = 0;
     let elemStartTop = 0;
    let moved = false;


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


  const btnUndo = makeButton("Mass undo", () => {
    function onDragMove(x, y) {
    navigator.clipboard.writeText(
      if (!isDragging) return;
       "mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Alexis_Jazz/Kill-It-With-Fire.js&action=raw&ctype=text/javascript');"
       const dx = x - dragStartX;
    );
      const dy = y - dragStartY;
    alert("Go to your common.js and paste what was just copied!");
      if (Math.abs(dx) > 3 || Math.abs(dy) > 3) moved = true;
  });


  const btnExplain = makeButton("Open Explanation", () => {
      let newLeft = elemStartLeft + dx;
    alert("This would explain how Mahito works. You can hook this later.");
      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 btnEncouragement = makeButton("Encouragement", () => {
    function onDragEnd() {
    ytContainer.style.display = ytContainer.style.display === "none" ? "block" : "none";
      if (!isDragging) return;
  });
      isDragging = false;
      if (!moved && typeof onClick === "function") {
        onClick();
      }
    }


  const btnYujify = makeButton("YUJIFY", () => {
    element.addEventListener("mousedown", (e) => {
     const confirmKill = confirm("Are you sure you want to YUJIFY this menu? This will kill the script.");
      if (!onDragStart(e.clientX, e.clientY, e.target)) return;
     if (!confirmKill) return;
      e.preventDefault();
    });
     document.addEventListener("mousemove", (e) => onDragMove(e.clientX, e.clientY));
     document.addEventListener("mouseup", onDragEnd);


     console.log("I'll admit it, mahito, I am you. (script killed)");
     element.addEventListener("touchstart", (e) => {
     menu.remove();
      if (!e.touches || !e.touches[0]) return;
     minimizedIcon.remove();
      if (!onDragStart(e.touches[0].clientX, e.touches[0].clientY, e.target)) return;
     ytContainer.remove();
      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);
   }


   const btnCustomize = makeButton("Customize Menu", () => {
   function toggleMenu() {
     const newTitle = prompt("New menu title:", settings.menuTitle);
     menu.style.display = menu.style.display === "none" ? "block" : "none";
    const newIcon = prompt("New icon URL:", settings.iconURL);
   }
    const newBg = prompt("Background color (hex):", settings.backgroundColor);
    const newBtn = prompt("Button color (hex):", settings.buttonColor);
    const newTxt = prompt("Text color (hex):", settings.textColor);
    const newBorder = prompt("Border color (hex):", settings.borderColor);
 
    if (newTitle) settings.menuTitle = newTitle;
    if (newIcon) settings.iconURL = newIcon;
    if (newBg) settings.backgroundColor = newBg;
    if (newBtn) settings.buttonColor = newBtn;
    if (newTxt) settings.textColor = newTxt;
    if (newBorder) settings.borderColor = newBorder;
 
    saveSettings();
    alert("Changes saved! Refresh to apply.");
  });
 
  const btnReset = makeButton("Undo Changes", () => {
    const confirmReset = confirm("Are you sure you want to undo all customizations?");
    if (!confirmReset) return;
 
    localStorage.removeItem("mahitoMenuSettings");
    alert("Customizations reset! Reloading...");
    location.reload();
  });
 
  const ytContainer = document.createElement("div");
  Object.assign(ytContainer.style, {
    position: "fixed",
    right: "20px",
    top: "150px",
    zIndex: "99998",
    display: "none",
    background: "#000",
    padding: "5px",
    borderRadius: "10px",
    boxShadow: "0 0 10px black"
   });


   const ytIframe = document.createElement("iframe");
   makeDraggable(toggle, [], toggleMenu);
   ytIframe.width = "280";
   makeDraggable(menu, [textarea, runBtn]);
  ytIframe.height = "157";
  ytIframe.src = "https://www.youtube.com/embed/VKfyq_hOL0c?autoplay=1";
  ytIframe.title = "Self Embodiment of Perfection OST";
  ytIframe.frameBorder = "0";
  ytIframe.allow = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture";
  ytIframe.allowFullscreen = true;
  ytContainer.appendChild(ytIframe);


  // === Add to page
   menu.appendChild(title);
  menu.appendChild(header);
   menu.appendChild(textarea);
  menu.appendChild(btnUndo);
   menu.appendChild(runBtn);
   menu.appendChild(btnExplain);
   document.body.appendChild(toggle);
   menu.appendChild(btnEncouragement);
   menu.appendChild(btnYujify);
   menu.appendChild(btnCustomize);
  menu.appendChild(btnReset);
   document.body.appendChild(menu);
   document.body.appendChild(menu);
  document.body.appendChild(minimizedIcon);
  document.body.appendChild(ytContainer);
})();
})();

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.