hoyocheckin

1.1.0 • Public • Published

HoyoCheckIn

A simple, fast and functional npm package for HoYoLAB check-ins in your project.

Commits License

Key Features

  • Supports Honkai: Star Rail, Genshin Impact and Honkai Impact 3rd.
  • Supports custom user agents, and defaults to a human-browser one if not provided.
  • Small, efficient and functional.

Install

Installing is done via NPM.

npm install hoyocheckin

Usage

[!NOTE] Before continuing, please grab your HoYoLAB token. Specifically, ltoken and ltuid. If you do not have these already, there is a script to get them below. Please also check if your token is v2 or not, as well.

The most simple way to check-in is to not specify an User-Agent at all. It will automatically use a browsers User-Agent.

Please, also check if your token is v2 or not. If it is, you will need to specify that in the checkIn() function. If you do not provide a token version, it will default to v1.

const { checkIn, HoyoGame } = require('hoyocheckin');

const cookie = {
  ltoken: 'YOUR_LTOKEN_VALUE',
  ltuid: 'YOUR_LTUID_VALUE'
};

const game = HoyoGame.StarRail; // You can replace this with Genshin or HKImpact, for those respective games.

try {
    const checkInResult = await checkIn(cookie, game, false); // v2, or not.
    console.log('Check-in successful:', checkInResult);
  } catch (error) {
    console.error('Check-in failed:', error.message);
}

However, if you would still like to use a custom User-Agent, you may do so by simply inputting it in the CheckIn() function.

const userAgent = "Example User-Agent";

const checkInResult = await checkIn(cookie, game, false, userAgent);

You can also find out if the user has already checked in, and respond to them accordingly.

const checkInResult = await checkIn(cookie, game, false);
if (checkInResult.alreadyCheckedIn) {
  console.log(checkInResult.message);
}

HoYoLAB returns a custom message if check-in is already done, so, if you wish you can simply return that output to the user, as I have above.

Just as an FYI, for each game they are:

  • You've already checked in today, Trailblazer~
  • Traveler, you've already checked in today~
  • You have already signed in, Captain~

How do I get my token (v1)?

[!WARNING] This method no longer functions for v2 HoYoLAB tokens. However, some users still have v1 tokens, so try this first. A method for v2 tokens is below.

Here's a script for you to get your token from HoYoLAB. Simply go to HoYoLAB, and hit Option + ⌘ + J on macOS, or Shift + CTRL + J.

After that, you can copy this script, and punch it into the console. It should return your ltuid and your ltoken. Which then, you can use in HoyoCheckIn, or any other programs that utilise it.

var ltoken = '';
var ltuid = '';

if (document.cookie.includes('ltoken') && document.cookie.includes('ltuid')) {
  var cookieArr = document.cookie.split(';');
  for (var i = 0; i < cookieArr.length; i++) {
    var cookie = cookieArr[i].trim();
    if (cookie.startsWith('ltoken')) {
      ltoken = 'ltoken=' + cookie.split('=')[1] + ';';
    } else if (cookie.startsWith('ltuid')) {
      ltuid = 'ltuid=' + cookie.split('=')[1] + ';';
    }
  }
}

if (ltoken && ltuid) {
  var cookie = ltoken + ' ' + ltuid;
  document.write(cookie);
} else {
  alert('Please logout and log back in before trying again. The cookie is currently expired or invalid!');
}

How do I get my token (v2)?

  • Go to HoYoLAB, and navigate to your profile page.
  • Open the developer console using Option + ⌘ + J on macOS, or Shift + CTRL + J, and go to the Network tab.
  • Click on the 'Preserve Log' button, then refresh the page.
  • Click on the getGameRecordCard request where the method is GET (It should be named getGameRecordCard with your HoYoLAB UID).
  • Go to the "Cookies" tab.
  • Copy the ltoken_v2 and ltuid_v2 cookie value.

Demo Screenshot

Contributing

If you have any features or fixes you'd like to contribute, open a PR.

Package Sidebar

Install

npm i hoyocheckin

Weekly Downloads

2

Version

1.1.0

License

MIT

Unpacked Size

701 kB

Total Files

6

Last publish

Collaborators

  • pixlox