Instagram Dark Theme

Redirects to /?theme=dark which is an official dark theme for instagram

< Feedback on Instagram Dark Theme

Review: Good - script works

§
Posted: 03-07-2022

This does not work when the URL already has query parameters like with https://www.instagram.com/?hl=en You should probably make use of URLSearchParams

drakewildTác giả
§
Posted: 04-07-2022

Thanks for your reply! I used URLSearchParams as you suggested.

§
Posted: 04-07-2022
Edited: 04-07-2022

Good approach but now it duplicates the params because they are already included in your url variable. Just test it with the URL I provided earlier.

And you can just use url.searchParams btw.

Example code

    const url = new URL(window.location.href);
    const { searchParams } = url;
    if (!searchParams.get("theme")) {
        searchParams.append("theme", "dark");
        window.location.replace(url);
    }
§
Posted: 05-07-2022

Now it works, but I don't understand why you're doing the replacement so complicated. See the code I provided, it works like this too.

drakewildTác giả
§
Posted: 05-07-2022

I must've done something wrong earlier cause window.location.replace(url) didn't work for me at first, but now it works just fine. It's definitely cleaner, thanks for your advices!

Post reply

Đăng nhập để bình luận