Chrome插件13: 修改Css

本文介绍了一个名为'FirstChromePlugin'的谷歌浏览器插件的详细配置,包括浏览器动作、后台页面、权限、内容脚本等设置。通过示例HTML和JS代码,展示了如何实现插件的基本功能,如修改页面CSS、调用后台JS以及系统通知等。
摘要由CSDN通过智能技术生成

主文件

{

 "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"')
})
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值