我正在开发一个Chrome扩展程序,当我访问“ https://www.google.com/”时会执行这些操作
清单文件:
{
"manifest_version": 2,
"name": "google extension",
"version": "0.1.0",
"description": "google extension",
"browser_action":{
"default_icon":"IMG/ghost.png"
} ,
"content_scripts": [{
"js": ["JS/jquery.min.js","JS/changecolor.js"],
"matches": ["https://www.google.com/*"],
"run_at": "document_end"
}]
}
changecolor.js文件:
$("#tsf").css("background","black"); // this works
$("#lst-ib").val("JAV"); // this works
$(".jsb").eq(2).find("input").click(); //this doesnt work
我想念什么吗?
答案 0 :(得分:0)
我已经找到用户PAEz的答案
How can I make a Chrome extension automatically click a button when a page loads?
我要在这里引用它:
function simulateClick(obj) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
var canceled = !obj.dispatchEvent(evt);
/*
if(canceled) {
// A handler called preventDefault
alert("canceled");
} else {
// None of the handlers called preventDefault
alert("not canceled");
}
*/
}
var what = document.querySelector('input[type="button"][value="Start!"]');
simulateClick(what);