This repository was archived by the owner on Apr 20, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
85 lines (69 loc) 路 2.93 KB
/
Copy pathscript.js
File metadata and controls
85 lines (69 loc) 路 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"use strict";
document.addEventListener("DOMContentLoaded", () => {
const btnNo = document.getElementById("btn-no");
const btnYes = document.getElementById("btn-yes");
const popupGay = document.getElementById("popup-gay");
const popupStraight = document.getElementById("popup-straight");
const closeBtns = document.querySelectorAll(".close-btn");
let audioGay = new Audio("assets/audio/gay-meme.mp3");
let audioStraight = new Audio("assets/audio/straight.MP3");
// Disable right-click for the "prank" feel
document.addEventListener("contextmenu", (e) => e.preventDefault());
/**
* Moves the "No" button to a random position within the viewport
*/
const moveButton = () => {
// Break out of the parent card to avoid clipping (backdrop-filter issue)
if (btnNo.parentElement !== document.body) {
document.body.appendChild(btnNo);
}
const padding = 20;
const btnWidth = btnNo.offsetWidth;
const btnHeight = btnNo.offsetHeight;
// Use window.innerWidth/Height for the most reliable viewport bounds
const vw = window.innerWidth;
const vh = window.innerHeight;
// Calculate maximum safe bounds
const maxX = vw - btnWidth - padding;
const maxY = vh - btnHeight - padding;
// Ensure we don't pick a position that's off-screen
const randomX = Math.floor(Math.random() * (Math.max(padding, maxX) - padding + 1)) + padding;
const randomY = Math.floor(Math.random() * (Math.max(padding, maxY) - padding + 1)) + padding;
btnNo.style.position = "fixed";
btnNo.style.left = `${randomX}px`;
btnNo.style.top = `${randomY}px`;
btnNo.style.margin = "0";
};
/**
* Shows a popup and plays associated audio
* @param {HTMLElement} popup
* @param {HTMLAudioElement} audio
*/
const showPopup = (popup, audio) => {
popup.classList.add("active");
audio.currentTime = 0;
audio.play().catch(err => console.log("Audio play failed:", err));
};
/**
* Closes all popups and stops all audio
*/
const closePopups = () => {
document.querySelectorAll(".popup").forEach(p => p.classList.remove("active"));
audioGay.pause();
audioStraight.pause();
};
// Event Listeners
btnNo.addEventListener("mouseover", moveButton);
btnNo.addEventListener("touchstart", (e) => {
e.preventDefault();
moveButton();
});
btnYes.addEventListener("click", () => showPopup(popupGay, audioGay));
// Fallback if they actually manage to click "No" (e.g. via keyboard)
btnNo.addEventListener("click", () => showPopup(popupStraight, audioStraight));
closeBtns.forEach(btn => btn.addEventListener("click", closePopups));
// Close on background click
window.addEventListener("click", (e) => {
if (e.target.classList.contains("popup")) closePopups();
});
});