Skip to content

Commit a688533

Browse files
committed
fix: update P2P detection to support Peersky and Agregore browsers
1 parent 97a8079 commit a688533

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/pages/p2p/wiki/script.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,21 @@ const searchForm = document.getElementById("searchForm");
44
const errorMessage = document.getElementById("errorMessage");
55
let debounceTimeout;
66

7-
/**
8-
* Detect if the browser supports the 'ipns://' protocol.
9-
* We do this by assigning a test URL to a hidden <a> element and checking its .protocol.
10-
*/
11-
function supportsIpnsProtocol() {
12-
const testLink = document.createElement("a");
13-
testLink.href = "ipns://test";
14-
return testLink.protocol === "ipns:";
7+
function isP2PEnvironment() {
8+
const protocol = window.location.protocol;
9+
const isIpfs = protocol.startsWith("ipfs") || protocol.startsWith("ipns");
10+
const ua = navigator.userAgent.toLowerCase();
11+
const isPeersky = ua.includes("peersky");
12+
const isAgregore = ua.includes("agregore");
13+
return isIpfs || isPeersky || isAgregore;
1514
}
1615

17-
/**
18-
* Returns the base URL prefix for Wikipedia on IPFS, depending on IPNS protocol support.
19-
* If the browser supports IPNS, use 'ipns://en.wikipedia-on-ipfs.org/'.
20-
* Otherwise, fall back to the public https gateway.
21-
*/
2216
function getIpfsBaseUrl() {
23-
if (supportsIpnsProtocol()) {
24-
// Direct IPNS (peer-to-peer)
17+
// If in a true P2P environment (or recognized one like Peersky or Agregore), use IPNS://
18+
if (isP2PEnvironment()) {
2519
return "ipns://en.wikipedia-on-ipfs.org/";
2620
} else {
27-
// HTTP gateway fallback
21+
// Otherwise, fallback to the HTTP gateway
2822
return "https://en-wikipedia--on--ipfs-org.ipns.dweb.link/";
2923
}
3024
}
@@ -82,7 +76,9 @@ function resolveQuery(query) {
8276
* Returns suggestions from Wikipedia on IPFS
8377
*/
8478
function fetchSuggestions(query) {
85-
const apiUrl = 'https://en.wikipedia.org/w/api.php?origin=*&action=opensearch&format=json&search=' + encodeURIComponent(query);
79+
const apiUrl =
80+
"https://en.wikipedia.org/w/api.php?origin=*&action=opensearch&format=json&search=" +
81+
encodeURIComponent(query);
8682

8783
fetch(apiUrl)
8884
.then((response) => response.json())

0 commit comments

Comments
 (0)