bep40 commited on
Commit
52db9b7
·
verified ·
1 Parent(s): 9e86800

Upload grob-img-fix.js

Browse files
Files changed (1) hide show
  1. grob-img-fix.js +76 -0
grob-img-fix.js ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * V.AI STUDIO — Grob Image Fix
3
+ * ==============================
4
+ * Fixes Grob product images: imgs[0] (grob_products_img/) are 404.
5
+ * Swaps the primary image (p.i) to imgs[1] and removes imgs[0].
6
+ * Applied to all Grob brand products with >= 2 gallery images.
7
+ */
8
+ (function() {
9
+ 'use strict';
10
+ if (window.__GROB_IMG_FIX__) return;
11
+ window.__GROB_IMG_FIX__ = true;
12
+
13
+ function fixGrobImages() {
14
+ if (typeof window.D === 'undefined' || !Array.isArray(window.D) || !window.D.length) return;
15
+
16
+ var fixed = 0;
17
+ var skipped = 0;
18
+
19
+ for (var i = 0; i < window.D.length; i++) {
20
+ var p = window.D[i];
21
+ if (!p) continue;
22
+
23
+ // Only process Grob brand products
24
+ if (p.brand !== 'Grob') continue;
25
+
26
+ var imgs = p.images || [];
27
+ if (imgs.length >= 2) {
28
+ // imgs[0] is broken (grob_products_img/ -> 404)
29
+ // imgs[1] works (malloca-website/grob_img/)
30
+
31
+ // Set primary image to imgs[1]
32
+ p.image = imgs[1];
33
+
34
+ // Remove imgs[0], keep rest as gallery
35
+ p.images = imgs.slice(1);
36
+
37
+ fixed++;
38
+ } else {
39
+ skipped++;
40
+ }
41
+ }
42
+
43
+ if (fixed > 0) {
44
+ console.log('[Grob Img Fix] Fixed ' + fixed + ' product(s) in D (swapped imgs[0]->broken with imgs[1]->ok). Skipped ' + skipped + ' (only 1 image).');
45
+
46
+ // Trigger UI refresh if available
47
+ if (typeof window.refreshUI === 'function') {
48
+ window.refreshUI();
49
+ }
50
+ }
51
+ }
52
+
53
+ // Patch after D is populated
54
+ function patchD() {
55
+ fixGrobImages();
56
+ }
57
+
58
+ // Try patching at various intervals as data loads
59
+ function onReady() {
60
+ setTimeout(patchD, 200);
61
+ setTimeout(patchD, 500);
62
+ setTimeout(patchD, 1000);
63
+ setTimeout(patchD, 2000);
64
+ setTimeout(patchD, 3000);
65
+ setTimeout(patchD, 5000);
66
+ setTimeout(patchD, 8000);
67
+ }
68
+
69
+ if (document.readyState === 'loading') {
70
+ document.addEventListener('DOMContentLoaded', onReady);
71
+ } else {
72
+ onReady();
73
+ }
74
+
75
+ console.log('[Grob Img Fix] Loaded: ready to fix 471 Grob product images (imgs[0] -> imgs[1])');
76
+ })();