chrome扩展开发——自动填表实例
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
manifest.json配置文件
---------------------------
{
"name": "项目名称",
"version": "1.0",
"permissions": ["tabs", "http://*/*", "https://*/*"],
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["jquery-1.6.4.min.js"]
}
],
"icons": {"128":"icon.png"},
"browser_action": {
"default_title": "优酷好友申请批量通过",
"default_icon": "icon.png",
"popup": "popup.html"
}
}
-------------------------------------------
解释:
"permissions": ["tabs", "http://*/*", "https://*/*"]是该扩展应用到tabs(选项页)中的所有http://和https://页面
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"], jquery应用的页面有http 和https开头的页面
"js": ["jquery-1.6.4.min.js"] 这是导入jquery用以应用
}],
浏览器行为:
"browser_action": {
"default_title": "优酷好友申请批量通过",
"default_icon": "icon.png",
"popup": "popup.html" 行为代码页面
}
popup.html浏览器行为代码页面,就是点击浏览器上的图标后,执行这个页面来对当前选项卡页面进行处理
-----------------------------------------------
function click() {
var y = Math.floor(Math.random()*10) + 7 ;
var x = Math.pow(10,y);
var num = Math.round( ( Math.random()*x ) );
var strEmail = num + "@";
//user_name
//百家姓
var arrName = new Array("王","李","张","刘","陈","杨","黄","孙","周","吴","徐","赵","朱","马","胡","郭","林","何","高","梁","郑","罗","宋","谢","唐","韩","曹","许","邓","萧","冯","曾","程","蔡","彭","潘","袁","于","董","余","苏","叶","吕","魏","蒋","田","杜","丁","沈","姜","范","江","傅","钟","卢","汪","戴","崔","任","陆","廖","姚","方","金","邱","夏","谭","韦","贾","邹","石","熊","孟","秦","阎","薛","侯","雷","白","龙","段","郝","孔","邵","史","毛","常","万","顾","赖","武","康","贺","严","尹","钱","施","牛","洪","龚","汤","陶","黎","温","莫","易","樊","乔","文","安","殷","颜","庄","章","鲁","倪","庞","邢","俞","翟","蓝","聂","齐","向","申","葛","柴","伍","覃","骆","关","焦","柳","欧","祝","纪","尚","毕","耿","芦","左","季","管","符","辛","苗","詹","曲","欧阳","靳","祁","路","涂","兰","甘","裴","梅","童","翁","霍","游","阮","尤","岳","柯","牟","滕","谷","舒","卜","成","饶","宁","凌","盛","查","单","冉","鲍","华","包","屈","房","喻","解","蒲","卫","简","时","连","车","项","闵","邬","吉","党","阳","司","费","蒙","席","晏","隋","古","强","穆","姬","宫","景","米","麦","谈","柏","瞿","艾","沙","鄢","桂","窦","郁","缪","畅","巩","卓","褚","栾","戚","全","娄","甄","郎","池","丛","边","岑","农","苟","迟","保","商","臧","佘","卞","虞","刁","冷","应","匡","栗","仇","练","楚","揭","师","官","佟","封","燕","桑","巫","敖","原","植","邝","仲","荆","储","宗
","楼","干","苑","寇","盖","南","屠","鞠","荣","井","乐","银","奚","明","麻","雍","花","闻","冼","木","郜","廉","衣","蔺","和","冀","占","公","门","帅","利","满 ");
//随机获得
var n1 = Math.round(Math.random() * 300);
var n2 = Math.round(Math.random() * 300);
var n3 = Math.round(Math.random() * 300);
var strName = arrName[n1] + arrName[n2] + arrName[n3];
//密码
var strPwd = 123123;
//填表
chrome.tabs.executeScript(null, {code:"document.getElementById('email').value='" + strEmail + "'"});
chrome.tabs.executeScript(null, {code:"document.getElementById('user_name').focus()"});
chrome.tabs.executeScript(null, {code:"document.getElementById('user_name').value='" + strName + "'"});
chrome.tabs.executeScript(null, {code:"document.getElementById('passwd').focus()"});
chrome.tabs.executeScript(null, {code:"document.getElementById('passwd').value='" + strPwd + "'"});
chrome.tabs.executeScript(null, {code:"document.getElementById('repasswd').focus()"});
chrome.tabs.executeScript(null, {code:"document.getElementById('repasswd').value='" + strPwd + "'"});
chrome.tabs.executeScript(null, {code:"javascript:refresh_captcha()"});
chrome.tabs.executeScript(null, {code:"document.getElementById('captcha').focus()"});
window.close();
}