manifest.json
{
"name": "1",
"manifest_version": 2,
"version": "1.0",
"description": "2",
"browser_action":
{
"default_icon": "1.png",
"default_popup":"1.html"
}
,"permissions":
[
"cookies"
,"tabs"
,"activeTab"
,"http://*/*"
,"webRequest"// web请求
,"webRequestBlocking"
]
,"web_accessible_resources": ["js/in.js"]
//,"background":{"scripts":["jq.js","js/a.js"]}
,"content_scripts":
[
{
"matches": ["http://jk.jznews.com.cn/*"],
"run_at": "document_end",
"js": ["1.js","jq.js"],
"all_frames": true
}
]
}
1.JS
var url=document.URL;
if(document.URL.indexOf("login_new.aspx")!=-1)
{
console.log("1.js login...");
var bt="<button style=\"margin:2px;\"onclick=\"load(\'jk1003yl\',\'yl8888\')\">杨莉</button>";
bt=bt+"<button style=\"margin:2px;\"onclick=\"load(\'jk2035whb\',\'jk2035whb\')\">王海波</button>";
bt=bt+"<button style=\"margin:2px;\"onclick=\"load(\'jk2035zj\',\'1988226zj\')\">赵静</button>";
bt=bt+"<button style=\"margin:2px;\"onclick=\"load(\'sjk401442\',\'xb434400\')\">刘嗣周</button>";
bt=bt+"<button style=\"margin:2px;\"onclick=\"load('jk4003001','ly13697157979')\">李义</button>";
bt=bt+"<button style=\"margin:2px;\"onclick=\"load('sjk40060523','xiajuan0523')\">夏娟</button>";
var str1="<div style=\"margin:0 auto;width:400px;\">"+bt+"</div>";
document.body.innerHTML=document.body.innerHTML+str1;
///js注入
injectCustomJs();
function injectCustomJs()
{
//jsPath = jsPath;
jsPath='js/in.js';
var temp = document.createElement('script');
temp.setAttribute('type', 'text/javascript');
// 获得的地址类似:chrome-extension://ihcokhadfjfchaeagdoclpnjdiokfakg/js/inject.js
temp.src = chrome.extension.getURL(jsPath);
temp.onload = function()
{
// 放在页面不好看,执行完后移除掉
this.parentNode.removeChild(this);
};
document.head.appendChild(temp);
}
}
if(document.URL.indexOf("Learning_Detail.aspx")!=-1)
{
getanswer();
var str1=document.getElementById("div_question").innerHTML;
check_tm();
function check_tm()
{
//console.log("check_tm");
var str2=document.getElementById("div_question").innerHTML;
if(str1!=str2)
{
getanswer();
str1=str2;
console.log("check_tm");
}
setTimeout("check_tm()",1000);
}
//
check_jx();
//
function check_jx()
{
if(document.getElementById("btnAnswer").value=="继续答题")
{
document.getElementById("btnAnswer").click();
console.log("check_jx");
}
setTimeout("check_jx()",2000);
}
function getanswer()
{
try
{
if(document.getElementById("hidden_a").value==1)
{
document.getElementById("a").click();
}
if(document.getElementById("hidden_b").value==1)
{
document.getElementById("b").click();
}
if(document.getElementById("hidden_c").value==1)
{
document.getElementById("c").click();
}
if(document.getElementById("hidden_d").value==1)
{
document.getElementById("d").click();
}
}
catch(e)
{
}
if(document.getElementById("btnAnswer").value=="确认提交")
{
document.getElementById("btnAnswer").click();
}
}
}
js/in.js (这段JS会注入页面环境)
function load(user,psw)
{
var cookie="";
var c_name="jk2016"
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1)
{
c_start=c_start + c_name.length+1
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
cookie=unescape(document.cookie.substring(c_start,c_end))
}
}
document.getElementById("UName").value=user;
document.getElementById("UPwd").value=psw;
document.getElementById("txtCode").value=cookie;
document.getElementById("btnLogin").click();
}