فهرست منبع

拒绝样式污染:除了系统自带的工具,针对FH开发者自研的工具,也实行content-css的按需注入

[email protected] 2 سال پیش
والد
کامیت
9e2349ba8c
3فایلهای تغییر یافته به همراه12 افزوده شده و 4 حذف شده
  1. 10 3
      apps/background/background.js
  2. 2 1
      apps/devtools/hello-world/content-script.js
  3. BIN
      output/fehelper.zip

+ 10 - 3
apps/background/background.js

@@ -59,8 +59,15 @@ let BgPageInstance = (function () {
     };
     };
 
 
     // 像页面注入css脚本
     // 像页面注入css脚本
-    let _injectContentCss = function(tabId,toolName){
-        InjectTools.inject(tabId, {files: [`${toolName}/content-script.css`]});
+    let _injectContentCss = function(tabId,toolName,isDevTool){
+        if(isDevTool){
+            Awesome.getContentScript(toolName, true)
+                .then(css => {
+                    InjectTools.inject(tabId, { css })
+                });
+        }else{
+            InjectTools.inject(tabId, {files: [`${toolName}/content-script.css`]});
+        }
     };
     };
 
 
 
 
@@ -403,7 +410,7 @@ let BgPageInstance = (function () {
                         Monkey.start(request.params);
                         Monkey.start(request.params);
                         break;
                         break;
                     case 'inject-content-css':
                     case 'inject-content-css':
-                        _injectContentCss(sender.tab.id,request.tool);
+                        _injectContentCss(sender.tab.id,request.tool,!!request.devTool);
                         break;
                         break;
                 }
                 }
                 callback && callback(request.params);
                 callback && callback(request.params);

+ 2 - 1
apps/devtools/hello-world/content-script.js

@@ -10,10 +10,11 @@ window.helloworldContentScript = function () {
         chrome.runtime.sendMessage({
         chrome.runtime.sendMessage({
             type: 'fh-dynamic-any-thing',
             type: 'fh-dynamic-any-thing',
             thing:'inject-content-css',
             thing:'inject-content-css',
+            devTool: true,
             tool: 'hello-world'
             tool: 'hello-world'
         });
         });
     }
     }
-    
+
     console.log('你好,我是来自FeHelper的工具Demo:hello world!');
     console.log('你好,我是来自FeHelper的工具Demo:hello world!');
 };
 };
 
 

BIN
output/fehelper.zip