Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome 使用chrome扩展打开新选项卡,并使用jQuery插入css_Google Chrome_Google Chrome Extension - Fatal编程技术网

Google chrome 使用chrome扩展打开新选项卡,并使用jQuery插入css

Google chrome 使用chrome扩展打开新选项卡,并使用jQuery插入css,google-chrome,google-chrome-extension,Google Chrome,Google Chrome Extension,我使用一个带有弹出窗口的chrome扩展来插入一个网站并隐藏一些div 现在的问题是,我想用 url:并使用my contentscript.js注入样式 另一个问题是:有时应用程序会重新加载页面。在此之后,所有注射都会丢失。是否有可能在不点击popup.html按钮的情况下,将所有路径都注入 如果页面已打开,则以下代码可以正常工作 manifest.json { "name": "example stealth mode", "version": "1.1", "description": "

我使用一个带有弹出窗口的chrome扩展来插入一个网站并隐藏一些div

  • 现在的问题是,我想用 url:并使用my contentscript.js注入样式
  • 另一个问题是:有时应用程序会重新加载页面。在此之后,所有注射都会丢失。是否有可能在不点击popup.html按钮的情况下,将所有路径都注入 如果页面已打开,则以下代码可以正常工作

    manifest.json

    {
    "name": "example stealth mode",
    "version": "1.1",
    "description": "lorem ipsum",
      "browser_action": {
      "default_icon": "icon-on.png",
        "default_popup": "popup.html",
      "default_title": "example stealth mode"
    
    },
    "manifest_version": 2,
    "content_scripts": [
        {
          "matches": ["https://*.app.example.de/*"],
          "js": ["jquery-1.11.0.min.js", "background.js"]
        }
      ],
        "background": {
            "scripts": ["background.js"]
        },
        "permissions": [
            "tabs", "https://*.app.example.de/*"
        ]   
    }
    
    popup.js

    document.addEventListener('DOMContentLoaded', function () {
        document.getElementById('On').addEventListener('click', clickHandlerOn);
    })
    // An
    function clickHandlerOn(e) {
        chrome.extension.sendMessage({directive: "popup-click"}, function(response) {
            this.close(); // close the popup when the background finishes processing request
        });
    }
    
    chrome.extension.onMessage.addListener(
        function(request, sender, sendResponse) {
            switch (request.directive) {
            case "popup-click":
                // execute the content script
                chrome.tabs.executeScript(null, { // defaults to the current tab
    
                    file: "contentscript.js", // script to inject into page and run in sandbox
                    allFrames: true // This injects script into iframes in the page and doesn't work before 4.0.266.0.
                });
    
                sendResponse({}); // sending back empty response to sender
                break;
            default:
                // helps debug when request directive doesn't match
                alert("Unmatched request of '" + request + "' from script to background.js from " + sender);
            }
        }
    );
    
    background.js

    document.addEventListener('DOMContentLoaded', function () {
        document.getElementById('On').addEventListener('click', clickHandlerOn);
    })
    // An
    function clickHandlerOn(e) {
        chrome.extension.sendMessage({directive: "popup-click"}, function(response) {
            this.close(); // close the popup when the background finishes processing request
        });
    }
    
    chrome.extension.onMessage.addListener(
        function(request, sender, sendResponse) {
            switch (request.directive) {
            case "popup-click":
                // execute the content script
                chrome.tabs.executeScript(null, { // defaults to the current tab
    
                    file: "contentscript.js", // script to inject into page and run in sandbox
                    allFrames: true // This injects script into iframes in the page and doesn't work before 4.0.266.0.
                });
    
                sendResponse({}); // sending back empty response to sender
                break;
            default:
                // helps debug when request directive doesn't match
                alert("Unmatched request of '" + request + "' from script to background.js from " + sender);
            }
        }
    );
    
    contenscript

    $(document).ready(function() {
        $('div#hlXXXContent').hide();
        $('#hlYYY').hide();
        $('#hlZZZ').hide();
        $('h3.hlVVV').append(' Stealth Mode');
    });
    
    popup.html

    <li><button class="hl123" id="On"><span class="hlSubmenuSelected">Stealthmode on</span</button></li>
    

    上的隐身模式文件名contentscript.js很奇怪,因为您使用的不是内容脚本。为什么不尝试在每个目标页面加载上加载一些东西,这将是您的代码决定是否对页面执行更多操作的机会