background.js
vip_url = {
'百度': 'http://baidu.com',
'百度': 'http://baidu.com',
'百度': 'http://baidu.com',
'百度': 'http://baidu.com',
'百度': 'http://baidu.com'
};
function openNewTab(url) {
chrome.tabs.create({
index: 0,
url: url
}, function (c) { });
}
chrome.runtime.onInstalled.addListener(function () {
var i = 0;
for (x in vip_url) {
var idTitle = x.split('-');
chrome.contextMenus.create({
id: idTitle[0],
type: 'normal',
title: idTitle[1],
contexts: ['page']
});
}
});
// 监听菜单的点击
chrome.contextMenus.onClicked.addListener(function (menuItem) {
var prefix = menuItem.pageUrl;
for (x in vip_url) {
if (x.indexOf(menuItem.menuItemId) != -1) {
prefix = vip_url[x];
}
}
chrome.tabs.create({
index: 0,
url: prefix
}, function (c) { });
});
menu.js
function genericOnClick(info, tab) {
alert(info.linkUrl);
}
function selectionOnClick(info, tab) {
alert(info.selectionText);
}
var link = chrome.contextMenus.create({"title": "链接地址","contexts":["link"],"onclick":genericOnClick});
var selection = chrome.contextMenus.create({"title": "选中文字","contexts":["selection"],"onclick":selectionOnClick});
popup.js
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {greeting: "hello"}, function(response) {
// console.log(response.farewell);
});
});
popup.html
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>访问助手</title>
<style type="text/css">
body {
margin: 0;
color: #345;
font: menu;
font-size: 8pt;
-webkit-user-select: none;
}
body,
td,
th,
input,
select,
textarea,
button {
font: menu;
font-size: 8pt;
}
body * {
white-space: nowrap;
}
hr {
height: 0;
margin: 0 0;
border: none;
border-top: solid 1px #eef;
}
.ltr,
.ltr * {
direction: ltr !important;
text-align: left !important;
}
#about {
font-size: 10pt;
padding: 10px;
}
#about * {
color: #578;
cursor: default;
}
#about a {
cursor: pointer;
text-decoration: blink;
color: #4285f4;
}
#about a:hover {
text-decoration: underline;
}
#about .header {
text-shadow: #ccc 1px 1px 3px;
}
#about .header td {
padding: 0 10px;
-webkit-padding-start: 0;
}
#about .header .title {
font-size: 22pt;
margin-top: -6px;
direction: ltr;
}
#about .header .titleTable {
border-collapse: collapse;
border-spacing: 0;
}
#about .header .titleTable td {
padding: 0;
}
#about .header .version {
font-size: 11pt;
padding: 0;
text-shadow: #ddd 1px 1px 2px;
-webkit-padding-start: 3px !important;
-webkit-user-select: text;
}
#about .header .versionNumber {
font-weight: bold;
-webkit-padding-start: 5px;
}
#about .header img {
vertical-align: middle;
}
#about .body {
padding: 10px 8px;
white-space: nowrap;
-webkit-user-select: text;
}
#about .body * {
color: #679;
}
#about .body span {
white-space: nowrap;
}
#about .footer {
height: 20px;
color: #789;
margin: 5px;
padding-top: 5px;
border-top: solid 1px #eef;
white-space: nowrap;
}
#about .close,
#addRule .close {
position: absolute;
right: 10px;
cursor: pointer;
}
#addRule .close {
top: 10px;
padding: 10px;
}
#about .close img,
#addRule .close img {
cursor: pointer;
}
#developer {
padding-bottom: 12px;
height: 74%
}
#developer .name {
padding: 5px 0;
}
#developer .name * {
font-size: 9pt;
}
#about #tips {
color: red;
font-size: 16px;
display: block;
padding-bottom: 5px;
}
#settings:after {
display: inline-block;
content: " ";
width: 100%;
height: 100%;
background: no-repeat url("theme/img/settings.png") 4px 4px;
}
.popup_copyright {
text-align: center;
}
#settings {
display: inline-block;
width: 25px;
height: 25px;
float: right;
margin-top: -22px;
}
</style>
</head>
<body data-i18n-values=".style.direction:global_direction;.style.textAlign:global_textAlign">
<div id="about">
<div class="header">
<table>
<tr>
<td>
<img src="icon.png" width="70" style="height: 59px;">
</td>
<td>
<table class="titleTable">
<tr>
<td colspan="2">
<div class="title">访问助手</div>
</td>
</tr>
<tr>
<td width="1" class="version" data-i18n-content="popup_version">版本</td>
<td class="version">
<span class="versionNumber" id="versionNumber">0.0.1</span>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div class="body">
<div id="developer">
<div class="name">
<table>
<tr>
<td data-i18n-content="popup_basedOn">11:
<a target="_blank" href="https://q.com/">PRD</a>,
<a target="_blank" href="https://q.com/">QA</a>,
<a target="_blank" href="http://d">DEV</a>
</td>
</tr>
<tr>
<td data-i18n-content="popup_basedOn">22:
<a target="_blank" href="http://b">PRD</a>,
<a target="_blank" href="http://q">QA</a>,
<a target="_blank" href="http://d">DEV</a>
</td>
</tr>
<tr>
<td data-i18n-content="popup_basedOn">33:
<a target="_blank" href="https://v">VPN </a>,
<a target="_blank" href="https://b">北斗</a>,
<a target="_blank" href="https://d">弹性云</a>
</td>
</tr>
<tr>
<td data-i18n-content="popup_basedOn">44:
<a target="_blank" href="http://c.com/">Code</a>
</td>
</tr>
<tr>
<td>
<br>
</td>
</tr>
<tr>
<td data-i18n-content="popup_basedOn">Maven仓库:
<a target="_blank" href="http://my">Maven仓库</a>
</td>
</tr>
<tr>
<td data-i18n-content="popup_basedOn">常用工具:
<br>
<a target="_blank" href="http://www.bejson.com/convert/unix/">时间戳转换</a>|
<a target="_blank" href="http://id.chacha138.com/">身份证号姓名匹配</a>|
<a target="_blank" href="https://www.json.cn/">Json格式化</a>|
<a target="_blank" href="https://tool.lu/sql/">sql格式化</a>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<script src="/popup.js"></script>
</body>
</html>
manifest.json
{
"manifest_version": 2,
"name": "访问助手",
"version": "0.0.4",
"description": "访问助手",
"homepage_url": "http:wwww.baidu.com",
"icons": {
"16": "icon/logo128.png",
"48": "icon/icon48.png",
"128": "icon/logo128.png"
},
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "访问助手"
},
"permissions": [
"background",
"contextMenus",
"tabs"
],
"background": {
"scripts": [
"background.js"
],
"persistent": false
}
}