chrome 自动填写表单插件

主要功能是打开任意网页插件会自动判断URL是否是form.php结尾,如果是则按照规则自动填写网页表单,如果不是则略过。

Manifest.json

{
  "name": "智能表单助手",
  "description": "自动填充***申请友情链接表单",
  "version": "1.0",
  "permissions": [
    "tabs", "http://*/plus/flink_add.php", "https://*/plus/flink_add.php"
  ],
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "browser_action": {
      "default_title": "自动填充***申请友情链接表单",
      "default_icon": "bird.png" 
  },
  "manifest_version": 2
}

background.js

// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Called when the user clicks on the browser action.

function check***(url){
    console.log('URL:'+url);
    var flag = false;
    if(typeof url == "undefined" || null == url)
        url = window.location.href; 
    var regex = /.*\:\/\/.*\/form.php/;
    var match = url.match(regex);
    if(typeof match != "undefined" && null != match)
        flag = true;
    return flag;
}
function autoAddValue()
{  
    chrome.tabs.executeScript(null,
        {code:" var inputs = document.querySelectorAll('input');\
                inputs[1].value='http://www.xxx.com.cn/';\
				inputs[2].value='xxxx';\
				inputs[3].value='http://www.xx.com.cn/xxx';\
				inputs[4].value='xxx@163.com';\
				var textareas = document.querySelectorAll('textarea');\
				textareas[0].value='xxxx';\
        "}); 
}

chrome.browserAction.onClicked.addListener(function(tab) {

    if(check***(tab.url))
	{
		autoAddValue();
		chrome.tabs.executeScript({
			code: 'document.body.style.backgroundColor="#f2d649"'
		});
		console.log('*** 表单填写成功!');
	}
	else
	{
		console.log('不是***网站!'); 
		chrome.tabs.executeScript({
			code: 'document.body.style.backgroundColor="#f24182"'
		});
	}
});
chrome.tabs.onUpdated.addListener(
function(tabId,changeInfo,tab){ 
    if(check***(tab.url))
	{
		autoAddValue();
		chrome.tabs.executeScript({
			code: 'document.body.style.backgroundColor="#f2d649"'
		});
		console.log('*** 表单填写成功!');
	}
	else
	{
		console.log('不是***网站!'); 
		chrome.tabs.executeScript({
			code: 'document.body.style.backgroundColor="#f24182"'
		});
	}
});

完整代码下载:http://download.csdn.net/detail/nerslegmail/8308589

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值