mirror of
https://github.com/aljazceru/njump.git
synced 2026-01-31 03:34:37 +01:00
Move clients filtering by platform client side
This commit is contained in:
142
clients.go
142
clients.go
@@ -7,104 +7,84 @@ import (
|
||||
)
|
||||
|
||||
type ClientReference struct {
|
||||
ID string
|
||||
Name string
|
||||
URL template.URL
|
||||
Type string
|
||||
ID string
|
||||
Name string
|
||||
URL template.URL
|
||||
Platform string
|
||||
}
|
||||
|
||||
func generateClientList(style Style, code string, event *nostr.Event) []ClientReference {
|
||||
clients := []ClientReference{
|
||||
{ID: "native", Name: "Your default app", URL: template.URL("nostr:" + code), Type: "app"},
|
||||
{ID: "native", Name: "Your default app", URL: template.URL("nostr:" + code), Platform: "native"},
|
||||
}
|
||||
|
||||
webClients_1_6 := []ClientReference{
|
||||
{ID: "snort", Name: "Snort", URL: template.URL("https://Snort.social/e/" + code), Type: "web"},
|
||||
{ID: "nostrudel", Name: "Nostrudel", URL: template.URL("https://nostrudel.ninja/#/n/" + code), Type: "web"},
|
||||
{ID: "satellite", Name: "Satellite", URL: template.URL("https://satellite.earth/thread/" + event.ID), Type: "web"},
|
||||
{ID: "coracle", Name: "Coracle", URL: template.URL("https://coracle.social/" + code), Type: "web"},
|
||||
{ID: "primal", Name: "Primal", URL: template.URL("https://primal.net/thread/" + event.ID), Type: "web"},
|
||||
{ID: "nostter", Name: "Nostter", URL: template.URL("https://nostter.vercel.app/" + code), Type: "web"},
|
||||
{ID: "highlighter", Name: "Highlighter", URL: template.URL("https://highlighter.com/a/" + code), Type: "web"},
|
||||
{ID: "iris", Name: "Iris", URL: template.URL("https://iris.to/" + code), Type: "web"},
|
||||
{ID: "snort", Name: "Snort", URL: template.URL("https://Snort.social/e/" + code), Platform: "web"},
|
||||
{ID: "nostrudel", Name: "Nostrudel", URL: template.URL("https://nostrudel.ninja/#/n/" + code), Platform: "web"},
|
||||
{ID: "satellite", Name: "Satellite", URL: template.URL("https://satellite.earth/thread/" + event.ID), Platform: "web"},
|
||||
{ID: "coracle", Name: "Coracle", URL: template.URL("https://coracle.social/" + code), Platform: "web"},
|
||||
{ID: "primal", Name: "Primal", URL: template.URL("https://primal.net/thread/" + event.ID), Platform: "web"},
|
||||
{ID: "nostter", Name: "Nostter", URL: template.URL("https://nostter.vercel.app/" + code), Platform: "web"},
|
||||
{ID: "highlighter", Name: "Highlighter", URL: template.URL("https://highlighter.com/a/" + code), Platform: "web"},
|
||||
{ID: "iris", Name: "Iris", URL: template.URL("https://iris.to/" + code), Platform: "web"},
|
||||
}
|
||||
|
||||
webClients_0 := []ClientReference{
|
||||
{ID: "nosta", Name: "Nosta", URL: template.URL("https://nosta.me/" + code), Type: "web"},
|
||||
{ID: "snort", Name: "Snort", URL: template.URL("https://snort.social/p/" + code), Type: "web"},
|
||||
{ID: "satellite", Name: "Satellite", URL: template.URL("https://satellite.earth/@" + code), Type: "web"},
|
||||
{ID: "coracle", Name: "Coracle", URL: template.URL("https://coracle.social/" + code), Type: "web"},
|
||||
{ID: "primal", Name: "Primal", URL: template.URL("https://primal.net/profile/" + event.PubKey), Type: "web"},
|
||||
{ID: "nostrudel", Name: "Nostrudel", URL: template.URL("https://nostrudel.ninja/#/u/" + code), Type: "web"},
|
||||
{ID: "nostter", Name: "Nostter", URL: template.URL("https://nostter.vercel.app/" + code), Type: "web"},
|
||||
{ID: "iris", Name: "Iris", URL: template.URL("https://iris.to/" + code), Type: "web"},
|
||||
{ID: "nosta", Name: "Nosta", URL: template.URL("https://nosta.me/" + code), Platform: "web"},
|
||||
{ID: "snort", Name: "Snort", URL: template.URL("https://snort.social/p/" + code), Platform: "web"},
|
||||
{ID: "satellite", Name: "Satellite", URL: template.URL("https://satellite.earth/@" + code), Platform: "web"},
|
||||
{ID: "coracle", Name: "Coracle", URL: template.URL("https://coracle.social/" + code), Platform: "web"},
|
||||
{ID: "primal", Name: "Primal", URL: template.URL("https://primal.net/profile/" + event.PubKey), Platform: "web"},
|
||||
{ID: "nostrudel", Name: "Nostrudel", URL: template.URL("https://nostrudel.ninja/#/u/" + code), Platform: "web"},
|
||||
{ID: "nostter", Name: "Nostter", URL: template.URL("https://nostter.vercel.app/" + code), Platform: "web"},
|
||||
{ID: "iris", Name: "Iris", URL: template.URL("https://iris.to/" + code), Platform: "web"},
|
||||
}
|
||||
|
||||
webClients_30024 := []ClientReference{
|
||||
{ID: "yakihonne", Name: "YakiHonne", URL: template.URL("https://yakihonne.com/article/" + code), Type: "web"},
|
||||
{ID: "habla", Name: "Habla", URL: template.URL("https://habla.news/a/" + code), Type: "web"},
|
||||
{ID: "highlighter", Name: "Highlighter", URL: template.URL("https://highlighter.com/a/" + code), Type: "web"},
|
||||
{ID: "blogstack", Name: "Blogstack", URL: template.URL("https://blogstack.io/" + code), Type: "web"},
|
||||
{ID: "yakihonne", Name: "YakiHonne", URL: template.URL("https://yakihonne.com/article/" + code), Platform: "web"},
|
||||
{ID: "habla", Name: "Habla", URL: template.URL("https://habla.news/a/" + code), Platform: "web"},
|
||||
{ID: "highlighter", Name: "Highlighter", URL: template.URL("https://highlighter.com/a/" + code), Platform: "web"},
|
||||
{ID: "blogstack", Name: "Blogstack", URL: template.URL("https://blogstack.io/" + code), Platform: "web"},
|
||||
}
|
||||
|
||||
webClients_1063 := []ClientReference{
|
||||
{ID: "native", Name: "your native client", URL: template.URL("nostr:" + code), Type: "web"},
|
||||
{ID: "snort", Name: "Snort", URL: template.URL("https://snort.social/p/" + code), Type: "web"},
|
||||
{ID: "coracle", Name: "Coracle", URL: template.URL("https://coracle.social/" + code), Type: "web"},
|
||||
{ID: "native", Name: "your native client", URL: template.URL("nostr:" + code), Platform: "web"},
|
||||
{ID: "snort", Name: "Snort", URL: template.URL("https://snort.social/p/" + code), Platform: "web"},
|
||||
{ID: "coracle", Name: "Coracle", URL: template.URL("https://coracle.social/" + code), Platform: "web"},
|
||||
}
|
||||
|
||||
switch style {
|
||||
case StyleIOS:
|
||||
clients = append(clients, []ClientReference{
|
||||
{ID: "nos", Name: "Nos", URL: template.URL("nos:" + code), Type: "app"},
|
||||
{ID: "damus", Name: "Damus", URL: template.URL("damus:" + code), Type: "app"},
|
||||
{ID: "nostur", Name: "Nostur", URL: template.URL("nostur:" + code), Type: "app"},
|
||||
{ID: "primal", Name: "Primal", URL: template.URL("primal:" + code), Type: "app"},
|
||||
}...)
|
||||
if event.Kind == 1 || event.Kind == 6 {
|
||||
clients = append(clients, webClients_1_6...)
|
||||
} else if event.Kind == 0 {
|
||||
clients = append(clients, webClients_0...)
|
||||
} else if event.Kind == 30023 || event.Kind == 30024 {
|
||||
clients = append(clients, webClients_30024...)
|
||||
} else if event.Kind == 1063 {
|
||||
clients = append(clients, webClients_1063...)
|
||||
}
|
||||
case StyleAndroid:
|
||||
clients = append(clients, []ClientReference{
|
||||
{ID: "nostrmo", Name: "Nostrmo", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=com.github.haorendashu.nostrmo;end`;"), Type: "app"},
|
||||
{ID: "amethyst", Name: "Amethyst", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=com.vitorpamplona.amethyst;end`;"), Type: "app"},
|
||||
{ID: "yana", Name: "Yana", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=yana.nostr;end`;"), Type: "app"},
|
||||
{ID: "spring", Name: "Spring", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=com.nostr.universe;end`;"), Type: "app"},
|
||||
{ID: "snort-app", Name: "Snort", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=social.snort.app;end`;"), Type: "app"},
|
||||
{ID: "freefrom", Name: "FreeFrom", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=com.freefrom;end`;"), Type: "app"},
|
||||
{ID: "current", Name: "Current", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=io.getcurrent.current;end`;"), Type: "app"},
|
||||
{ID: "plebstr", Name: "Plebstr", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=com.plebstr.client;end`;"), Type: "app"},
|
||||
{ID: "nozzle", Name: "Nozzle", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=com.dluvian.nozzle;end`;"), Type: "app"},
|
||||
{ID: "plasma", Name: "Plasma", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=social.plasma;end`;"), Type: "app"},
|
||||
// {ID: "", Name: "", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=;end`;"), Type: "app"},
|
||||
}...)
|
||||
if event.Kind == 1 || event.Kind == 6 {
|
||||
clients = append(clients, webClients_1_6...)
|
||||
} else if event.Kind == 0 {
|
||||
clients = append(clients, webClients_0...)
|
||||
} else if event.Kind == 30023 || event.Kind == 30024 {
|
||||
clients = append(clients, webClients_30024...)
|
||||
} else if event.Kind == 1063 {
|
||||
clients = append(clients, webClients_1063...)
|
||||
}
|
||||
default:
|
||||
if event.Kind == 1 || event.Kind == 6 {
|
||||
clients = append(clients, webClients_1_6...)
|
||||
} else if event.Kind == 0 {
|
||||
clients = append(clients, webClients_0...)
|
||||
} else if event.Kind == 30023 || event.Kind == 30024 {
|
||||
clients = append(clients, webClients_30024...)
|
||||
} else if event.Kind == 1063 {
|
||||
clients = append(clients, webClients_1063...)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
androidClients := []ClientReference{
|
||||
{ID: "nostrmo", Name: "Nostrmo", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=com.github.haorendashu.nostrmo;end`;"), Platform: "android"},
|
||||
{ID: "amethyst", Name: "Amethyst", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=com.vitorpamplona.amethyst;end`;"), Platform: "android"},
|
||||
{ID: "yana", Name: "Yana", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=yana.nostr;end`;"), Platform: "android"},
|
||||
{ID: "spring", Name: "Spring", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=com.nostr.universe;end`;"), Platform: "android"},
|
||||
{ID: "snort-android", Name: "Snort", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=social.snort.android;end`;"), Platform: "android"},
|
||||
{ID: "freefrom", Name: "FreeFrom", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=com.freefrom;end`;"), Platform: "android"},
|
||||
{ID: "current", Name: "Current", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=io.getcurrent.current;end`;"), Platform: "android"},
|
||||
{ID: "plebstr", Name: "Plebstr", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=com.plebstr.client;end`;"), Platform: "android"},
|
||||
{ID: "nozzle", Name: "Nozzle", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=com.dluvian.nozzle;end`;"), Platform: "android"},
|
||||
{ID: "plasma", Name: "Plasma", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=social.plasma;end`;"), Platform: "android"},
|
||||
// {ID: "", Name: "", URL: template.URL("intent:" + code + "#Intent;scheme=nostr;package=;end`;"), Platform: "app"},
|
||||
}
|
||||
|
||||
iosClients := []ClientReference{
|
||||
{ID: "nos", Name: "Nos", URL: template.URL("nos:" + code), Platform: "ios"},
|
||||
{ID: "damus", Name: "Damus", URL: template.URL("damus:" + code), Platform: "ios"},
|
||||
{ID: "nostur", Name: "Nostur", URL: template.URL("nostur:" + code), Platform: "ios"},
|
||||
{ID: "primal", Name: "Primal", URL: template.URL("primal:" + code), Platform: "ios"},
|
||||
}
|
||||
|
||||
clients = append(clients, androidClients...)
|
||||
clients = append(clients, iosClients...)
|
||||
|
||||
if event.Kind == 1 || event.Kind == 6 {
|
||||
clients = append(clients, webClients_1_6...)
|
||||
} else if event.Kind == 0 {
|
||||
clients = append(clients, webClients_0...)
|
||||
} else if event.Kind == 30023 || event.Kind == 30024 {
|
||||
clients = append(clients, webClients_30024...)
|
||||
} else if event.Kind == 1063 {
|
||||
clients = append(clients, webClients_1063...)
|
||||
}
|
||||
|
||||
return clients
|
||||
@@ -112,6 +92,6 @@ func generateClientList(style Style, code string, event *nostr.Event) []ClientRe
|
||||
|
||||
func generateRelayBrowserClientList(host string) []ClientReference {
|
||||
return []ClientReference{
|
||||
{ID: "coracle", Name: "Coracle", URL: template.URL("https://coracle.social/relays/" + host), Type: "web"},
|
||||
{ID: "coracle", Name: "Coracle", URL: template.URL("https://coracle.social/relays/" + host), Platform: "web"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
_="on load
|
||||
wait 50ms
|
||||
get my children
|
||||
get sortByCount(it) then repeat for c in it call me.appendChild(c) end
|
||||
get filterAndSort(it) then repeat for c in it call me.appendChild(c) end
|
||||
get first in me
|
||||
then tell it
|
||||
remove .hidden
|
||||
@@ -64,6 +64,7 @@
|
||||
>
|
||||
{{range $index, $client := .Clients}}
|
||||
<div
|
||||
data-platform="{{$client.Platform}}"
|
||||
class="client | hidden w-full items-center border-b border-zinc-800 bg-zinc-700 first-of-type:rounded-t-lg first-of-type:border-0 first-of-type:bg-strongpink hover:bg-zinc-800 sm:mb-3 sm:flex sm:rounded-lg sm:border-0 sm:first-of-type:rounded-lg"
|
||||
_="on load get localStorage['nj:{{.ID}}'] or 0 then set @count to it then set @title to `used ${it} times`
|
||||
on click increment localStorage['nj:{{$client.ID}}']"
|
||||
@@ -79,16 +80,16 @@
|
||||
{{$client.Name}}
|
||||
<span
|
||||
class="type | float-right mr-4 text-xs uppercase text-neutral-400 sm:hidden"
|
||||
>{{$client.Type}}</span
|
||||
>{{$client.Platform}}</span
|
||||
>
|
||||
</a>
|
||||
</div>
|
||||
{{end}}
|
||||
<div class="client | hidden h-8 bg-zinc-700"></div>
|
||||
<div data-platform="dummy" class="client | hidden h-8 bg-zinc-700" ></div>
|
||||
</div>
|
||||
<div
|
||||
id="gradient"
|
||||
class="fixed bottom-0 hidden h-16 w-full bg-gradient-to-t from-zinc-800 to-transparent"
|
||||
class="fixed bottom-0 hidden h-10 w-full bg-gradient-to-t from-zinc-800 to-transparent pointer-events-auto"
|
||||
></div>
|
||||
</aside>
|
||||
|
||||
@@ -110,10 +111,46 @@
|
||||
</style>
|
||||
|
||||
<script>
|
||||
function sortByCount(children) {
|
||||
return Array.from(children).sort(
|
||||
(a, b) =>
|
||||
parseInt(b.getAttribute('count')) - parseInt(a.getAttribute('count'))
|
||||
)
|
||||
function getPlatform() {
|
||||
const userAgent = navigator.userAgent || navigator.vendor || window.opera;
|
||||
|
||||
if (/android/i.test(userAgent)) {
|
||||
return 'android';
|
||||
} else if (/iPad|iPhone|iPod/i.test(userAgent) && !window.MSStream) {
|
||||
return 'ios';
|
||||
} else {
|
||||
return 'web';
|
||||
}
|
||||
}
|
||||
|
||||
function filterAndSort(children) {
|
||||
const platform = getPlatform();
|
||||
|
||||
const filteredElements = Array.from(children).filter((element) => {
|
||||
const platformAttr = element.getAttribute('data-platform');
|
||||
return platform === platformAttr || platformAttr === 'web' || platformAttr === 'native' || platformAttr === 'dummy';
|
||||
});
|
||||
|
||||
Array.from(children).forEach((element) => {
|
||||
if (!filteredElements.includes(element)) {
|
||||
element.remove();
|
||||
}
|
||||
});
|
||||
|
||||
const sortedElements = filteredElements.sort(
|
||||
(a, b) =>
|
||||
parseInt(b.getAttribute('count')) - parseInt(a.getAttribute('count'))
|
||||
);
|
||||
|
||||
// Assuming you want to re-insert the sorted elements into their parent container
|
||||
const parent = children[0].parentNode;
|
||||
parent.innerHTML = ''; // Clear the parent container
|
||||
sortedElements.forEach((element) => {
|
||||
parent.appendChild(element);
|
||||
});
|
||||
|
||||
return sortedElements;
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user