我正在使用"run_at": "document_end"
但是当预订配额打开时,运行它的网站会过载。意味着在8/10的情况下,前5分钟内容脚本不会被调用。可能是js文件没有加载并需要很长时间才能加载
我想要的是,即使DOM加载失败或仍在加载,我想在页面上找到“#label1
”元素时立即启动内容脚本。
如何实现它?
现在我已在内容脚本中使用此逻辑将run_at
更改为docment_start
:
var sidbegin = setInterval(function () {
console.log('script started');
if (document.getElementById('label1')) //is label1 there?
{
$(document).ready(function () {
$("#label1").before('<button id="fillall">Fill All</button>');
$("#fillall").click(function(){
main_func();
return false;
});
clearInterval(sidbegin);
});
}
}, 200);
{
"name": "inv b Autofill",
"options_page": "options.html",
"description": "Autofiller and clicker for inv b",
"version": "1.3",
"icons": {
"16": "icons/logo16.png",
"48": "icons/logo48.png",
"128": "icons/logo128.png"
},
"permissions": [
"tabs", "notifications", "cookies", "history", "browsingData", "activeTab", "storage", "webRequest", "webRequestBlocking", "http://*/*", "https://*/*"
],
"background": {
"scripts": [
"js/lz-string.min.js",
"client_server_common.js",
"common.js",
"background.js"
],
"persistent": true
},
"browser_action": {
"default_title": "Change the v details",
"default_popup": "options.html"
},
"content_security_policy": "script-src 'self'; object-src 'self'",
"manifest_version": 2,
"content_scripts": [
{
"run_at": "document_end",
"all_frames": true,
"matches": ["*://inv-b.nic.in/*", "http://inv-b.nic.in/", "http://45.79.8.5/*"],
"css": ["jqueryui/jquery-ui.css", "jqueryui/jquery-ui.css", "js/slidenavi/sidenavi-right.css","main.css", "jqueryui/jquery-ui.css", "js/bootstrap-switch-master/dist/css/bootstrap3/bootstrap-switch.min.css"],
"js": ["jquery-2.1.4.min.js", "jqueryui/jquery-ui.min.js", "js/jquery.cookie.js", "jqueryui/jquery-ui.min.js","js/slidenavi/SideNavi.js","js/cryptojs/rollups/aes.js", "client_server_common.js", "user-selections.js",
"jquery.countdown.min.js", "js/bootstrap-switch-master/dist/js/bootstrap-switch.min.js", "js/cryptojs/rollups/md5.js", "js/ocrad.js", "common.js",
"myscript.js"
]
},
{
"run_at": "document_start",
"all_frames": true,
"matches": ["*://inv-b.nic.in/*", "http://inv-b.nic.in/", "http://45.79.8.5/*"],
"css": ["jqueryui/jquery-ui.css", "main.css", "jqueryui/jquery-ui.css", "js/bootstrap-switch-master/dist/css/bootstrap3/bootstrap-switch.min.css"],
"js": ["jquery-2.1.4.min.js", "jqueryui/jquery-ui.min.js", "js/jquery.cookie.js", "js/cryptojs/rollups/aes.js", "client_server_common.js", "user-selections.js",
"jquery.countdown.min.js", "js/bootstrap-switch-master/dist/js/bootstrap-switch.min.js", "js/cryptojs/rollups/md5.js", "js/ocrad.js", "common.js",
"myscriptbeforedom.js"
]
},
{
"run_at": "document_start",
"all_frames": false,
"matches": ["*://inv-b.nic.in/*", "http://inv-b.nic.in/", "http://45.79.8.5/*"],
"js": ["client_server_common.js", "common.js", "injected/remove-alert.js"]
}
],
"web_accessible_resources": [
"options.html", "terms.html", "resource/v/js/modernizr.js",
]
}