1. 程式人生 > >chrome外掛-自動填寫績效

chrome外掛-自動填寫績效

##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();
}