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
Line 1: Line 1:
(function() {
(function () {
    const minimizedImgURL = "https://files.catbox.moe/wk78nl.jpg";
 
     const menu = document.createElement("div");
     const menu = document.createElement("div");
     menu.id = "mahitoMenu";
     menu.id = "mahitoMenu";
Line 14: Line 16:
     menu.style.boxShadow = "0 0 10px rgba(0,0,0,0.5)";
     menu.style.boxShadow = "0 0 10px rgba(0,0,0,0.5)";
     menu.style.userSelect = "none";
     menu.style.userSelect = "none";
     menu.style.touchAction = "none"; // prevents weird scrolling glitches
     menu.style.touchAction = "none";
    menu.style.width = "auto";


     // Header for dragging and minimizing
     // Header
     const header = document.createElement("div");
     const header = document.createElement("div");
     header.style.cursor = "grab";
     header.style.cursor = "grab";
Line 36: Line 39:
     minimizeBtn.style.cursor = "pointer";
     minimizeBtn.style.cursor = "pointer";
     minimizeBtn.style.marginLeft = "10px";
     minimizeBtn.style.marginLeft = "10px";
    minimizeBtn.onclick = function() {
        content.style.display = content.style.display === "none" ? "block" : "none";
    };
     header.appendChild(minimizeBtn);
     header.appendChild(minimizeBtn);
     menu.appendChild(header);
     menu.appendChild(header);


    // Content
     const content = document.createElement("div");
     const content = document.createElement("div");


Line 51: Line 52:
     openBtn.style.padding = "5px 10px";
     openBtn.style.padding = "5px 10px";
     openBtn.style.cursor = "pointer";
     openBtn.style.cursor = "pointer";
     openBtn.onclick = function() {
     openBtn.onclick = function () {
         console.log("Open Explanation clicked");
         console.log("Open Explanation clicked");
     };
     };
     content.appendChild(openBtn);
     content.appendChild(openBtn);
     menu.appendChild(content);
     menu.appendChild(content);
     document.body.appendChild(menu);
     document.body.appendChild(menu);


     // Dragging support for mouse + touch
    // Minimized image element (hidden at first)
     let isDragging = false, offsetX = 0, offsetY = 0;
    const minimizedIcon = document.createElement("img");
    minimizedIcon.src = minimizedImgURL;
    minimizedIcon.style.position = "fixed";
    minimizedIcon.style.top = "20px";
    minimizedIcon.style.right = "20px";
    minimizedIcon.style.width = "30px";
    minimizedIcon.style.height = "30px";
    minimizedIcon.style.borderRadius = "5px";
    minimizedIcon.style.cursor = "pointer";
    minimizedIcon.style.display = "none";
    minimizedIcon.style.zIndex = "9999";
    document.body.appendChild(minimizedIcon);
 
    // Minimize logic
    minimizeBtn.onclick = function () {
        menu.style.display = "none";
        minimizedIcon.style.display = "block";
    };
 
    // Restore logic
    minimizedIcon.onclick = function () {
        menu.style.display = "block";
        minimizedIcon.style.display = "none";
    };
 
     // Dragging (mouse + touch)
     let isDragging = false,
        offsetX = 0,
        offsetY = 0;


     function startDrag(x, y) {
     function startDrag(x, y) {
Line 89: Line 117:
     document.addEventListener("mouseup", stopDrag);
     document.addEventListener("mouseup", stopDrag);


     // Touch events (for mobile)
     // Touch events
     header.addEventListener("touchstart", e => {
     header.addEventListener("touchstart", e => {
         const touch = e.touches[0];
         const touch = e.touches[0];

Revision as of 00:49, 27 June 2025

(function () {
    const minimizedImgURL = "https://files.catbox.moe/wk78nl.jpg";

    const menu = document.createElement("div");
    menu.id = "mahitoMenu";
    menu.style.position = "fixed";
    menu.style.top = "20px";
    menu.style.right = "20px";
    menu.style.padding = "10px";
    menu.style.backgroundColor = "#111";
    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)";
    menu.style.userSelect = "none";
    menu.style.touchAction = "none";
    menu.style.width = "auto";

    // Header
    const header = document.createElement("div");
    header.style.cursor = "grab";
    header.style.display = "flex";
    header.style.justifyContent = "space-between";
    header.style.alignItems = "center";
    header.style.marginBottom = "8px";

    const title = document.createElement("div");
    title.textContent = "💀 Mahito Menu 💀";
    title.style.fontWeight = "bold";
    header.appendChild(title);

    const minimizeBtn = document.createElement("button");
    minimizeBtn.textContent = "➖";
    minimizeBtn.style.background = "#333";
    minimizeBtn.style.color = "#fff";
    minimizeBtn.style.border = "none";
    minimizeBtn.style.cursor = "pointer";
    minimizeBtn.style.marginLeft = "10px";
    header.appendChild(minimizeBtn);
    menu.appendChild(header);

    // Content
    const content = document.createElement("div");

    const openBtn = document.createElement("button");
    openBtn.textContent = "Open Explanation";
    openBtn.style.background = "#444";
    openBtn.style.color = "#fff";
    openBtn.style.border = "none";
    openBtn.style.padding = "5px 10px";
    openBtn.style.cursor = "pointer";
    openBtn.onclick = function () {
        console.log("Open Explanation clicked");
    };
    content.appendChild(openBtn);
    menu.appendChild(content);
    document.body.appendChild(menu);

    // Minimized image element (hidden at first)
    const minimizedIcon = document.createElement("img");
    minimizedIcon.src = minimizedImgURL;
    minimizedIcon.style.position = "fixed";
    minimizedIcon.style.top = "20px";
    minimizedIcon.style.right = "20px";
    minimizedIcon.style.width = "30px";
    minimizedIcon.style.height = "30px";
    minimizedIcon.style.borderRadius = "5px";
    minimizedIcon.style.cursor = "pointer";
    minimizedIcon.style.display = "none";
    minimizedIcon.style.zIndex = "9999";
    document.body.appendChild(minimizedIcon);

    // Minimize logic
    minimizeBtn.onclick = function () {
        menu.style.display = "none";
        minimizedIcon.style.display = "block";
    };

    // Restore logic
    minimizedIcon.onclick = function () {
        menu.style.display = "block";
        minimizedIcon.style.display = "none";
    };

    // Dragging (mouse + touch)
    let isDragging = false,
        offsetX = 0,
        offsetY = 0;

    function startDrag(x, y) {
        isDragging = true;
        const rect = menu.getBoundingClientRect();
        offsetX = x - rect.left;
        offsetY = y - rect.top;
        menu.style.right = "auto";
    }

    function doDrag(x, y) {
        if (isDragging) {
            menu.style.left = (x - offsetX) + "px";
            menu.style.top = (y - offsetY) + "px";
        }
    }

    function stopDrag() {
        isDragging = false;
    }

    // Mouse events
    header.addEventListener("mousedown", e => {
        startDrag(e.clientX, e.clientY);
        e.preventDefault();
    });
    document.addEventListener("mousemove", e => doDrag(e.clientX, e.clientY));
    document.addEventListener("mouseup", stopDrag);

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