From 012bf1d77d9fdbf9e8889244d2a2c9496c378e70 Mon Sep 17 00:00:00 2001 From: zhxy-CN Date: Sat, 6 Aug 2022 12:46:52 +0800 Subject: [PATCH] Create the script --- GetGenshinWishLink.ps1 | 40 ++++++++++++++++++++++++++++++++++++++++ README.md | 9 +++++++++ 2 files changed, 49 insertions(+) create mode 100644 GetGenshinWishLink.ps1 diff --git a/GetGenshinWishLink.ps1 b/GetGenshinWishLink.ps1 new file mode 100644 index 0000000..07e6d5e --- /dev/null +++ b/GetGenshinWishLink.ps1 @@ -0,0 +1,40 @@ +$logLocationCN = "%userprofile%\AppData\LocalLow\miHoYo\$([char]0x539f)$([char]0x795e)\output_log.txt"; +$logLocationGlobal = "%userprofile%\AppData\LocalLow\miHoYo\Genshin Impact\output_log.txt"; + +$pathCN = [System.Environment]::ExpandEnvironmentVariables($logLocationCN); +$pathGlobal = [System.Environment]::ExpandEnvironmentVariables($logLocationGlobal); +$findCN = [System.IO.File]::Exists($pathCN); +$findGlobal = [System.IO.File]::Exists($pathGlobal); + +if ($findCN -And $findGlobal) { + Write-Host "Find both China and Global log file. Please choose one. Press [1] for CN, [2] for Global." -ForegroundColor Yellow + $keyInput = [Console]::ReadKey($true).Key + if ($keyInput -eq "NumPad1" -or $keyInput -eq "D1") { + $path = $pathCN + } elseif ($keyInput -eq "NumPad2" -or $keyInput -eq "D2") { + $path = $pathGlobal + } else { + Write-Host "Invalid input." -ForegroundColor Red + break + } +} elseif ($findCN) { + $path = $pathCN +} elseif ($findGlobal) { + $path = $pathGlobal +} else { + Write-Host "Cannot find the log file. Make sure to open the wish history first." -ForegroundColor Red + break +} + +$logs = Get-Content -Path $path +$match = $logs -match "^OnGetWebViewPageFinish.*log$" + +if (-Not $match) { + Write-Host "Cannot find the wish history url. Make sure to open the wish history first." -ForegroundColor Red + return +} + +[string] $wishHistoryUrl = $match[$match.Length - 1] -replace 'OnGetWebViewPageFinish:', '' +Write-Host $wishHistoryUrl +Set-Clipboard -Value $wishHistoryUrl +Write-Host "Link copied to clipboard." -ForegroundColor Green diff --git a/README.md b/README.md index 07ff163..78e64ee 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ # GetGenshinWishLink A script for getting Genshin Impact wish links on Windows. + +## How to use +Open Windows PowerShell and run any one of the following commands. +``` +iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/zhxycn/GetGenshinWishLink/main/GetGenshinWishLink.ps1')) +``` +``` +iex ((New-Object System.Net.WebClient).DownloadString('https://cdn.jsdelivr.net/gh/zhxycn/GetGenshinWishLink/GetGenshinWishLink.ps1')) +```