Browse Source

Merge branch 'dev/v4.10.9_tsz' of qmx/jy into feature/v4.10.9

汤世哲 3 months ago
parent
commit
2c4fea7d61
1 changed files with 65 additions and 7 deletions
  1. 65 7
      src/web/staticres/common-module/public/head.js

+ 65 - 7
src/web/staticres/common-module/public/head.js

@@ -1,4 +1,62 @@
 ;(function() {
+  function loadJS (url, success, inject) {
+    var scripts = document.getElementsByTagName('script')
+    for (var i = 0; i < scripts.length; i++) {
+      if (scripts[i].src && scripts[i].src.indexOf(url) > -1) {
+        if (success) success();
+        return;
+      }
+    }
+    var domScript = document.createElement('script');
+    domScript.src = url;
+    typeof inject === 'function' ? inject(domScript) : null;
+    success = success || function () {};
+    domScript.onload = domScript.onreadystatechange = function () {
+      if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
+        success();
+        this.onload = this.onreadystatechange = null;
+        //this.parentNode.removeChild(this);
+      }
+    }
+    document.getElementsByTagName('head')[0].appendChild(domScript);
+  }
+  
+  function injectDevTools () {
+  
+    const devToolsAssets = [
+      'https://pagespy.jydev.jianyu360.com/page-spy/index.min.js',
+      'https://pagespy.jydev.jianyu360.com/plugin/data-harbor/index.min.js',
+      'https://pagespy.jydev.jianyu360.com/plugin/rrweb/index.min.js',
+    ]
+    const waitStates = [false, false, false]
+    function checkLoadState () {
+      const result = !waitStates.some(v => !v)
+      if (result) {
+        console.log('注入远程调试依赖成功')
+        window.$harbor = new DataHarborPlugin();
+        window.$rrweb = new RRWebPlugin();
+  
+        [window.$harbor, window.$rrweb].forEach(p => {
+          PageSpy.registerPlugin(p)
+        })
+  
+        window.$pageSpy = new PageSpy();
+      }
+    }
+    function loadToolsSuccess (i) {
+      waitStates[i] = true
+      checkLoadState()
+    }
+    for (let i = 0; i < devToolsAssets.length; i++) {
+      loadJS(devToolsAssets[i], () => {
+        loadToolsSuccess(i)
+      }, (scriptDom) => {
+        scriptDom.crossorigin = 'anonymous'
+      })
+    }
+  }
+  
+  injectDevTools();
   var host = location.host
   var hm = document.createElement("script");
   // 去除query后的location
@@ -113,12 +171,12 @@
 
   }
 
-  // if (document.cookie.indexOf('fid') === -1) {
-  //   try {
-  //     addMaticId()
-  //   } catch (e) {
-  //     console.log(e)
-  //   }
-  // }
+  if (document.cookie.indexOf('fid') === -1) {
+    try {
+      addMaticId()
+    } catch (e) {
+      console.log(e)
+    }
+  }
 
 })();