Blame view

泰额版/Food Labeling Management Code/Yi.Vben5.Vue3/docs/.vitepress/theme/plugins/hm.ts 719 Bytes
383e20a3   杨鑫   拉取
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
  import { inBrowser } from 'vitepress';
  
  const SITE_ID = '2e443a834727c065877c01d89921545e';
  
  declare global {
    interface Window {
      _hmt: any;
    }
  }
  
  function registerAnalytics() {
    window._hmt = window._hmt || [];
    const script = document.createElement('script');
    script.innerHTML = `var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?${SITE_ID}";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })()`;
    document.querySelector('head')?.append(script);
  }
  
  export function initHmPlugin() {
    if (inBrowser && import.meta.env.PROD) {
      registerAnalytics();
    }
  }