修改文件
This commit is contained in:
parent
1bc804cf7d
commit
669babe5fd
@ -1,23 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>新标签页</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<style>
|
||||
html,body{height: 100%;}
|
||||
body{font-family: 'Microsoft Yahei';margin:0;padding:0;}
|
||||
.center {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
font-size: 48px;
|
||||
color: #CCC;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<head></head>
|
||||
<body>
|
||||
<div class="center"><p>这是一个自定义的新标签页</p></div>
|
||||
<script type="text/javascript" src="devtools.js"></script>
|
||||
<script type="text/javascript" src="js/devtools.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -1,8 +0,0 @@
|
||||
|
||||
chrome.devtools.panels.create("My Panel",
|
||||
"MyPanelIcon.png",
|
||||
"devtools.html",
|
||||
function(panel) {
|
||||
console.log(222);
|
||||
}
|
||||
);
|
@ -1,4 +1,4 @@
|
||||
// 右键菜单演示
|
||||
//-------------------- 右键菜单演示 ------------------------//
|
||||
chrome.contextMenus.create({
|
||||
title: "测试右键菜单",
|
||||
onclick: function(){
|
||||
@ -19,14 +19,43 @@ chrome.contextMenus.create({
|
||||
chrome.tabs.create({url: 'https://www.baidu.com/s?ie=utf-8&wd=' + encodeURI(params.selectionText)});
|
||||
}
|
||||
});
|
||||
|
||||
// badge 演示
|
||||
// chrome.browserAction.setBadgeText({text: 'new'});
|
||||
// chrome.browserAction.setBadgeBackgroundColor({color: [255, 0, 0, 255]});
|
||||
|
||||
chrome.tabs.onCreated.addListener(function(activeInfo)
|
||||
{
|
||||
//alert(activeInfo.tabId)
|
||||
console.log(activeInfo);
|
||||
chrome.pageAction.show(activeInfo.tabId);
|
||||
chrome.contextMenus.create({
|
||||
title: "获取当前页面tabId",
|
||||
onclick: function() {
|
||||
chrome.tabs.query({active: true, currentWindow: true}, function(tabs)
|
||||
{
|
||||
alert('当前tabId:' + (tabs.length ? tabs[0].id : '未知'));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------- badge演示 ------------------------//
|
||||
(function()
|
||||
{
|
||||
var showBadge = false;
|
||||
var menuId = chrome.contextMenus.create({
|
||||
title: '显示图标上的Badge',
|
||||
type: 'checkbox',
|
||||
checked: false,
|
||||
onclick: function() {
|
||||
if(!showBadge)
|
||||
{
|
||||
chrome.browserAction.setBadgeText({text: 'New'});
|
||||
chrome.browserAction.setBadgeBackgroundColor({color: [255, 0, 0, 255]});
|
||||
chrome.contextMenus.update(menuId, {title: '隐藏图标上的Badge', checked: true});
|
||||
}
|
||||
else
|
||||
{
|
||||
chrome.browserAction.setBadgeText({text: ''});
|
||||
chrome.browserAction.setBadgeBackgroundColor({color: [0, 0, 0, 0]});
|
||||
chrome.contextMenus.update(menuId, {title: '显示图标上的Badge', checked: false});
|
||||
}
|
||||
showBadge = !showBadge;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
console.log('这是content script!');
|
||||
|
||||
// 注意,必须设置了run_at=document_start 此段代码才会生效
|
||||
document.addEventListener('DOMContentLoaded', function()
|
||||
{
|
||||
// 给谷歌搜索结果的超链接增加 _target="blank"
|
||||
@ -12,5 +13,33 @@ document.addEventListener('DOMContentLoaded', function()
|
||||
}
|
||||
console.log('已处理谷歌超链接!');
|
||||
}
|
||||
else if(location.host == 'www.baidu.com')
|
||||
{
|
||||
function fuckBaiduAD()
|
||||
{
|
||||
var temp = document.createElement('style');
|
||||
temp.id = 'my_custom_css';
|
||||
(document.head || document.body).appendChild(temp);
|
||||
var css = `
|
||||
/* 移除百度右侧广告 */
|
||||
#content_right{display:none;}
|
||||
[data-click] [data-tuiguang]{display:none;}
|
||||
/* 覆盖整个屏幕的相关推荐 */
|
||||
.rrecom-btn-parent{display:none;}'
|
||||
/* 难看的按钮 */
|
||||
.result-op{display:none !important;}`;
|
||||
temp.innerHTML = css;
|
||||
console.log('已注入自定义CSS!');
|
||||
// 屏蔽百度推广信息
|
||||
$('[data-tuiguang]').parents('[data-click]').remove();
|
||||
// 重新搜索时页面不会刷新,但是被注入的style会被移除,所以需要重新执行
|
||||
temp.addEventListener('DOMNodeRemoved', function(e)
|
||||
{
|
||||
console.log('自定义CSS被移除,重新注入!');
|
||||
fuckBaiduAD();
|
||||
});
|
||||
}
|
||||
fuckBaiduAD();
|
||||
}
|
||||
});
|
||||
|
||||
|
14
demo/js/devtools.js
Normal file
14
demo/js/devtools.js
Normal file
@ -0,0 +1,14 @@
|
||||
// 创建自定义面板,同一个插件可以创建多个自定义面板
|
||||
// 几个参数依次为:panel标题、图标(其实设置了也没地方显示)、要加载的页面、加载成功后的回调
|
||||
chrome.devtools.panels.create('MyPanel', 'img/icon.png', 'mypanel.html', function(panel)
|
||||
{
|
||||
console.log('自定义面板创建成功!'); // 注意这个log一般看不到
|
||||
});
|
||||
|
||||
// 创建自定义侧边栏
|
||||
chrome.devtools.panels.elements.createSidebarPane("Images", function(sidebar)
|
||||
{
|
||||
// sidebar.setPage('../sidebar.html'); // 指定加载某个页面
|
||||
sidebar.setExpression('document.querySelectorAll("img")', 'All Images'); // 通过表达式来指定
|
||||
//sidebar.setObject({aaa: 111, bbb: 'Hello World!'}); // 直接设置显示某个对象
|
||||
});
|
54
demo/js/mypanel.js
Normal file
54
demo/js/mypanel.js
Normal file
@ -0,0 +1,54 @@
|
||||
// 检测jQuery
|
||||
document.getElementById('check_jquery').addEventListener('click', function()
|
||||
{
|
||||
// 访问被检查的页面DOM需要使用inspectedWindow
|
||||
// 简单例子:检测被检查页面是否使用了jQuery
|
||||
chrome.devtools.inspectedWindow.eval("jQuery.fn.jquery", function(result, isException)
|
||||
{
|
||||
var html = '';
|
||||
if (isException) html = '当前页面没有使用jQuery。';
|
||||
else html = '当前页面使用了jQuery,版本为:'+result;
|
||||
alert(html);
|
||||
});
|
||||
});
|
||||
|
||||
// 打开某个资源
|
||||
document.getElementById('open_resource').addEventListener('click', function()
|
||||
{
|
||||
chrome.devtools.inspectedWindow.eval("window.location.href", function(result, isException)
|
||||
{
|
||||
chrome.devtools.panels.openResource(result, 20, function()
|
||||
{
|
||||
console.log('资源打开成功!');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// 审查元素
|
||||
document.getElementById('test_inspect').addEventListener('click', function()
|
||||
{
|
||||
chrome.devtools.inspectedWindow.eval("inspect(document.images[0])", function(result, isException){});
|
||||
});
|
||||
|
||||
// 获取所有资源
|
||||
document.getElementById('get_all_resources').addEventListener('click', function()
|
||||
{
|
||||
chrome.devtools.inspectedWindow.getResources(function(resources)
|
||||
{
|
||||
alert(JSON.stringify(resources));
|
||||
});
|
||||
});
|
||||
|
||||
var myconsole =
|
||||
{
|
||||
_log: function(obj)
|
||||
{
|
||||
// 不知为何,这种方式不行
|
||||
chrome.devtools.inspectedWindow('console.log('+JSON.stringify(obj)+')');
|
||||
},
|
||||
log: function(obj)
|
||||
{
|
||||
// 这里有待完善
|
||||
chrome.tabs.executeScript(chrome.devtools.inspectedWindow.tabId, {code: 'console.log(' + JSON.stringify(obj) + ')'}, function(){});
|
||||
}
|
||||
};
|
@ -23,6 +23,7 @@
|
||||
"browser_action":
|
||||
{
|
||||
"default_icon": "img/icon.png",
|
||||
// 图标悬停时的标题,可选
|
||||
"default_title": "这是一个示例Chrome插件",
|
||||
"default_popup": "popup.html"
|
||||
},
|
||||
@ -38,7 +39,10 @@
|
||||
[
|
||||
{
|
||||
"matches": ["http://*/*", "https://*/*"],
|
||||
"js": ["js/content-script.js"]
|
||||
"js": ["js/jquery-1.8.3.js", "js/content-script.js"],
|
||||
"css": [],
|
||||
// 代码注入的时间,可选值: "document_start", "document_end", or "document_idle",最后一个表示页面空闲时,默认document_idle
|
||||
"run_at": "document_start"
|
||||
}
|
||||
],
|
||||
// 权限申请
|
||||
@ -46,13 +50,18 @@
|
||||
[
|
||||
"contextMenus", // 右键菜单
|
||||
"tabs", // 标签
|
||||
"notifications"
|
||||
"notifications", // 通知
|
||||
"http://*/*", // 可以通过executeScript或者insertCSS访问的网站
|
||||
"https://*/*" // 可以通过executeScript或者insertCSS访问的网站
|
||||
],
|
||||
// 插件主页,这个很重要,不要浪费了这个免费广告位
|
||||
"homepage_url": "https://www.baidu.com",
|
||||
// 覆盖浏览器默认页面
|
||||
"chrome_url_overrides":
|
||||
{
|
||||
// 覆盖浏览器默认的新标签页
|
||||
"newtab": "newtab.html"
|
||||
},
|
||||
// devtools页面入口,注意只能指向一个HTML文件,不能是JS文件
|
||||
"devtools_page": "devtools.html"
|
||||
}
|
38
demo/mypanel.html
Normal file
38
demo/mypanel.html
Normal file
@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>新标签页</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<style>
|
||||
html,body{height: 100%;}
|
||||
body{font-family: 'Microsoft Yahei';margin:0;padding:0;}
|
||||
.center {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 40px;
|
||||
color: #CCC;
|
||||
}
|
||||
.content {
|
||||
position: absolute;
|
||||
left: 20px;
|
||||
top: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="center"><p>这是一个自定义Chrome开发者工具页面</p></div>
|
||||
<div class="content">
|
||||
<div><a href="javascript:;" id="check_jquery">检测当前页面jQuery</a></div>
|
||||
<div><a href="javascript:;" id="open_resource">查看当前页面HTML代码的第20行</a></div>
|
||||
<div><a href="javascript:;" id="test_inspect">审查当前页面第一张图片</a></div>
|
||||
<div><a href="javascript:;" id="get_all_resources">获取当前页面所有Resources</a></div>
|
||||
</div>
|
||||
<script type="text/javascript" src="js/mypanel.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -2,6 +2,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>新标签页</title>
|
||||
<meta charset="utf-8"/>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<style>
|
||||
html,body{height: 100%;}
|
||||
|
@ -1,15 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>popup</title>
|
||||
<title>popup页</title>
|
||||
<meta charset="utf-8"/>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<style>
|
||||
body{font-family: 'Microsoft Yahei';}
|
||||
body {
|
||||
font-family: 'Microsoft Yahei';
|
||||
width: 500px;
|
||||
min-height: 100px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>这是一个popup页面!</h1>
|
||||
<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
|
||||
<script type="text/javascript" src="js/popup.js"></script>
|
||||
</head>
|
||||
<body style="width:300px;min-height:100px;">
|
||||
<h1>这是一个popup页面!</h1>
|
||||
</body>
|
||||
</html>
|
23
demo/sidebar.html
Normal file
23
demo/sidebar.html
Normal file
@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>侧边栏</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<style>
|
||||
html,body{height: 100%;}
|
||||
body{font-family: 'Microsoft Yahei';margin:0;padding:0;}
|
||||
.center {
|
||||
position: fixed;
|
||||
left: 10px;
|
||||
top: 10px;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-size: 18px;
|
||||
color: #CCC;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="center"><p>这是一个自定义侧边栏</p></div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user