我正在编写一个 chrome 扩展程序,我基本上希望当它处于活动状态时,屏幕上显示一个小圆圈。我需要 CSS,所以我想做的是在我的清单中添加背景,并且基本上只在单击图标时执行内容脚本。目前我知道如果选项卡 URL 更改,该设置就会打开,但我正在测试一些东西。我需要将 CSS 添加到我的内容脚本中,但不知道如何添加。我查了一下,发现 insertCSS() 是一个东西,但这只是一行代码,我有更多的东西。有什么想法吗?我已经审阅了它的主要 google 文档以及 MDN。任何帮助,将不胜感激。
//BACKGROUND
try {
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(changeInfo.status == 'complete') {
chrome.scripting.executeScript({
files: ['content-script.js'],
target: {tabId: tab.id}
});
}
});
} catch (e) {
console.log(e);
}
//CONTENT-SCRIPT (in another file, wasn't sure how to add it to the question
if (typeof init === 'undefined') {
const init = function() {
const injectElement = document.createElement("button");
injectElement.className = 'button_attempt';
injectElement.innerHTML = "T";
document.body.appendChild(injectElement);
}
init();
}Run Code Online (Sandbox Code Playgroud)
//CSS
@import url('https://fonts.googleapis.com/css2?family=Prociono&family=Sorts+Mill+Goudy&display=swap'); …Run Code Online (Sandbox Code Playgroud)javascript css scripting google-chrome-extension chrome-extension-manifest-v3