DEV Community

usama fouad
usama fouad

Posted on

4 4

Building sepia theme for mobile browser using CSS

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:
Here's the image with the issue
I want it not to invert the page content, and Here's the target image
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;
}
Enter fullscreen mode Exit fullscreen mode
/*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;
}
Enter fullscreen mode Exit fullscreen mode
/*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;
}
Enter fullscreen mode Exit fullscreen mode

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);
    });
}
Enter fullscreen mode Exit fullscreen mode

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay