-
Notifications
You must be signed in to change notification settings - Fork 1
/
nosgraph.html
126 lines (109 loc) · 3.17 KB
/
nosgraph.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Nosgraph Recommendation</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
background-color: #f5f5f5;
color: #333;
}
h1 {
font-size: 2em;
color: #333;
}
#pubkey {
padding: 10px;
border: none;
border-radius: 5px;
width: 70%;
margin-right: 10px;
}
button {
padding: 10px 20px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: #fff;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
.recommendation {
margin: 20px 0;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: #fff;
}
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>Nosgraph Recommendation</h1>
<div>
<input
type="text"
id="pubkey"
name="pubkey"
placeholder="Enter a public key"
/>
<button onclick="getRecommendations()">Get Recommendations</button>
</div>
<div id="results"></div>
<script>
async function getRecommendations() {
const pubkey = document.getElementById('pubkey').value
const data = await fetchPublicKey(pubkey)
const followers = data.mainEntity.following.map(f =>
f.replace('nostr:pubkey:', '')
)
const recommendations = await fetchRecommendations(pubkey, followers)
displayRecommendations(recommendations)
}
async function fetchPublicKey(pubkey) {
const url = `https://nostr.social/.well-known/nostr/pubkey/${pubkey}/index.json`
const response = await fetch(url)
return await response.json()
}
async function fetchRecommendations(pubkey, followers) {
const recommendationUrl = `https://api.semisol.dev/nosgraph/v1/recommend`
const recommendationResponse = await fetch(recommendationUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
pubkey: pubkey,
following: followers,
exclude: []
})
})
return await recommendationResponse.json()
}
function displayRecommendations(recommendationData) {
const resultsElement = document.getElementById('results')
resultsElement.innerHTML = ''
recommendationData.recommendations.forEach(([recPubkey]) => {
const recElement = document.createElement('div')
recElement.classList.add('recommendation')
const linkElement = document.createElement('a')
linkElement.href = `https://nostr.social/${recPubkey}`
linkElement.textContent = recPubkey
linkElement.target = '_blank'
recElement.appendChild(linkElement)
resultsElement.appendChild(recElement)
})
}
</script>
</body>
</html>