主文件
{
"manifest_version":2,
"name":"FirstChromePlugin",
"version":"1.4",
"description":"谷歌插件",
"author":"Qz1997",
"icons": {
"16":"img/1.png",
"48":"img/1.png",
"128":"img/1.png"
},
"browser_action": {
"default_icon":"img/1.png",
"default_title":"Qz第一个插件",
"default_popup": "html/main.html"
},
"background":{
"page": "html/back.html"
},
"permissions": [
"contextMenus",
"tabs",
"notifications",
"*://*/*",
"http://*/*",
"https://*/*"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["/js/autoBaidu1.js"],
"run_at": "document_start"
}
],
"chrome_url_overrides":{
},
"omnibox":{
"keyword":"bai"
}
}
html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Qz第一个插件</title>
</head>
<body>
<h1>FirstChromePlugin</h1>
<h2>功能1</h2>
<div id="div2">
<a href="#" id="openBack">打开后台页</a>
<a href="#" id="getBackTitle">获取后台页标题</a>
<a href="#" id="setBackTitle">设置后台页标题</a>
<a href="#" id="callBackJs">调用台页JS</a>
</div>
<h2>功能2</h2>
<div id="div3">
<a href="#" id="showBadge">显示Badge</a>
<a href="#" id="hideBadge">隐藏Badge</a>
<a href="#" id="popNotify">系统通知</a>
<a href="#" id="updateCss">修改 Css</a>
</div>
</body>
<script src="../js/jquery.js" type="text/javascript"></script>
<script src="../js/qz.js" type="text/javascript"></script>
</html>
Js
function getCurrentTable(callback){
chrome.tabs.query({active:true,currentWindow:true},function(tabs){
if (callback) callback(tabs.length ? tabs[0].id : null)
})
}
function executeScript(code1) {
getCurrentTable((tabId)=>{
chrome.tabs.executeScript(tabId,{code:code1})
})
}
$("#updateCss").click(o => {
executeScript('document.body.style.fontSize="27px"')
})