1const startUrl = "https://x.com/";
2const homeUrl = "https://x.com/home";
3const profileUrl = "https://x.com/{{twitter_username}}";
4
5//Click Sign-in by Google button to trigger google init script and prepare it for user clicking
6function clickGoogleAuthButtonIfPresent() {
7 const googleAuthButton = document.querySelector(
8 '[data-testid*="google_placeholder_button"]',
9 );
10 if (googleAuthButton !== null) {
11 googleAuthButton.click();
12 }
13}
14
15function checkIsFollowing() {
16 if (!isFollowing()) {
17 if (typeof displayInstruction === "function") {
18 displayInstruction({
19 message: `Hit the "Follow" button on the profile to continue`,
20 imageUrl: "https://app.getvouch.io/follow_instruction.png",
21 });
22 } else {
23 alert(`Hit the "Follow" button on the profile to continue`);
24 }
25 awaitFollowChange();
26 }
27}
28
29function isFollowing() {
30 const element = document.querySelector('[data-testid*="unfollow"]');
31 return element !== null;
32}
33
34function awaitFollowChange() {
35 setInterval(() => {
36 if (isFollowing()) {
37 window.location.reload();
38 }
39 }, 1000);
40}
41
42window.onload = function () {
43 setTimeout(clickGoogleAuthButtonIfPresent, 100);
44
45 console.log(
46 "JavaScriptNavigator: selecting action for " + window.location.href,
47 );
48 switch (window.location.href) {
49 case startUrl:
50 setInterval(() => {
51 if (window.location.href === homeUrl) {
52 window.location.href = profileUrl;
53 }
54 }, 1000);
55 break;
56 case homeUrl:
57 window.location.href = profileUrl;
58 break;
59 case profileUrl:
60 setTimeout(checkIsFollowing, 1200);
61 break;
62 default:
63 break;
64 }
65};
66