chrome.tabs.executeScript | insertCss可以一次性运行

时间:2018-07-01 13:30:58

标签: javascript google-chrome-extension styles

我将样式和脚本添加到后台的某个站点。

chrome.tabs.onUpdated.addListener (function (tabId, changeInfo, tab) {
        console.log (tabId, changeInfo, tab);
        if (changeInfo.status === 'complete' && siteUrl.test (tab.url)) {
            insertCss (tab.id, '/css/bootstrap.min.css', function () {
                insertCss (tab.id, '/css/jquery.toast.min.css', function () {
                    insertCss (tab.id, '/css/content_style.css', function () {
                        executeScript (tab.id, '/js/utils/jquery-3.3.1.js', function () {
                            executeScript (tab.id, '/js/utils/js.cookie.js', function () {
                                executeScript (tab.id, '/js/utils/jquery.toast.min.js', function () {
                                    executeScript (tab.id, '/js/utils/sweetalert2.js', function () {
                                        executeScript (tab.id, '/js/core.js', function () {
                                            executeScript (tab.id, '/js/content_script.js', function () {
                                                console.warn ('FILES INJECTION COMPLETE');
                                            });
                                        });
                                    });
                                });
                            });
                        });
                    });
                });
            });
        }
    });

当您进入页面时,所有内容都可以注入,但是如果您稍后更新页面,样式和脚本会一直插入-一旦不进行任何更新,就会再次出现所有内容。

那是为什么?

如果您写入manifest.json content_scripts,这也不总是可行。有时它会打开一个页面(不重新启动),并且没有加载任何内容。

0 个答案:

没有答案