-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
195 lines (162 loc) · 7.58 KB
/
script.js
File metadata and controls
195 lines (162 loc) · 7.58 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
document.addEventListener('DOMContentLoaded', () => {
// Edge Tooltip (handles both Radioactive warning and Cookie message)
const edgeTooltip = document.getElementById('edgeTooltip');
// Messages
const radioactiveText = '☢️ WARNING: radioactive! ☢️ <br> keeping this website open <br> might fry your device!';
const cookieText = '<div style="display: flex; align-items: center; text-align: right;"><div>me no spy with cookies...<br>me eat them!</div><img src="cookie3-gold-128.png" alt="Cookie" class="cookie-img"></div>';
// Detect touch devices
const isTouchDevice = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0);
function updateMouseDrivenVisibility(clientX, clientY) {
const viewportWidth = window.innerWidth || document.documentElement.clientWidth;
const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
// Thresholds
const sideThreshold = 25;
const bottomThreshold = 50;
// Detection
const isNearLeft = clientX < sideThreshold;
const isNearRight = clientX > viewportWidth - sideThreshold;
const isNearBottom = clientY > viewportHeight - bottomThreshold;
if (edgeTooltip) {
if (isNearBottom) {
// Bottom Mode: Cookie Message
edgeTooltip.innerHTML = cookieText;
edgeTooltip.style.display = 'block';
// Position: Fixed at bottom center
edgeTooltip.style.top = 'auto';
edgeTooltip.style.bottom = '20px';
edgeTooltip.style.left = '50%';
edgeTooltip.style.right = 'auto';
edgeTooltip.style.transform = 'translateX(-50%)'; // Center it
} else if (isNearLeft || isNearRight) {
// Side Mode: Radioactive Warning
edgeTooltip.innerHTML = radioactiveText;
edgeTooltip.style.display = 'block';
edgeTooltip.style.bottom = 'auto';
edgeTooltip.style.top = `${clientY + 10}px`;
edgeTooltip.style.transform = 'none'; // Remove centering transform
if (isNearLeft) {
edgeTooltip.style.left = `${clientX + 15}px`;
edgeTooltip.style.right = 'auto';
} else {
edgeTooltip.style.left = 'auto';
edgeTooltip.style.right = `${viewportWidth - clientX + 15}px`;
}
} else {
edgeTooltip.style.display = 'none';
}
}
}
// Track mouse movement
window.addEventListener('mousemove', (e) => {
if (!isTouchDevice) {
updateMouseDrivenVisibility(e.clientX, e.clientY);
}
});
// For touch devices, handle scroll-based visibility
if (isTouchDevice) {
let cookieBannerTimeout;
let isBannerVisible = false;
let hasFadedOut = false;
window.addEventListener('scroll', () => {
const scrollPosition = window.scrollY + window.innerHeight;
const documentHeight = document.documentElement.scrollHeight;
const scrollThreshold = 50; // Show when within 50px of bottom
const isAtBottom = scrollPosition >= documentHeight - scrollThreshold;
if (isAtBottom) {
// Only show if not already visible and hasn't just faded out
if (!isBannerVisible && !hasFadedOut) {
if (edgeTooltip) {
edgeTooltip.innerHTML = cookieText;
edgeTooltip.style.display = 'block';
edgeTooltip.style.top = 'auto';
edgeTooltip.style.bottom = '20px';
edgeTooltip.style.left = '50%';
edgeTooltip.style.right = 'auto';
edgeTooltip.style.transform = 'translateX(-50%)';
}
isBannerVisible = true;
// Set timeout to hide after 5 seconds
cookieBannerTimeout = setTimeout(() => {
if (edgeTooltip) {
edgeTooltip.style.display = 'none';
}
isBannerVisible = false;
hasFadedOut = true; // Prevent showing again until user leaves bottom
}, 5000);
}
} else {
// User left the bottom area
if (edgeTooltip) {
edgeTooltip.style.display = 'none';
}
// Reset state so it can show again next time they scroll down
isBannerVisible = false;
hasFadedOut = false;
if (cookieBannerTimeout) {
clearTimeout(cookieBannerTimeout);
}
}
});
}
});
// Existing Background Text Logic (remains outside DOMContentLoaded as it handles its own init)
class TextPosition {
constructor(x, y, width, height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
// Check if this position overlaps with another
overlaps(other) {
// Add padding around boxes for better spacing
const padding = 50;
return !(this.x + this.width + padding < other.x ||
this.x > other.x + other.width + padding ||
this.y + this.height + padding < other.y ||
this.y > other.y + other.height + padding);
}
}
function createBackgroundTexts() {
const container = document.getElementById('backgroundTextContainer');
if (!container) return;
container.innerHTML = ''; // Clear existing texts
const viewportWidth = window.innerWidth;
const viewportHeight = window.innerHeight;
const textWidth = 300; // Width of text element
const textHeight = 50; // Height of text element
// Generate random rotation between -45 and 45 degrees
const rotation = Math.random() * 90 - 45;
const positions = [];
let attempts = 0;
const maxAttempts = 100; // Prevent infinite loops
const numBackgroundText = 7
// Create text elements
while (positions.length < numBackgroundText && attempts < maxAttempts) {
const randomX = Math.random() * (viewportWidth - textWidth);
const randomY = Math.random() * (viewportHeight - textHeight);
const newPosition = new TextPosition(randomX, randomY, textWidth, textHeight);
// Check if this position overlaps with any existing positions
let overlaps = false;
for (const position of positions) {
if (newPosition.overlaps(position)) {
overlaps = true;
break;
}
}
if (!overlaps) {
positions.push(newPosition);
const textElement = document.createElement('div');
textElement.className = 'background-text';
textElement.textContent = '🚀6.67% yield!🚀';
textElement.style.left = `${randomX}px`;
textElement.style.top = `${randomY}px`;
textElement.style.transform = `rotate(${rotation}deg)`;
container.appendChild(textElement);
}
attempts++;
}
}
// Initial creation (wait for load to ensure styles/dimensions are ready)
window.addEventListener('load', createBackgroundTexts);
window.addEventListener('resize', createBackgroundTexts);