浏览器小插件

在这里插入图片描述
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
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值