PageSourceSearch

https://pupwife.com/scripts/dependencies/perfModeToggle.js

js pupwife.com collected 2026-09-30 15:05:20 UTC 6,652 bytes, 219 lines download raw bytes

1/**
2 * Performance Mode Toggle Button
3 * Disables heavy visual effects: caustics, aurora, fish glow, and shadows
4 * Persists across all pages
5 */
6
7(function() {
8  function emitDevWarn() {
9    if (typeof window !== 'undefined' && typeof window.devWarn === 'function') {
10      window.devWarn.apply(window, arguments);
11    }
12  }
13
14  // Global flag for particle systems to check
15  window.PERFORMANCE_MODE_ENABLED = false;
16  
17  // Systems to control
18  const systems = {
19    caustics: null,
20    aurora: null,
21    glow: null,
22    shadows: null,
23    clickSparks: null,
24    navConfetti: null,
25    friendsConfetti: null,
26    bubbles: null,
27    seasonalOverlay: null,
28    cursorTrails: null
29  };
30  
31  let perfModeEnabled = false;
32  
33  function detectSystems() {
34    // Check for caustics (container div with canvas inside)
35    const causticsDiv = document.querySelector('#webgl-overlay');
36    if (causticsDiv) {
37      systems.caustics = causticsDiv;
38    }
39    
40    // Check for aurora (container div)
41    const auroraDiv = document.getElementById('aurora-overlay');
42    if (auroraDiv) {
43      systems.aurora = auroraDiv;
44    }
45    
46    // Check for glow (container div)
47    const glowDiv = document.getElementById('fish-glow-overlay');
48    if (glowDiv) {
49      systems.glow = glowDiv;
50    }
51    
52    // Check for shadows system
53    if (window.FishBuddyShadows) systems.shadows = window.FishBuddyShadows;
54    
55    // Check for particle systems (these will be controlled via flags)
56    // We'll set these to true if the scripts are loaded
57    if (typeof createClickBurst !== 'undefined' || document.querySelector('script[src*="clickSparks"]')) {
58      systems.clickSparks = true;
59    }
60    if (document.querySelector('script[src*="navConfetti"]')) {
61      systems.navConfetti = true;
62    }
63    if (document.querySelector('script[src*="friendsConfetti"]')) {
64      systems.friendsConfetti = true;
65    }
66    if (document.querySelector('script[src*="bubbles"]')) {
67      systems.bubbles = true;
68    }
69    if (window.seasonalOverlay) {
70      systems.seasonalOverlay = window.seasonalOverlay;
71    }
72    if (window.CursorTrails) {
73      systems.cursorTrails = window.CursorTrails;
74    }
75    
76    console.log('🎮 Detected systems:', {
77      caustics: !!systems.caustics,
78      aurora: !!systems.aurora,
79      glow: !!systems.glow,
80      shadows: !!systems.shadows,
81      clickSparks: !!systems.clickSparks,
82      navConfetti: !!systems.navConfetti,
83      friendsConfetti: !!systems.friendsConfetti,
84      bubbles: !!systems.bubbles,
85      seasonalOverlay: !!systems.seasonalOverlay,
86      cursorTrails: !!systems.cursorTrails
87    });
88    
89    // Log element info for debugging
90    if (systems.caustics) console.log('  Caustics div:', systems.caustics.id);
91    if (systems.aurora) console.log('  Aurora div:', systems.aurora.id);
92    if (systems.glow) console.log('  Glow div:', systems.glow.id);
93  }
94  
95  function applyPerformanceMode(enabled) {
96    perfModeEnabled = enabled;
97    window.PERFORMANCE_MODE_ENABLED = enabled;
98
99    // Caustics, aurora, and bubbles stay on — only optional effects respect perf mode
100    
101    // Control glow (canvas element)
102    if (systems.glow) {
103      systems.glow.style.display = enabled ? 'none' : '';
104      console.log(`   Glow: ${enabled ? 'OFF' : 'ON'}`);
105    }
106    
107    // Control shadows (JS system)
108    if (systems.shadows) {
109      if (enabled) {
110        systems.shadows.stop();
111        console.log(`   Shadows: OFF`);
112      } else {
113        // Restart shadow system
114        systems.shadows.start();
115        console.log(`   Shadows: ON`);
116      }
117    }
118    
119    // Particle systems are controlled via global flag check
120    if (systems.clickSparks) {
121      console.log(`   Click Sparks: ${enabled ? 'OFF' : 'ON'}`);
122    }
123    if (systems.navConfetti) {
124      console.log(`   Nav Confetti: ${enabled ? 'OFF' : 'ON'}`);
125    }
126    if (systems.friendsConfetti) {
127      console.log(`   Friends Confetti: ${enabled ? 'OFF' : 'ON'}`);
128    }
129    if (systems.bubbles) {
130      console.log(`   Bubbles: ${enabled ? 'OFF' : 'ON'}`);
131    }
132    
133    // Control seasonal overlay
134    if (systems.seasonalOverlay) {
135      if (enabled) {
136        systems.seasonalOverlay.destroy();
137        console.log(`   Seasonal Overlay: OFF`);
138      } else {
139        // Note: Can't easily restart it, user will need to refresh
140        console.log(`   Seasonal Overlay: refresh page to restart`);
141      }
142    }
143    
144    // Control cursor trails
145    if (systems.cursorTrails) {
146      if (enabled) {
147        systems.cursorTrails.setTrailType('none');
148        console.log(`   Cursor Trails: OFF`);
149      } else {
150        // Note: User's preference will be restored by settings
151        console.log(`   Cursor Trails: restored from settings`);
152      }
153    }
154    
155    console.log(`⚡ Performance mode ${enabled ? 'ENABLED' : 'DISABLED'}`);
156  }
157  
158  function updateButton(button) {
159    if (!button) return;
160    
161    if (perfModeEnabled) {
162      button.classList.add('enabled');
163      button.textContent = 'Performance Mode: ON ⚡';
164    } else {
165      button.classList.remove('enabled');
166      button.textContent = 'Performance Mode: OFF';
167    }
168  }
169  
170  function init() {
171    const button = document.getElementById('perfModeButton');
172    if (!button) {
173      emitDevWarn('Performance mode button not found');
174      return;
175    }
176    
177    // Detect available systems
178    detectSystems();
179    
180    // Load saved preference from localStorage
181    const savedPref = localStorage.getItem('globalPerfMode');
182    perfModeEnabled = savedPref === 'true';
183    
184    // Apply saved preference
185    if (perfModeEnabled) {
186      applyPerformanceMode(true);
187    }
188    
189    // Update button appearance
190    updateButton(button);
191    
192    // Handle button click
193    button.addEventListener('click', () => {
194      perfModeEnabled = !perfModeEnabled;
195      
196      // Apply to all systems
197      applyPerformanceMode(perfModeEnabled);
198      
199      // Update button appearance
200      updateButton(button);
201      
202      // Save preference
203      localStorage.setItem('globalPerfMode', perfModeEnabled.toString());
204    });
205    
206    console.log('✨ Performance mode toggle ready!');
207  }
208  
209  // Initialize when DOM is ready and systems are loaded
210  if (document.readyState === 'loading') {
211    document.addEventListener('DOMContentLoaded', () => {
212      // Wait for all systems to initialize
213      setTimeout(init, 200);
214    });
215  } else {
216    setTimeout(init, 200);
217  }
218})();
219

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.