【发布时间】:2020-06-06 21:21:26
【问题描述】:
我第一次尝试开发 chrome 扩展程序,但我遇到了一些困难。 我想要达到的目标: 每次重新加载新 URL 时,它都会检查它是否是我定义的特定 URL 之一,比如说 - 如果重新加载 URL = https://www.google.com/,将文本更改为“这是 google”。 如果重新加载 URL = https://translate.google.com/,将文本更改为“这是 google transalte”,等等 20 个 URL。 当没有重新加载任何 URL 时,它将停留在最后一个状态。
如有任何帮助,将不胜感激。
Popup.html
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<link rel="stylesheet" type="text/css" href="art.css"> <!--Include art.css File-->
<body>
<button id="click"></button>
<h1>H1</h1>
<h2>The Text I want to change</h2>
<div class="square"></div>
<h3>by X</h3>
</body>
</html>
background.js
chrome.runtime.onInstalled.addListener(function () {
chrome.tabs.insertCSS(tabId, {
file: "art.css"
});
});
manifest.json
{
"name": "X2",
"version": "1.0",
"description": "X3",
"permissions": [ "tabs", "activeTab", "declarativeContent", "storage" ],
"background": {
"scripts": [ "background.js" ], //Background Scripts
"persistent": false
},
"web_accessible_resources": [
"art.css"
],
"page_action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
}
},
"icons": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
},
"manifest_version": 2
}
【问题讨论】:
标签: javascript html css google-chrome google-chrome-extension