使用CSS构建用于移动浏览器的棕褐色主题

发布于 2025-02-09 04:56:04 字数 1216 浏览 1 评论 0 原文

我正在建立一个 ios Safari扩展,它颠倒了不同的主题(灰色,黑暗和棕褐色)。灰色和深色效果很好,但是它对棕褐色的预期无法正常工作。它不仅改变了背景的颜色,还会改变页面内容的内容。 这是带有问题的图像,我希望它不倒入页面内容,这是目标图像

,这是我注入页面的CSS文件。

/* sepia.css */

body {
    background-color: rgb(246, 240, 229) !important;
    filter: sepia(1) !important;
}
/*dark.css*/

body {
    background-color: rgb(0, 0, 0) !important;
    filter: invert(1.0) hue-rotate(165deg) !important;
}

img,
video {
    filter: invert(1.0) hue-rotate(-165deg) !important;
}
/*gray.css*/

body {
    background-color: rgb(75, 75, 75) !important;
    filter: invert(0.85) hue-rotate(165deg) !important;
}

img,
video {
    filter: invert(0.85) hue-rotate(-165deg) !important;
}

这是我用来发送(注入)CSS文件到网站的JavaScript代码。

//popup.js

insertCSS("sepia.css");

function insertCSS(file) {
    return new Promise((resolve, reject) => {
        browser.tabs.insertCSS({ file }).then(resolve, reject);
    });
}

I am building an iOS Safari extension that inverts to different themes (Gray, Dark, and Sepia). Gray and Dark work well, but it doesn't work as expected for the Sepia one. It change colors of not only the background, but also the content of the page.
Here's the image with the issue, I want it not to invert the page content, and Here's the target image

And this is my css files I inject to the page.

/* sepia.css */

body {
    background-color: rgb(246, 240, 229) !important;
    filter: sepia(1) !important;
}
/*dark.css*/

body {
    background-color: rgb(0, 0, 0) !important;
    filter: invert(1.0) hue-rotate(165deg) !important;
}

img,
video {
    filter: invert(1.0) hue-rotate(-165deg) !important;
}
/*gray.css*/

body {
    background-color: rgb(75, 75, 75) !important;
    filter: invert(0.85) hue-rotate(165deg) !important;
}

img,
video {
    filter: invert(0.85) hue-rotate(-165deg) !important;
}

And this is the javascript code I use to send (inject) the css file to the website.

//popup.js

insertCSS("sepia.css");

function insertCSS(file) {
    return new Promise((resolve, reject) => {
        browser.tabs.insertCSS({ file }).then(resolve, reject);
    });
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文