Fix Nexus login (#2476)

* Fix Nexus login handler after API keys web page changes

* Automatically press request button

* Automatically press request API key button
This commit is contained in:
trawzified
2024-01-11 06:24:18 +01:00
committed by GitHub
parent 1b3d85af3c
commit 3cdf3c9ed6

View File

@ -45,7 +45,7 @@ public class NexusLoginHandler : BrowserWindowViewModel
Instructions = "Getting API Key...";
await NavigateTo(new Uri("https://www.nexusmods.com/users/myaccount?tab=api"));
await NavigateTo(new Uri("https://next.nexusmods.com/settings/api-keys"));
var key = "";
@ -53,12 +53,7 @@ public class NexusLoginHandler : BrowserWindowViewModel
{
try
{
key = (await GetDom(token))
.DocumentNode
.QuerySelectorAll("input[value=wabbajack]")
.SelectMany(p => p.ParentNode.ParentNode.QuerySelectorAll("textarea.application-key"))
.Select(node => node.InnerHtml)
.FirstOrDefault() ?? "";
key = (await GetDom(token)).DocumentNode.QuerySelectorAll("img[alt='Wabbajack']").SelectMany(p => p.ParentNode.ParentNode.QuerySelectorAll("input[aria-label='api key']")).Select(node => node.Attributes["value"]).FirstOrDefault()?.Value;
}
catch (Exception)
{
@ -71,11 +66,10 @@ public class NexusLoginHandler : BrowserWindowViewModel
try
{
await EvaluateJavaScript(
"var found = document.querySelector(\"input[value=wabbajack]\").parentElement.parentElement.querySelector(\"form button[type=submit]\");" +
"var found = document.querySelector(\"img[alt='Wabbajack']\").parentElement.parentElement.querySelector(\"button[aria-label='Request Api Key']\");" +
"found.onclick= function() {return true;};" +
"found.class = \" \"; " +
"found.click();" +
"found.remove(); found = undefined;"
"found.click();"
);
Instructions = "Generating API Key, Please Wait...";
}