javascript - 在不加载活动选项卡的情况下运行内容脚本
问题描述
如何在不重新加载活动选项卡的情况下运行内容脚本?
内容脚本仅在我刷新活动选项卡时才有效。
清单.js
{
"name": "CMS",
"description": "A simple CMS solution that can update a website contents and images without modifying the current website structure.",
"options_page": "options.html",
"background": {
"page": "background.html"
},
"browser_action": {
"default_popup": "popup.html",
"default_icon": "icon48.png"
},
"icons": {
"16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png"
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*", "<all_urls>"],
"js": ["contentScript.bundle.js"],
"css": ["content.styles.css"]
}
],
"web_accessible_resources": [
"content.styles.css",
"icon128.png",
"icon48.png"
],
"manifest_version": 2,
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}
内容脚本
let paragraphs = document.querySelectorAll('*');
for (const elt of paragraphs) {
elt.style['border'] = '1px solid green';
}
解决方案
推荐阅读
- sql - SQL Code = -420 在函数“decfloat”的字符串参数中发现无效字符
- java - Spring HATEOAS 构建指向分页资源的链接
- google-app-maker - AppMaker 中的过滤器
- php - PHP表单不向数据库发送数据
- javascript - RxJS.Observable 是一个单子吗?
- javascript - 在移动模式下单击按钮时,按钮仅工作一次
- reactjs - 反应路由器 v4。重定向不起作用
- c# - 在 WebDav 中打开 xlsx 文档提示重命名
- sql - 在 SQL 中计算百分位数
- laravel - laravel 应用程序不会出现在本地主机上