sfc-utils 1.4.171 → 1.4.173
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/accountswap.js +42 -54
- package/package.json +1 -1
package/accountswap.js
CHANGED
|
@@ -2,76 +2,64 @@
|
|
|
2
2
|
// Any domain + /realm/ should work for an account link
|
|
3
3
|
const accountURL = "/realm/";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
// Start the iterator
|
|
14
|
-
if (!i) {
|
|
15
|
-
i = 0;
|
|
16
|
-
}
|
|
17
|
-
// Add a click event to signin
|
|
18
|
-
if (isNav && !attachedRealm) {
|
|
5
|
+
// Attach the sign-in handler to the .hnp-signin button if not already attached
|
|
6
|
+
const attachSigninHandler = async function () {
|
|
7
|
+
let attachedRealm = false;
|
|
8
|
+
let tries = 0;
|
|
9
|
+
const maxTries = 20; // 20 * 500ms = 10 seconds
|
|
10
|
+
while (!attachedRealm && tries < maxTries) {
|
|
11
|
+
tries++;
|
|
19
12
|
const signinButton = document.querySelector(".hnp-signin");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
console.log("Found signin button");
|
|
23
|
-
// Add event listener to signin button
|
|
24
|
-
attachedRealm = true;
|
|
13
|
+
if (signinButton && !signinButton.dataset.realmAttached) {
|
|
14
|
+
signinButton.dataset.realmAttached = "true";
|
|
25
15
|
signinButton.onclick = function (e) {
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
if (window?.treg?.realm?.core) {
|
|
17
|
+
window.treg.realm.core.login();
|
|
18
|
+
}
|
|
28
19
|
e.preventDefault();
|
|
29
20
|
e.stopPropagation();
|
|
30
21
|
};
|
|
22
|
+
attachedRealm = true;
|
|
31
23
|
} else {
|
|
32
|
-
|
|
24
|
+
// Wait and try again
|
|
25
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
33
26
|
}
|
|
34
27
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Swap the Subscribe button for the Account button if logged in
|
|
31
|
+
const swapSubscribeForAccount = async function () {
|
|
32
|
+
let swapped = false;
|
|
33
|
+
let tries = 0;
|
|
34
|
+
const maxTries = 20; // 20 * 500ms = 10 seconds
|
|
35
|
+
while (!swapped && tries < maxTries) {
|
|
36
|
+
tries++;
|
|
37
|
+
if (window?.treg?.identity?.id) {
|
|
44
38
|
const rightBlock = document.querySelector(".nav2-right");
|
|
45
|
-
if (rightBlock) {
|
|
46
|
-
if (!rightBlock.innerText) {
|
|
47
|
-
// If there's no innerText, keep waiting
|
|
48
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
49
|
-
return await pollForAccount(i + 1, isNav);
|
|
50
|
-
}
|
|
51
|
-
// Change the inner HTML
|
|
39
|
+
if (rightBlock && rightBlock.innerText) {
|
|
52
40
|
rightBlock.innerHTML = `<a id="nav2-sub-box" href="${accountURL}"><div>Account</div></a>`;
|
|
53
|
-
|
|
54
|
-
if (window.treg.realm.iframeProfile) {
|
|
55
|
-
// Find the newly swapped button
|
|
41
|
+
if (window?.treg?.realm?.iframeProfile) {
|
|
56
42
|
const subButton = document.querySelector("#nav2-sub-box");
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
43
|
+
if (subButton) {
|
|
44
|
+
subButton.onclick = function (e) {
|
|
45
|
+
window.treg.realm.iframeProfile.NavigateToIndex();
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
e.stopPropagation();
|
|
48
|
+
};
|
|
49
|
+
swapped = true;
|
|
50
|
+
}
|
|
62
51
|
}
|
|
63
52
|
}
|
|
64
53
|
}
|
|
65
|
-
return true;
|
|
66
|
-
} else {
|
|
67
|
-
if (i > 10) {
|
|
68
|
-
// If we've waited 5 seconds and there's still no entitlement, assume we aren't getting one
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
// Check again after 0.5 sec using a Promise with async/await
|
|
72
54
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
73
|
-
return await pollForAccount(i + 1, isNav, attachedRealm);
|
|
74
55
|
}
|
|
75
56
|
};
|
|
76
57
|
|
|
58
|
+
// Launch both processes
|
|
59
|
+
const pollForAccount = async function () {
|
|
60
|
+
// Launch both async processes, but don't wait for them to finish (they are self-terminating)
|
|
61
|
+
attachSigninHandler();
|
|
62
|
+
swapSubscribeForAccount();
|
|
63
|
+
};
|
|
64
|
+
|
|
77
65
|
module.exports = { pollForAccount };
|