Instagram Dark Theme

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

< Feedback on Instagram Dark Theme

Değerlendirme: İyi - script çalışıyor

§
Gönderildi: 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

drakewildSahip
§
Gönderildi: 04.07.2022

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

§
Gönderildi: 04.07.2022
Düzenlendi: 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);
    }
§
Gönderildi: 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.

drakewildSahip
§
Gönderildi: 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!

Cevap paylaş

Yanıt göndermek için oturum açın.