PageSourceSearch

https://www.atncorp.com/js/5.4.36/weildAI.js

js atncorp.com collected 2026-09-24 09:30:05 UTC 16,612 bytes, 433 lines download raw bytes

1/**
2 * Unified chat widget loader for WieldAI and Drift
3 *
4 * Logic:
5 * 1. If WieldAI should be loaded (Thor LTV, Thor 4, Customer Support pages, Manual pages, or X-Sound pages) -> Load WieldAI, skip Drift
6 * 2. If WieldAI is NOT loaded -> Load Drift
7 *
8 * WieldAI enabled pages:
9 * - Product pages: Thor LTV, Thor 4
10 * - Support pages: orderstatus, rma, faq, channel, how-to-videos, user, firmware, productreturninformation (with expert=support parameter)
11 * - Manual pages: /manuals (with expert=manual parameter)
12 * - Special: X-Sound (with expert=manual)
13 *
14 * This ensures only one chat widget is active at a time.
15 */
16(function () {
17  // Helper function to get query parameters
18  const getQueryParameter = (name) =>
19    new URLSearchParams(window.location.search).get(name);
20
21  const currentDomain = window.location.hostname;
22  const currentPath = window.location.pathname;
23  const isWWW = currentDomain === 'www.atncorp.com';
24
25  // Enable WieldAI for product pages
26  const isProductPage = [
27    '/thermal-scope-thor-ltv',
28    '/thermal-scope-thor-4'
29  ].some((path) => currentPath.includes(path));
30
31  // Enable WieldAI for customer support pages
32  const isSupportPage = [
33    // '/orderstatus', // ORDER/RETURN STATUS - handled separately
34    '/rma', // SERVICE AND REPAIR CENTER
35    '/faq', // FAQ
36    '/channel', // VIDEOS
37    '/how-to-videos', // HOW TO VIDEOS
38    '/user', // REGISTER PRODUCT
39    '/firmware', // FIRMWARE DOWNLOAD
40    '/productreturninformation', // RETURNS/CONTACT US
41    // '/contactus' // CONTACT US
42  ].some((path) => currentPath.includes(path));
43
44  // Enable WieldAI for manual pages with expert=manual parameter
45  const isManualPage = currentPath.includes('/manuals');
46
47  // Determine the environment first
48  const wieldEnv = isWWW ? 'staging' : getQueryParameter('wieldEnv');
49
50  // On www.atncorp.com we disable old WieldAI fallback for support/manual pages
51  // to use only the new customer support widget via specialPages.
52  const isWieldAIEnabledPage =
53    isProductPage || ((isSupportPage || isManualPage) && !isWWW);
54  // const isWieldAIEnabledPage =
55  //   isProductPage || (isSupportPage && wieldEnv !== 'staging') || isManualPage;
56
57  // Script URLs - declared early for use in specialPages
58  const atncorpScript = 'https://stage.cdn.wield-ai.com/wolf-ai-widget.umd.js';
59  const goblinScript = 'https://s3.eu-north-1.amazonaws.com/wolfai.stage/libs/wolf-ai-widget.es.js'
60  // Customer support widget URL for www.atncorp.com
61  const agentBrainsCustomerSupportUrl =
62    'https://cdn.agent-brains.com/legacy-chat-widget.umd.js?expertApiKey=6c296f5ed7698a4e755e696c978762b34d25d9ab6c51077f965d15ef615cd35d';
63  // Sales AI widget URL for Thor products on www.atncorp.com
64  const agentBrainsSalesUrl =
65    'https://cdn.agent-brains.com/legacy-chat-widget.umd.js?expertApiKey=a10bd6e34e3de9e497465f065d00be528d07ece091367e612301fc8f73deac90';
66
67  const agentBrainsMarketingWriterUrl =
68    'https://cdn.agent-brains.com/legacy-chat-widget.umd.js?expertApiKey=911db4a3d82b1512f3ab724761a4c56081d525f287f563e0ac802d36a976275b';
69  const agentBrainsAmazonWriterUrl =    
70    'https://cdn.agent-brains.com/legacy-chat-widget.umd.js?expertApiKey=0ac6efb3f990c74afc4e113b13662298cf94cc0f3eeb6b124fb5e8e36f4a8d5f';
71  // Special pages with custom configurations
72  const specialPages = [
73    {
74      name: 'xsound',
75      condition: () =>
76        ['goblin.od.atncorp.com', 'localhost'].includes(currentDomain) &&
77        currentPath === '/x-sound-shooting-ear-muffs',
78      getUrl: () =>
79        'https://s3.eu-north-1.amazonaws.com/wolfai.stage/libs/wolf-ai-widget.es.js?expert=manual&deviceId=xsound&timeout=0'
80    },
81    // Specific Thor LTV 256 2-6x page with Sales AI (goblin)
82    {
83      name: 'thor-ltv-256-2-6x',
84      condition: () =>
85        ['goblin.od.atncorp.com', 'localhost'].includes(currentDomain) &&
86        currentPath === '/thermal-scope-thor-ltv-256-2-6x',
87      getUrl: () =>
88        'https://cdn.dwm-sndbx-ai.com/legacy-chat-widget.umd.js?expertApiKey=840a3c5cabb441cc706c1b48d5d55a06e0980d85b89fd7ffa97a1adb9b3dc9dd'
89    },
90    // General Thor product pages (match any path containing these substrings)
91    {
92      name: 'thor-ltv-general',
93      condition: () => currentPath.includes('thermal-scope-thor-ltv'),
94      getUrl: () => (isWWW ? agentBrainsSalesUrl : 'https://cdn.dwm-sndbx-ai.com/legacy-chat-widget.umd.js?expertApiKey=45ca498a1a8ab97b6419fb47c0091870050bc9d1d568b499f0bbc01db0d66f62')
95    },
96    {
97      name: 'thor-4-general',
98      condition: () => currentPath.includes('thermal-scope-thor-4'),
99      getUrl: () => (isWWW ? agentBrainsSalesUrl : 'https://cdn.dwm-sndbx-ai.com/legacy-chat-widget.umd.js?expertApiKey=45ca498a1a8ab97b6419fb47c0091870050bc9d1d568b499f0bbc01db0d66f62')
100    },
101    {
102      name: 'orderstatus-goblin',
103      condition: () =>
104        ['goblin.od.atncorp.com', 'localhost'].includes(currentDomain) &&
105        currentPath === '/orderstatus',
106      getUrl: () =>
107        'https://cdn.dwm-sndbx-ai.com/legacy-chat-widget.umd.js?expertApiKey=379d95ffe55bb8174ae240cd10d4bd543340511105685449a282d01572a4f3a5'
108    },
109    {
110      name: 'orderstatus-goblin',
111      condition: () =>
112        ['goblin.od.atncorp.com', 'localhost'].includes(currentDomain) &&
113        currentPath === '/orderstatus',
114      getUrl: () =>
115        'https://cdn.dwm-sndbx-ai.com/legacy-chat-widget.umd.js?expertApiKey=379d95ffe55bb8174ae240cd10d4bd543340511105685449a282d01572a4f3a5'
116    },
117    {
118      name: 'support-chat-goblin',
119      condition: () =>
120        ['goblin.od.atncorp.com', 'localhost'].includes(currentDomain) && currentPath === '/support-chat',
121      getUrl: () =>  'https://cdn.dwm-sndbx-ai.com/legacy-chat-widget.umd.js?expertApiKey=379d95ffe55bb8174ae240cd10d4bd543340511105685449a282d01572a4f3a5'
122    },
123    {
124      name: 'rma-goblin',
125      condition: () =>
126        ['goblin.od.atncorp.com', 'localhost'].includes(currentDomain) &&
127        currentPath === '/rma',
128      getUrl: () =>
129        'https://cdn.dwm-sndbx-ai.com/legacy-chat-widget.umd.js?expertApiKey=8f9b4d7c37027aa170d1cc130ccab3bfe080ffa346ccf06ac453dd197dbec3c8'
130    },
131    {
132      name: 'chat-for-market-goblin',
133      condition: () =>
134        ['goblin.od.atncorp.com', 'localhost'].includes(currentDomain) && currentPath === '/chat-for-market',
135      getUrl: () => 'https://cdn.agent-brains.com/legacy-chat-widget.umd.js?expertApiKey=a0f77cbe39311d07b173edb716668a967427893b6ac4c9b2a272e9e94c63379e'
136    },
137    {
138      name: 'marketing-article-writter-goblin',
139      condition: () =>
140        ['goblin.od.atncorp.com', 'localhost'].includes(currentDomain) && currentPath === '/marketing-article-writter',
141      getUrl: () => 'https://cdn.agent-brains.com/legacy-chat-widget.umd.js?expertApiKey=911db4a3d82b1512f3ab724761a4c56081d525f287f563e0ac802d36a976275b'
142    },
143    {
144      name: 'amazonwriter-goblin',
145      condition: () =>
146        ['goblin.od.atncorp.com', 'localhost'].includes(currentDomain) && currentPath === '/amazonwriter',
147      getUrl: () => 'https://cdn.agent-brains.com/legacy-chat-widget.umd.js?expertApiKey=0ac6efb3f990c74afc4e113b13662298cf94cc0f3eeb6b124fb5e8e36f4a8d5f'
148    },
149    {
150      name: 'scope-lens-tissue-goblin',
151      condition: () =>
152        ['goblin.od.atncorp.com', 'localhost'].includes(currentDomain) &&
153        currentPath === '/scope-lens-tissue',
154      getUrl: () =>
155        'https://cdn.dwm-sndbx-ai.com/legacy-chat-widget.umd.js?expertApiKey=325d8462b2422b221cb6956230b74415d66d87feb7bebc6db004f6520ae2fd5c'
156    },
157    // Customer support for goblin.od.atncorp.com
158    {
159      name: 'orderstatus-goblin',
160      condition: () =>
161        ['goblin.od.atncorp.com', 'localhost'].includes(currentDomain) &&
162        currentPath === '/orderstatus',
163      getUrl: () =>
164        'https://cdn.dwm-sndbx-ai.com/legacy-chat-widget.umd.js?expertApiKey=379d95ffe55bb8174ae240cd10d4bd543340511105685449a282d01572a4f3a5'
165    },
166    // General helper for goblin.od.atncorp.com
167    {
168      name: 'contactus-goblin',
169      condition: () =>
170        ['goblin.od.atncorp.com', 'localhost'].includes(currentDomain) &&
171        currentPath === '/contactus',
172      getUrl: () =>
173        'https://cdn.dwm-sndbx-ai.com/legacy-chat-widget.umd.js?expertApiKey=67be14ef32517312c7383583900b579b7ac6f57e3a4b9ee9468263890c0af394'
174    },
175    // New customer support for www.atncorp.com pages
176    {
177      name: 'support-chat',
178      condition: () => isWWW && currentPath === '/support-chat',
179      getUrl: () => agentBrainsCustomerSupportUrl
180    },
181    {
182      name: 'orderstatus',
183      condition: () => isWWW && currentPath === '/orderstatus',
184      getUrl: () => agentBrainsCustomerSupportUrl
185    },
186    {
187      name: 'faq',
188      condition: () => isWWW && currentPath === '/faq',
189      getUrl: () => agentBrainsCustomerSupportUrl
190    },
191    {
192      name: 'how-to-videos',
193      condition: () => isWWW && currentPath === '/how-to-videos',
194      getUrl: () => agentBrainsCustomerSupportUrl
195    },
196    {
197      name: 'firmware',
198      condition: () => isWWW && currentPath === '/firmware',
199      getUrl: () => agentBrainsCustomerSupportUrl
200    },
201    {
202      name: 'contactus',
203      condition: () => isWWW && currentPath === '/contactus',
204      getUrl: () => agentBrainsCustomerSupportUrl
205    },
206    // Additional www.atncorp.com pages using the new customer support widget
207    {
208      name: 'rma',
209      condition: () => isWWW && currentPath === '/rma',
210      getUrl: () => 'https://cdn.agent-brains.com/legacy-chat-widget.umd.js?expertApiKey=6c296f5ed7698a4e755e696c978762b34d25d9ab6c51077f965d15ef615cd35d'
211    },
212    {
213      name: 'channel',
214      condition: () => isWWW && currentPath === '/channel',
215      getUrl: () => agentBrainsCustomerSupportUrl
216    },
217    {
218      name: 'manuals',
219      condition: () => isWWW && currentPath.startsWith('/manuals'),
220      getUrl: () => agentBrainsCustomerSupportUrl
221    },
222    {
223      name: 'user',
224      condition: () => isWWW && currentPath === '/user',
225      getUrl: () => agentBrainsCustomerSupportUrl
226    },
227    {
228      name: 'productreturninformation',
229      condition: () => isWWW && currentPath === '/productreturninformation',
230      getUrl: () => agentBrainsCustomerSupportUrl
231    },
232    {
233      name: 'ballistic-calculator',
234      condition: () => isWWW && currentPath === '/ballistic-calculator',
235      getUrl: () => agentBrainsCustomerSupportUrl
236    },
237    {
238      name: 'blog',
239      condition: () => isWWW && currentPath.startsWith('/blog'),
240      getUrl: () => agentBrainsCustomerSupportUrl
241    },
242    {
243      name: 'marketing-article-writter',
244      condition: () => isWWW && currentPath.startsWith('/marketing-article-writter'),
245      getUrl: () => agentBrainsMarketingWriterUrl
246    },
247    {
248      name: 'amazonwriter',
249      condition: () => isWWW && currentPath.startsWith('/amazonwriter'),
250      getUrl: () => agentBrainsAmazonWriterUrl
251    },
252    
253  ];
254
255  // Find current special page if any
256  const currentSpecialPage = specialPages.find(page => page.condition());
257  
258  // Check if WieldAI should be loaded
259  const shouldLoadWieldAI = isWieldAIEnabledPage || currentSpecialPage;
260
261  // Function to determine the correct AI script URL
262  const getAiUrl = () => {
263    // Check if current page is a special page
264    if (currentSpecialPage) {
265      return currentSpecialPage.getUrl();
266    }
267
268    // For manual pages, add expert=manual parameter and deviceId if available
269    if (isManualPage) {
270      const deviceId = window.manualDeviceId;
271      const manualParams = deviceId
272        ? `?expert=manual&deviceId=${deviceId}&timeout=0`
273        : '?expert=manual';
274
275      return wieldEnv === 'staging'
276        ? `${atncorpScript}${manualParams}`
277        : `${goblinScript}${manualParams}`;
278    }
279
280    // For support pages, add expert=support parameter
281    if (isSupportPage) {
282      const supportParams = '?expert=support';
283
284      return wieldEnv === 'staging'
285        ? `${atncorpScript}${supportParams}`
286        : `${goblinScript}${supportParams}`;
287
288      // return `https://s3.eu-north-1.amazonaws.com/wolfai.stage/libs/wolf-ai-widget.es.js${supportParams}`;
289    }
290
291    return wieldEnv === 'staging' ? atncorpScript : goblinScript;
292  };
293
294  // Function to load WieldAI script
295  const loadWieldAI = () => {
296    const aiUrl = getAiUrl();
297    // add autoopen param to orl
298    const autoOpenParam = '&autoOpen=true';
299    const script = document.createElement('script');
300    script.src = aiUrl + autoOpenParam;
301    script.async = true;
302    document.body.appendChild(script);
303
304    console.log('WieldAI loaded, actualUrl:', script.src);
305
306    // Handle AI chat events
307    const handleEvents = (event) => {
308      switch (event.data.type) {
309        case 'addProductsToCart':
310          document.dispatchEvent(
311            new CustomEvent('wolfAiProducts', {
312              detail: { products: event.data.products }
313            })
314          );
315          break;
316        case 'addDiscount':
317          document.dispatchEvent(
318            new CustomEvent('wolfAiDiscount', {
319              detail: { discount: event.data.discounts }
320            })
321          );
322          break;
323        case 'checkout':
324          document.dispatchEvent(
325            new CustomEvent('wolfAiCheckout', { detail: { items: event.data } })
326          );
327          break;
328        case 'deleteProductsFromCart':
329          document.dispatchEvent(
330            new CustomEvent('wolfAiRemoveProducts', {
331              detail: { products: event.data.products }
332            })
333          );
334          break;
335      }
336    };
337
338    window.addEventListener('message', handleEvents);
339  };
340
341  // Inject AI script if the page is eligible
342  if (shouldLoadWieldAI) {
343    // For manual pages, check if we need to wait for deviceId
344    if (isManualPage && !window.manualDeviceId) {
345      // Listen for the custom event when deviceId becomes available
346      const handleDeviceIdReady = () => {
347        loadWieldAI();
348        document.removeEventListener(
349          'manualDeviceIdReady',
350          handleDeviceIdReady
351        );
352      };
353
354      document.addEventListener('manualDeviceIdReady', handleDeviceIdReady);
355
356      // Fallback: check window.manualDeviceId one more time after DOM is ready
357      // If still no deviceId, load WieldAI without it
358      document.addEventListener('DOMContentLoaded', () => {
359        // Final check for window.manualDeviceId before loading without it
360        if (!window.manualDeviceId) {
361          console.log(
362            'Loading WieldAI without deviceId (not found after DOM ready)'
363          );
364          loadWieldAI();
365          document.removeEventListener(
366            'manualDeviceIdReady',
367            handleDeviceIdReady
368          );
369        }
370      });
371    } else {
372      // Load immediately for other pages or if deviceId is already available
373      loadWieldAI();
374    }
375  } else {
376    // If WieldAI is not loaded, load Drift on all other pages
377    if (true) {
378      // Load Drift chat
379      !(function () {
380        var t = (window.driftt = window.drift = window.driftt || []);
381        if (!t.init) {
382          if (t.invoked)
383            return void (
384              window.console &&
385              console.error &&
386              console.error('Drift snippet included twice.')
387            );
388          (t.invoked = !0),
389            (t.methods = [
390              'identify',
391              'config',
392              'track',
393              'reset',
394              'debug',
395              'show',
396              'ping',
397              'page',
398              'hide',
399              'off',
400              'on'
401            ]),
402            (t.factory = function (e) {
403              return function () {
404                var n = Array.prototype.slice.call(arguments);
405                return n.unshift(e), t.push(n), t;
406              };
407            }),
408            t.methods.forEach(function (e) {
409              t[e] = t.factory(e);
410            }),
411            (t.load = function (t) {
412              var e = 3e5,
413                n = Math.ceil(new Date() / e) * e,
414                o = document.createElement('script');
415              (o.type = 'text/javascript'),
416                (o.async = !0),
417                (o.crossorigin = 'anonymous'),
418                (o.src =
419                  'https://js.driftt.com/include/' + n + '/' + t + '.js');
420              var i = document.getElementsByTagName('script')[0];
421              i.parentNode.insertBefore(o, i);
422            });
423        }
424      })();
425      drift.SNIPPET_VERSION = '0.3.1';
426      drift.load('8kfx4vdywpbv');
427
428      console.log('Drift loaded (WieldAI not available on this page)');
429    } else {
430      console.log('Neither WieldAI nor Drift loaded - excluded page');
431    }
432  }
433})();

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.