Greasy Fork is available in English.

Instagram Dark Theme

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

< Instagram Dark Themeについてのフィードバック

レート:良 – スクリプトは良好に動作する

§
投稿日: 2022/07/03

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

drakewild作者
§
投稿日: 2022/07/04

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

§
投稿日: 2022/07/04
編集日: 2022/07/04

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);
    }
§
投稿日: 2022/07/05

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.

drakewild作者
§
投稿日: 2022/07/05

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!

返信を投稿

返信を投稿するにはログインしてください。