Instagram Dark Theme

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

< Rückmeldungen auf Instagram Dark Theme

Rezension: Gut - Skript funktioniert

§
Veröffentlicht: 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

drakewildVerfasser
§
Veröffentlicht: 04.07.2022

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

§
Veröffentlicht: 04.07.2022
Bearbeitet: 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);
    }
§
Veröffentlicht: 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.

drakewildVerfasser
§
Veröffentlicht: 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!

Antwort schreiben

Anmelden um eine Antwort zu senden.