Skip to content

Commit 1bc804c

Browse files
author
xiananliu
committed
初始化
1 parent 5bf1ff7 commit 1bc804c

File tree

10 files changed

+9674
-0
lines changed

10 files changed

+9674
-0
lines changed

demo/devtools.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>新标签页</title>
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6+
<style>
7+
html,body{height: 100%;}
8+
body{font-family: 'Microsoft Yahei';margin:0;padding:0;}
9+
.center {
10+
display: flex;
11+
align-items: center;
12+
justify-content: center;
13+
height: 100%;
14+
font-size: 48px;
15+
color: #CCC;
16+
}
17+
</style>
18+
</head>
19+
<body>
20+
<div class="center"><p>这是一个自定义的新标签页</p></div>
21+
<script type="text/javascript" src="devtools.js"></script>
22+
</body>
23+
</html>

demo/devtools.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
chrome.devtools.panels.create("My Panel",
3+
"MyPanelIcon.png",
4+
"devtools.html",
5+
function(panel) {
6+
console.log(222);
7+
}
8+
);

demo/img/icon.png

41.1 KB
Loading

demo/js/background.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// 右键菜单演示
2+
chrome.contextMenus.create({
3+
title: "测试右键菜单",
4+
onclick: function(){
5+
chrome.notifications.create(null, {
6+
type: 'basic',
7+
iconUrl: 'img/icon.png',
8+
title: '这是标题',
9+
message: '您刚才点击了自定义右键菜单!'
10+
});
11+
}
12+
});
13+
chrome.contextMenus.create({
14+
title: '使用度娘搜索:%s', // %s表示选中的文字
15+
contexts: ['selection'], // 只有当选中文字时才会出现此右键菜单
16+
onclick: function(params)
17+
{
18+
// 注意不能使用location.href,因为location是属于background的window对象
19+
chrome.tabs.create({url: 'https://www.baidu.com/s?ie=utf-8&wd=' + encodeURI(params.selectionText)});
20+
}
21+
});
22+
23+
// badge 演示
24+
// chrome.browserAction.setBadgeText({text: 'new'});
25+
// chrome.browserAction.setBadgeBackgroundColor({color: [255, 0, 0, 255]});
26+
27+
chrome.tabs.onCreated.addListener(function(activeInfo)
28+
{
29+
//alert(activeInfo.tabId)
30+
console.log(activeInfo);
31+
chrome.pageAction.show(activeInfo.tabId);
32+
});

demo/js/content-script.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
console.log('这是content script!');
2+
3+
document.addEventListener('DOMContentLoaded', function()
4+
{
5+
// 给谷歌搜索结果的超链接增加 _target="blank"
6+
if(location.host == 'www.google.com.tw')
7+
{
8+
var objs = document.querySelectorAll('h3.r a');
9+
for(var i=0; i<objs.length; i++)
10+
{
11+
objs[i].setAttribute('_target', 'blank');
12+
}
13+
console.log('已处理谷歌超链接!');
14+
}
15+
});
16+

0 commit comments

Comments
 (0)