@@ -4,27 +4,21 @@ const searchForm = document.getElementById("searchForm");
44const errorMessage = document . getElementById ( "errorMessage" ) ;
55let 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- */
2216function 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 */
8478function 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