Don't want to miss out on free stuff but too lazy to do it by hand? This is what this script helps to solve. Works for Genshin, Honkai: Star Rail, and Zenless Zone Zero.
-
Create a Google Apps Script and copy the code from Code.gs into it. Then for each account and game do steps 2 to 7 to setup your account info.
-
Open a redeem code page in your browser.
-
Login to your account.
-
Open the developer menu by hitting F12 and go to the network tab.
-
Enter anything in the code and click the button. A request should appear.
-
Click on the GET webExchangeCdkey request., and copy over to the right game URL in the script the
region,game_bizanduidparameters. -- or directly copy the URL and you'll replace that, at your own risk if there are more parameters (it needs lang to work too).
-
Then, scroll down into the Request Headers section and copy the part of the cookie that includes
cookie_token_v2,account_mid_v2andaccount_id_v2.
-
In the Google apps script, on the left sidebar go into "Project Settings", and in the bottom add/edit a property named
COOKIEand paste what you just copied in and click save. If you have multiple accounts, you can save different cookies by providing a property per account you are using. For example if you named your profiles "main" and "2nd", you can provide the properties "COOKIE_main" and "COOKIE_2nd" to have the script use these for the configured profile. -
Set
DISCORD_IDandWEBHOOK_URLproperties also, so that it notifies you when it uses a new code or when you need to copy a new cookie. If you don't want to be pinged, leaveDISCORD_IDblank.
First, run it by choosing first_main in the top bar and running. Then, you will to set a trigger for it to run periodically.
In the left sidebar, go to "Triggers", then click "Add Trigger". The function to run should be main, and I recommend to make the source Time-driven, triggering at Day timer and a random time of day. Then click save and it's finished.

If you have problems, I am available for help in on discord @Kynatosh on the Stardb Discord Server: https://discord.gg/chives.
- https://github.com/canaria3406/hoyolab-auto-sign for inspiration
- @Minigamer42 on the StarDB Discord Server for the idea