User:Stumblean/common.js: Difference between revisions
No edit summary Tags: Mobile edit Mobile web edit Advanced mobile edit |
No edit summary Tags: Mobile edit Mobile web edit Advanced mobile edit |
||
Line 1: | Line 1: | ||
(function () { | (function () { | ||
const | const iconURL = "https://files.catbox.moe/wk78nl.jpg"; | ||
const menu = document.createElement("div"); | const menu = document.createElement("div"); | ||
Line 7: | Line 7: | ||
position: "fixed", | position: "fixed", | ||
top: "20px", | top: "20px", | ||
right: "20px", | right: "20px", | ||
padding: "10px", | padding: "10px", | ||
Line 18: | Line 17: | ||
boxShadow: "0 0 10px rgba(0,0,0,0.5)", | boxShadow: "0 0 10px rgba(0,0,0,0.5)", | ||
userSelect: "none", | userSelect: "none", | ||
touchAction: "none | touchAction: "none" | ||
}); | }); | ||
Line 26: | Line 24: | ||
cursor: "grab", | cursor: "grab", | ||
display: "flex", | display: "flex", | ||
alignItems: "center", | alignItems: "center", | ||
marginBottom: "8px" | marginBottom: "8px", | ||
gap: "6px" | |||
}); | }); | ||
const | // Replace title with catbox image | ||
const icon = document.createElement("img"); | |||
icon.src = iconURL; | |||
header.appendChild( | icon.width = 10; | ||
icon.height = 10; | |||
icon.alt = "Mahito"; | |||
icon.style.borderRadius = "2px"; | |||
header.appendChild(icon); | |||
menu.appendChild(header); | menu.appendChild(header); | ||
Line 60: | Line 52: | ||
openBtn.onclick = () => console.log("Open Explanation clicked"); | openBtn.onclick = () => 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 logic (mouse + touch) | ||
let isDragging = false, offsetX = 0, offsetY = 0; | let isDragging = false, offsetX = 0, offsetY = 0; | ||
Line 118: | Line 64: | ||
offsetX = x - rect.left; | offsetX = x - rect.left; | ||
offsetY = y - rect.top; | offsetY = y - rect.top; | ||
menu.style.right = "auto"; | menu.style.right = "auto"; | ||
} | } | ||
Line 132: | Line 78: | ||
} | } | ||
// Mouse events | |||
header.addEventListener("mousedown", e => { | header.addEventListener("mousedown", e => { | ||
startDrag(e.clientX, e.clientY); | startDrag(e.clientX, e.clientY); | ||
Line 139: | Line 86: | ||
document.addEventListener("mouseup", stopDrag); | document.addEventListener("mouseup", stopDrag); | ||
// Touch events | |||
header.addEventListener("touchstart", e => { | header.addEventListener("touchstart", e => { | ||
const touch = e.touches[0]; | const touch = e.touches[0]; |