-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage-debug.js
More file actions
313 lines (274 loc) · 10.4 KB
/
image-debug.js
File metadata and controls
313 lines (274 loc) · 10.4 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/**
* Debug and Diagnostic Script for Image Loading Issues
* Vietnamese Bird's Nest Landing Page
*/
document.addEventListener('DOMContentLoaded', function() {
console.log('🔍 Starting image diagnostic...');
// Check device information
logDeviceInfo();
// Monitor all images
monitorImages();
// Check for common issues
checkCommonIssues();
// Set up real-time monitoring
setupRealTimeMonitoring();
});
function logDeviceInfo() {
console.log('📱 Device Information:');
console.log('User Agent:', navigator.userAgent);
console.log('Screen Size:', window.screen.width + 'x' + window.screen.height);
console.log('Viewport Size:', window.innerWidth + 'x' + window.innerHeight);
console.log('Device Pixel Ratio:', window.devicePixelRatio);
console.log('Connection:', navigator.connection ? navigator.connection.effectiveType : 'Unknown');
// Check if iPhone SE
const isIPhoneSE = window.innerWidth === 375 && window.innerHeight === 667;
console.log('Is iPhone SE:', isIPhoneSE);
if (isIPhoneSE) {
console.log('🎯 iPhone SE detected - applying specific fixes...');
applyIPhoneSEFixes();
}
}
function monitorImages() {
const images = document.querySelectorAll('img');
console.log(`🖼️ Found ${images.length} images to monitor`);
images.forEach((img, index) => {
console.log(`Image ${index + 1}:`, {
src: img.src,
alt: img.alt,
className: img.className,
loaded: img.complete,
naturalWidth: img.naturalWidth,
naturalHeight: img.naturalHeight,
width: img.width,
height: img.height,
style: {
display: getComputedStyle(img).display,
visibility: getComputedStyle(img).visibility,
opacity: getComputedStyle(img).opacity,
zIndex: getComputedStyle(img).zIndex,
position: getComputedStyle(img).position,
transform: getComputedStyle(img).transform
}
});
// Monitor load events
img.addEventListener('load', function() {
console.log(`✅ Image ${index + 1} loaded successfully:`, this.src);
});
img.addEventListener('error', function() {
console.error(`❌ Image ${index + 1} failed to load:`, this.src);
console.log('Attempting to fix...');
fixBrokenImage(this, index + 1);
});
});
}
function checkCommonIssues() {
console.log('🔍 Checking for common issues...');
// Check for product images
const productImages = document.querySelectorAll('.product-image');
console.log(`Found ${productImages.length} product images`);
productImages.forEach((img, index) => {
const rect = img.getBoundingClientRect();
const isVisible = rect.width > 0 && rect.height > 0 &&
getComputedStyle(img).visibility !== 'hidden' &&
getComputedStyle(img).display !== 'none' &&
getComputedStyle(img).opacity !== '0';
console.log(`Product Image ${index + 1}:`, {
visible: isVisible,
boundingRect: rect,
computedStyle: {
display: getComputedStyle(img).display,
visibility: getComputedStyle(img).visibility,
opacity: getComputedStyle(img).opacity,
transform: getComputedStyle(img).transform,
zIndex: getComputedStyle(img).zIndex
}
});
if (!isVisible) {
console.warn(`⚠️ Product Image ${index + 1} is not visible! Attempting to fix...`);
forceImageVisibility(img, index + 1);
}
});
// Check hero visual container
const heroVisual = document.querySelector('.hero-visual');
if (heroVisual) {
const rect = heroVisual.getBoundingClientRect();
console.log('Hero Visual Container:', {
boundingRect: rect,
computedStyle: {
display: getComputedStyle(heroVisual).display,
visibility: getComputedStyle(heroVisual).visibility,
opacity: getComputedStyle(heroVisual).opacity,
overflow: getComputedStyle(heroVisual).overflow,
zIndex: getComputedStyle(heroVisual).zIndex
}
});
}
}
function forceImageVisibility(img, index) {
console.log(`🔧 Forcing visibility for image ${index}...`);
// Apply aggressive visibility fixes
img.style.cssText += `
display: block !important;
visibility: visible !important;
opacity: 1 !important;
position: relative !important;
z-index: 99999 !important;
transform: none !important;
width: auto !important;
height: auto !important;
max-width: 100% !important;
left: auto !important;
top: auto !important;
right: auto !important;
bottom: auto !important;
margin: 0 auto !important;
clip: auto !important;
clip-path: none !important;
mask: none !important;
-webkit-mask: none !important;
filter: none !important;
animation: none !important;
transition: opacity 0.3s ease !important;
`;
// Ensure parent containers don't interfere
let parent = img.parentElement;
while (parent && parent !== document.body) {
parent.style.cssText += `
overflow: visible !important;
position: relative !important;
z-index: auto !important;
transform: none !important;
clip: auto !important;
clip-path: none !important;
mask: none !important;
-webkit-mask: none !important;
`;
parent = parent.parentElement;
}
setTimeout(() => {
const rect = img.getBoundingClientRect();
const isNowVisible = rect.width > 0 && rect.height > 0;
console.log(`📊 Image ${index} visibility fix result:`, isNowVisible ? '✅ Success' : '❌ Still hidden');
}, 100);
}
function applyIPhoneSEFixes() {
console.log('🎯 Applying iPhone SE specific fixes...');
// Add iPhone SE class to body
document.body.classList.add('iphone-se-device');
// Force all critical images to be visible
const criticalSelectors = [
'.product-image',
'.hero-visual img',
'.about-image img',
'.image-placeholder'
];
criticalSelectors.forEach(selector => {
const elements = document.querySelectorAll(selector);
elements.forEach((el, index) => {
console.log(`Applying iPhone SE fix to ${selector} ${index + 1}`);
forceImageVisibility(el, index + 1);
});
});
// Apply container fixes
const heroContent = document.querySelector('.hero-content');
if (heroContent) {
heroContent.style.cssText += `
display: grid !important;
grid-template-columns: 1fr !important;
gap: 2rem !important;
align-items: center !important;
justify-items: center !important;
overflow: visible !important;
`;
}
}
function fixBrokenImage(img, index) {
console.log(`🔧 Attempting to fix broken image ${index}...`);
// Try reloading the image
const originalSrc = img.src;
img.src = '';
setTimeout(() => {
img.src = originalSrc;
console.log(`🔄 Reloaded image ${index}`);
}, 1000);
// Create fallback if still fails
setTimeout(() => {
if (!img.complete || img.naturalWidth === 0) {
console.log(`📝 Creating fallback for image ${index}`);
const fallback = document.createElement('div');
fallback.innerHTML = `
<div style="
width: 280px;
height: 280px;
background: linear-gradient(135deg, #f8f6f3 0%, #e8e6e3 100%);
border: 2px dashed #c89678;
display: flex;
align-items: center;
justify-content: center;
color: #c89678;
font-family: Arial, sans-serif;
font-size: 16px;
text-align: center;
border-radius: 12px;
margin: 0 auto;
">
🖼️<br>Product Image<br>Loading...
</div>
`;
img.parentNode.insertBefore(fallback, img);
img.style.display = 'none';
}
}, 3000);
}
function setupRealTimeMonitoring() {
// Monitor viewport changes
window.addEventListener('resize', function() {
console.log('📏 Viewport changed:', window.innerWidth + 'x' + window.innerHeight);
setTimeout(() => {
checkCommonIssues();
}, 500);
});
// Monitor orientation changes
window.addEventListener('orientationchange', function() {
console.log('🔄 Orientation changed');
setTimeout(() => {
logDeviceInfo();
checkCommonIssues();
}, 500);
});
// Periodic health check
setInterval(() => {
const productImages = document.querySelectorAll('.product-image');
let visibleCount = 0;
productImages.forEach(img => {
const rect = img.getBoundingClientRect();
if (rect.width > 0 && rect.height > 0 &&
getComputedStyle(img).visibility !== 'hidden' &&
getComputedStyle(img).opacity !== '0') {
visibleCount++;
}
});
if (productImages.length > 0 && visibleCount === 0) {
console.warn('⚠️ No product images are visible! Running emergency fix...');
productImages.forEach((img, index) => {
forceImageVisibility(img, index + 1);
});
}
}, 5000);
}
// Emergency fix function that can be called manually
window.emergencyImageFix = function() {
console.log('🚨 Running emergency image fix...');
const allImages = document.querySelectorAll('img');
allImages.forEach((img, index) => {
forceImageVisibility(img, index + 1);
});
};
// Export functions for console access
window.imageDebug = {
logDeviceInfo,
monitorImages,
checkCommonIssues,
forceImageVisibility,
applyIPhoneSEFixes
};