css - Chrome 扩展 Tailwind CSS 干扰了我访问的网站
问题描述
我正在构建一个 chrome 扩展。我正在使用 React、Typescript、TailwindCSS、自定义 Webpack 配置。我已经覆盖了 manifest.json 中的默认操作,因此单击工具栏图标会触发一条消息并打开内容脚本,该脚本会在任何站点上注入停留。
我面临的问题是我的 Tailwind 样式会影响我访问的每个网站,有时还会影响其他网站。例如。谷歌搜索网站的标题更小,在 Reddit 上,我的扩展程序的文本更小。
我希望我的扩展样式仅应用于我的停留。我已经尝试过使用 React Shadow DOM 但它不起作用,我可能做错了什么。
这是我的文件:
manifest.json
{
"name": "Intro",
"description": "Intro extension",
"version": "1.0.0",
"manifest_version": 3,
"icons": {
"16": "icon.png",
"48": "icon.png",
"128": "icon.png"
},
"action": {
"default_title": "Intro",
"default_icon": "icon.png"
},
"permissions": ["alarms", "contextMenus", "storage"],
"options_page": "options.html",
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["contentScript.js"]
}
]
}
contentScript.tsx
import React, { useEffect, useState } from 'react';
import ReactDOM from 'react-dom';
import { Messages } from '../utils/types';
import '@fontsource/roboto';
import { useDelayUnmount } from '../hooks/useDelayUnmount';
import App from '../App';
import './contentScript.css';
const mountedStyle = { animation: 'inAnimation 150ms ease-in' };
const unmountedStyle = {
animation: 'outAnimation 170ms ease-out',
animationFillMode: 'forwards',
};
const ContentScriptOverlay: React.FC<{}> = () => {
const [isActive, setIsActive] = useState<boolean>(false);
const showDiv = useDelayUnmount(isActive, 250);
const handleMessages = (msg: Messages) => {
if (msg === Messages.TOGGLE_OVERLAY) {
setIsActive(!isActive);
}
};
useEffect(() => {
chrome.runtime.onMessage.addListener(handleMessages);
return () => {
chrome.runtime.onMessage.removeListener(handleMessages);
};
}, [isActive]);
return (
<>
{showDiv && (
<div
className="overlay top-0 right-0 bg-white backdrop-filter backdrop-blur-lg bg-opacity-70 h-screen overflow-auto shadow-md"
style={isActive ? mountedStyle : unmountedStyle}
>
<App />
</div>
)}
</>
);
};
const root = document.createElement('div');
root.setAttribute('id', 'intro-extension');
document.body.appendChild(root);
ReactDOM.render(<ContentScriptOverlay />, root);
contentScript.css
@tailwind base;
@tailwind components;
@tailwind utilities;
#intro-extension ::-webkit-scrollbar {
width: 0px;
background: transparent;
}
.overlay {
width: 376px;
z-index: 9999;
position: fixed;
border-radius: '6px 0px 0px 6px';
}
@keyframes inAnimation {
0% {
right: -376px;
}
100% {
right: 0;
}
}
@keyframes outAnimation {
0% {
right: 0;
}
100% {
right: -376px;
}
}
我真诚地感谢任何帮助!
解决方案
推荐阅读
- c# - MimeMessage Get Attachment Name
- python - invalid syntax when trying to make a dictionary comprehension?
- google-app-engine - 我可以让 GCS 存储桶仅对特定人员可用(或使用密码)吗
- arrays - 在VBA中访问类对象数组中的浮点数组
- ruta - Ruta,识别模式并返回其中的一部分
- ios - iOS SpringBoard 不加载通知服务扩展
- python - 根据我的代码,多行到单行
- sql-server - 将服务器登录/数据库用户权限降级为 SELECT、查看定义、执行存储过程和使用函数
- python - 在没有外部库的情况下将 IPv6 转换为 long
- flutter - Storing data from form using onSubmitted vs onPressed