11// ==UserScript==
22// @name Forward Nostr Events
33// @description Your events and of those you interacted with
4- // @version 0.5
4+ // @version 0.6
55// @downloadURL https://userscripts.codonaft.com/forward-nostr-events.user.js
66// @run -at document-start
77// @grant none
@@ -28,6 +28,7 @@ const MS_IN_SEC = 1000;
2828const sockets = new Map ( ) ;
2929const pending = new Map ( ) ;
3030const bannedPubkeys = new Map ( ) ;
31+ const brainstormResponses = new Map ( ) ;
3132
3233let forwardedEvents ;
3334let cachedEvents ;
@@ -224,14 +225,16 @@ const handleOutgoing = async (socket, message) => {
224225 return ;
225226 }
226227
227- if ( ! bannedPubkeys . has ( pubkey ) ) {
228+ if ( pubkey !== myPubkey && ! bannedPubkeys . has ( pubkey ) && ! brainstormResponses . has ( pubkey ) ) {
228229 try {
229- const response = await fetch ( 'https://api.brainstorm.world/stats/pubkey' , {
230+ const response = fetch ( 'https://api.brainstorm.world/stats/pubkey' , {
230231 method : 'POST' ,
231232 headers : { 'Content-Type' : 'application/json' } ,
232233 body : JSON . stringify ( { pubkey } )
233234 } ) ;
234- const wot = await response . json ( ) ;
235+ brainstormResponses . set ( pubkey , response ) ;
236+ const wot = await ( await response ) . json ( ) ;
237+ brainstormResponses . delete ( pubkey ) ;
235238 console . log ( 'wot' , wot ) ;
236239 const { rank, followers, follows, reporters, muters } = wot ;
237240
@@ -253,6 +256,14 @@ const handleOutgoing = async (socket, message) => {
253256 bannedPubkeys . set ( pubkey , false ) ;
254257 }
255258
259+ try {
260+ if ( brainstormResponses . has ( pubkey ) ) {
261+ await brainstormResponses . get ( pubkey ) ;
262+ }
263+ } catch ( e ) {
264+ console . error ( e ) ;
265+ }
266+
256267 if ( bannedPubkeys . get ( pubkey ) ) {
257268 console . log ( `ignoring events from ${ pubkey } ` ) ;
258269 return ;
0 commit comments