Giter Club home page Giter Club logo

js-inject's Introduction

Elong_javascript_inject v1.0.0

chrome浏览器拓展——js脚本拦截及注入

概要

该浏览器拓展插件是拥有为页面拦截和注入js功能的chrome浏览器扩展,可以拦截页面脚本、检索页面脚本文件、下载页面脚本文件、为页面注入js文件,以及为页面注入requirejs和requirejs入口文件。

安装方式

拓展为开发版本,尚未打包发布,安装时需要将项目文件更新到本地,具体如下:

  • 1,更新项目到本地目录,如:/users/js_inject

  • 2,在chrome浏览器中打开 chrome://extensions/

  • 3,点击“加载正在开发的拓展程序”按钮

  • 4,选择/users/js_inject目录,确定

  • 5,浏览器地址栏右边的艺龙logo小图标,即为拓展插件的入口

自定义

在本版插件中,预设了一些默认设定,可以根据实际需求进行修改。功能点、配置文件位置、如何修改详情如下:

1,配置需要开启js拦截功能的站点域名。“background.js” 文件中的如下位置:

urls: [
	"*://*.jquery.top/*", //域名过滤器,*://*/* 表示所有协议、所有域名、域名下的所有资源均匹配 
    "*://*.baidu.com/*"
],

2,配置拓展启动时需要向页面注入的资源。“manifest.json” 文件中的如下位置:

"content_scripts": [
	{
		"matches": ["http://*/*"], //域名过滤器
		"js": ["jquery-1.9.1.js"], //需要向页面中注入的脚本资源
		"run_at": "document_end"   //注入时机,该选项表明是文档节点加载完成后注入
	}
],

3,配置拓展包内资源引用权限。“manifest.json” 文件中的如下位置:

"web_accessible_resources": [
	"require.js",
	"returnjs.js",
	"images/*"
]

功能点

1,脚本拦截功能

打开拦截匹配的域名链接后,拓展会自动拦截页面中引入的所有的外部脚本资源。

2,js脚本检索功能

打开拓展界面后,即会加载出页面中所有引用的外部js脚本列表,可以通过“检索URL”输入框对脚本关键字进行检索。

3,下载选中脚本

点击“下载选中脚本”按钮可以下载已经选中的检索出的脚本文件。

4,向页面中注入指定脚本(远程脚本)

4.1 普通注入方式

普通注入方式将直接向页面中注入在“脚本URL”文本框中输入的远程脚本并立即执行。

4.2 requirejs入口脚本方式注入

该方式将首先向页面注入require.js,随后将把“脚本URL”文本框中输入的远程脚本作为requirejs的入口脚本执行。

注:脚本URL文本框中默认的远程url即通过requirejs入口脚本方式注入的demo,注入的main.js文件将依赖jQuery.js和另一个自定义模块count.js,注入后会更改页面背景色为红色,并在控制台输出“111+222”的计算结果。

外部API资源文档

360极速浏览器开放平台(chrome官方API的中文版本,但不是最新): http://open.chrome.360.cn/extension_dev/overview.html

chrome插件中文开发文档(非官方,与官方文档一致,不用翻墙): http://chrome.liuyixi.com/overview.html

Chrome扩展及应用开发(电子书): http://www.ituring.com.cn/book/1472

js-inject's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.