|
7 | 7 | <body>
|
8 | 8 |
|
9 | 9 |
|
10 |
| - <script> |
11 |
| - (function() { |
12 |
| - // Helper to check if we're on checkout/thank you pages |
13 |
| - const isCheckoutPage = window.location.pathname.includes('/checkout'); |
14 |
| - const isThankYouPage = window.location.pathname.includes('/thank_you'); |
15 |
| - |
16 |
| - // Don't load on regular checkout pages |
17 |
| - if (isCheckoutPage && !isThankYouPage) { |
18 |
| - return; |
19 |
| - } |
20 |
| - |
21 |
| - // Function to initialize the widget |
22 |
| - const initializeWidget = () => { |
23 |
| - // Add CSS first |
24 |
| - const link = document.createElement('link'); |
25 |
| - link.rel = 'stylesheet'; |
26 |
| - link.href = 'https://feedbackstack.test/js/core/style.css'; |
27 |
| - document.head.appendChild(link); |
| 10 | + <script> |
| 11 | +(() => { |
| 12 | + // Load CSS |
| 13 | + document.head.insertAdjacentHTML('beforeend', |
| 14 | + '<link rel="stylesheet" href="https://feedbackstack.test/js/core/style.css">'); |
28 | 15 |
|
29 |
| - // Then load JS |
| 16 | + // Load and initialize widget |
30 | 17 | const script = document.createElement('script');
|
31 | 18 | script.src = `https://feedbackstack.test/js/core/script.js?token=b19bf05984da4b073b378ba2dc3ec0b5e941ea42e0bdaf52cebe7a9051396fd2&shop=${window.location.host}`;
|
32 |
| - script.onload = function() { |
33 |
| - if (typeof FeedbackWidget === 'function') { |
34 |
| - FeedbackWidget(); |
35 |
| - } |
36 |
| - }; |
| 19 | + script.onload = () => window.FeedbackWidget?.(); |
37 | 20 | document.body.appendChild(script);
|
38 |
| - }; |
39 |
| - |
40 |
| - // If on thank you page, wait for Shopify's checkout to be ready |
41 |
| - if (isThankYouPage) { |
42 |
| - // Wait for Shopify's checkout object to be fully initialized |
43 |
| - const waitForCheckout = setInterval(() => { |
44 |
| - if (window.Shopify && window.Shopify.checkout) { |
45 |
| - clearInterval(waitForCheckout); |
46 |
| - setTimeout(initializeWidget, 1000); // Add a small delay after checkout is ready |
47 |
| - } |
48 |
| - }, 100); |
49 |
| - } else { |
50 |
| - // Regular page, initialize normally |
51 |
| - initializeWidget(); |
52 |
| - } |
53 | 21 | })();
|
54 | 22 | </script>
|
55 | 23 | </body>
|
|
0 commit comments