-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex.html
More file actions
163 lines (148 loc) · 5.92 KB
/
Copy pathIndex.html
File metadata and controls
163 lines (148 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>FarClean</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 font-sans">
<!-- Top Bar -->
<header class="flex justify-between items-center bg-white p-4 shadow">
<h1 class="text-xl font-bold text-blue-600">FarClean</h1>
<button id="loginBtn" class="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700">
Login with Farcaster
</button>
</header>
<!-- Main -->
<main class="max-w-3xl mx-auto mt-6 p-4 bg-white shadow rounded-lg">
<h2 class="text-lg font-semibold mb-4">Clean up your followers & following</h2>
<div class="flex space-x-4">
<button id="scanFollowersBtn" disabled class="bg-gray-400 text-white px-4 py-2 rounded-lg cursor-not-allowed">
Scan Followers
</button>
<button id="scanFollowingBtn" disabled class="bg-gray-400 text-white px-4 py-2 rounded-lg cursor-not-allowed">
Scan Following
</button>
</div>
<div id="results" class="mt-6 hidden">
<h3 class="text-md font-bold mb-2" id="resultsTitle"></h3>
<div id="resultsList" class="space-y-2"></div>
</div>
</main>
<script>
const API_KEY = "YOUR_API_KEY_HERE"; // from Neynar dashboard
const CLIENT_ID = "YOUR_CLIENT_ID_HERE"; // from Neynar app setup
let currentUser = null;
// --- Helper: check activity ---
async function checkUserStatus(fid) {
try {
const castResp = await fetch(
`https://api.neynar.com/v2/farcaster/user/casts?fid=${fid}`,
{ headers: { "accept": "application/json", "api_key": API_KEY } }
);
const castData = await castResp.json();
if (!castData.casts || castData.casts.length === 0) {
return "Bot?";
}
let lastCast = new Date(castData.casts[0].timestamp);
let daysAgo = (Date.now() - lastCast) / (1000 * 60 * 60 * 24);
if (daysAgo > 30) return "Inactive";
return "Active";
} catch (e) {
return "Unknown";
}
}
// --- Helper: render results ---
async function renderResults(users, title) {
const resultsDiv = document.getElementById("results");
resultsDiv.classList.remove("hidden");
document.getElementById("resultsTitle").textContent = title;
const listDiv = document.getElementById("resultsList");
listDiv.innerHTML = "<p class='text-gray-500'>Scanning...</p>";
listDiv.innerHTML = "";
for (let user of users.slice(0, 10)) { // limit for demo
let status = await checkUserStatus(user.fid);
listDiv.innerHTML += `
<div class="p-3 border rounded flex justify-between">
<span>@${user.username}</span>
<span class="font-semibold ${status === "Active" ? "text-green-600" : "text-red-600"}">${status}</span>
</div>
`;
}
}
// --- Login with Farcaster (SIWN flow) ---
document.getElementById("loginBtn").addEventListener("click", async () => {
try {
const resp = await fetch("https://api.neynar.com/v2/farcaster/siwn/request", {
method: "POST",
headers: {
"Content-Type": "application/json",
"api_key": API_KEY
},
body: JSON.stringify({
client_id: CLIENT_ID,
redirect_uri: window.location.origin,
scope: "user:read follow:read"
})
});
const data = await resp.json();
if (!data.url) {
alert("Failed to start login");
return;
}
const popup = window.open(data.url, "siwnPopup", "width=500,height=600");
let timer = setInterval(async () => {
if (popup.closed) {
clearInterval(timer);
const sessionResp = await fetch(
`https://api.neynar.com/v2/farcaster/siwn/session/${data.session_id}`,
{ headers: { "api_key": API_KEY } }
);
const sessionData = await sessionResp.json();
if (sessionData.user) {
currentUser = sessionData.user;
document.getElementById("loginBtn").textContent =
"Logged in as @" + currentUser.username;
// Enable both scan buttons
["scanFollowersBtn", "scanFollowingBtn"].forEach(id => {
const btn = document.getElementById(id);
btn.disabled = false;
btn.classList.remove("bg-gray-400", "cursor-not-allowed");
btn.classList.add("bg-blue-600", "hover:bg-blue-700");
});
} else {
alert("Login failed.");
}
}
}, 1000);
} catch (e) {
console.error(e);
alert("Error logging in with Farcaster");
}
});
// --- Scan Followers ---
document.getElementById("scanFollowersBtn").addEventListener("click", async () => {
if (!currentUser) return alert("Please login first");
const resp = await fetch(
`https://api.neynar.com/v2/farcaster/user/followers?fid=${currentUser.fid}`,
{ headers: { "accept": "application/json", "api_key": API_KEY } }
);
const data = await resp.json();
if (!data.users) return alert("Failed to load followers");
await renderResults(data.users, "Followers Scan Results");
});
// --- Scan Following ---
document.getElementById("scanFollowingBtn").addEventListener("click", async () => {
if (!currentUser) return alert("Please login first");
const resp = await fetch(
`https://api.neynar.com/v2/farcaster/user/following?fid=${currentUser.fid}`,
{ headers: { "accept": "application/json", "api_key": API_KEY } }
);
const data = await resp.json();
if (!data.users) return alert("Failed to load following");
await renderResults(data.users, "Following Scan Results");
});
</script>
</body>
</html>