User:Stumblean/common.js: Difference between revisions
Appearance
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 icon = "https://files.catbox.moe/wk78nl.jpg"; | const icon = "https://files.catbox.moe/wk78nl.jpg"; | ||
const menu = document.createElement("div"); | const menu = document.createElement("div"); | ||
Line 18: | Line 17: | ||
boxShadow: "0 0 10px black", | boxShadow: "0 0 10px black", | ||
touchAction: "none", | touchAction: "none", | ||
width: "300px", | |||
}); | }); | ||
Line 71: | Line 71: | ||
}); | }); | ||
const | // YouTube embed container, hidden by default | ||
const ytContainer = document.createElement("div"); | |||
ytContainer.style.display = "none"; | |||
ytContainer.style.marginTop = "10px"; | |||
ytContainer.style.textAlign = "center"; | |||
const ytIframe = document.createElement("iframe"); | |||
ytIframe.width = "280"; | |||
ytIframe.height = "157"; // 16:9 aspect ratio for 280 width | |||
ytIframe.src = "https://www.youtube.com/embed/MtYy5YMF6fk?autoplay=1"; | |||
ytIframe.title = "Self Embodiment of Perfection OST - Mahito Theme"; | |||
ytIframe.frameBorder = "0"; | |||
ytIframe.allow = | |||
"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"; | |||
ytIframe.allowFullscreen = true; | |||
ytContainer.appendChild(ytIframe); | |||
const btnEncouragement = makeButton("Encouragement", () => { | |||
if (ytContainer.style.display === "none") { | |||
ytContainer.style.display = "block"; | |||
} else { | |||
ytContainer.style.display = "none"; | |||
// Stop the video by resetting the src | |||
ytIframe.src = ytIframe.src; | |||
} | |||
}); | }); | ||
menu.appendChild(header); | menu.appendChild(header); | ||
menu.appendChild(btn1); | menu.appendChild(btn1); | ||
menu.appendChild(btn2); | menu.appendChild(btn2); | ||
menu.appendChild( | menu.appendChild(btnEncouragement); | ||
menu.appendChild(ytContainer); | |||
document.body.appendChild(menu); | document.body.appendChild(menu); | ||
// === DRAGGING === | // === DRAGGING === | ||
let isDragging = false; | let isDragging = false; | ||
let offsetX = 0, offsetY = 0; | let offsetX = 0, | ||
offsetY = 0; | |||
function startDrag(x, y) { | function startDrag(x, y) { |
Revision as of 21:17, 27 June 2025
(function () {
const icon = "https://files.catbox.moe/wk78nl.jpg";
const menu = document.createElement("div");
menu.id = "mahitoMenu";
Object.assign(menu.style, {
position: "fixed",
top: "20px",
right: "20px",
background: "#7889B2",
color: "#fff",
border: "2px solid #666",
borderRadius: "10px",
padding: "10px",
fontFamily: "monospace",
zIndex: "99999",
boxShadow: "0 0 10px black",
touchAction: "none",
width: "300px",
});
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");
title.textContent = "Mahito Menu";
title.style.fontWeight = "bold";
title.style.color = "#fff";
const img2 = document.createElement("img");
img2.src = icon;
img2.width = 15;
img2.height = 15;
header.appendChild(img1);
header.appendChild(title);
header.appendChild(img2);
function makeButton(text, onclick) {
const btn = document.createElement("button");
btn.textContent = text;
btn.onclick = onclick;
Object.assign(btn.style, {
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", () => {
alert("Open Explanation clicked");
});
// YouTube embed container, hidden by default
const ytContainer = document.createElement("div");
ytContainer.style.display = "none";
ytContainer.style.marginTop = "10px";
ytContainer.style.textAlign = "center";
const ytIframe = document.createElement("iframe");
ytIframe.width = "280";
ytIframe.height = "157"; // 16:9 aspect ratio for 280 width
ytIframe.src = "https://www.youtube.com/embed/MtYy5YMF6fk?autoplay=1";
ytIframe.title = "Self Embodiment of Perfection OST - Mahito Theme";
ytIframe.frameBorder = "0";
ytIframe.allow =
"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture";
ytIframe.allowFullscreen = true;
ytContainer.appendChild(ytIframe);
const btnEncouragement = makeButton("Encouragement", () => {
if (ytContainer.style.display === "none") {
ytContainer.style.display = "block";
} else {
ytContainer.style.display = "none";
// Stop the video by resetting the src
ytIframe.src = ytIframe.src;
}
});
menu.appendChild(header);
menu.appendChild(btn1);
menu.appendChild(btn2);
menu.appendChild(btnEncouragement);
menu.appendChild(ytContainer);
document.body.appendChild(menu);
// === DRAGGING ===
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) {
if (!isDragging) return;
menu.style.left = x - offsetX + "px";
menu.style.top = y - offsetY + "px";
}
function stopDrag() {
isDragging = false;
}
header.addEventListener("mousedown", (e) => {
startDrag(e.clientX, e.clientY);
e.preventDefault();
});
document.addEventListener("mousemove", (e) => {
doDrag(e.clientX, e.clientY);
});
document.addEventListener("mouseup", stopDrag);
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);
})();