plebbit / seedit

A GUI for plebbit similar to old.reddit
https://seedit.eth.limo/#/
GNU General Public License v2.0
11 stars 2 forks source link

add iframe support for custom youtube links #322

Closed plebeius-eth closed 6 months ago

plebeius-eth commented 6 months ago

for example links from invidious instances, they still contain the regular video id and yt prefix

plebeius-eth commented 6 months ago

4e070551c588a5ec1fef2f48d48744cd2d936296

estebanabaroa commented 6 months ago
const isYoutubeVideoUrl = (parsedUrl: URL): boolean => {
    const youtubeVideoPattern = /\/watch\?v=/;
    const youtubeHostPatterns = /^(www\.)?(youtube\.com|youtu\.be|yt\.)$/;
    return youtubeVideoPattern.test(parsedUrl.pathname + parsedUrl.search) || youtubeHostPatterns.test(parsedUrl.host);
  };

what does this do? there's a reason I use a Set of strings, and not regex, this code is ran tons of time, it's a waste of resources to run regex every single link every single rerender

plebeius-eth commented 6 months ago

fixed a3db239a302cc35c516426ce6a1019746a482476

estebanabaroa commented 6 months ago

it should probably actually be

 if (youtubeHosts.has(parsedUrl.host) || (parsedUrl.host.startsWith('yt.') && parsedUrl.searchParams.has('v'))) {
    return <YoutubeEmbed parsedUrl={parsedUrl} />;
  }

since getYouTubeVideoId requires it to have a v param

also

  } else if (url.searchParams.has('v')) {
    return url.searchParams.get('v');
  } else if (url.host.startsWith('yt.')) {
    return url.searchParams.get('v');
  }

} else if (url.host.startsWith('yt.')) { will never hit

plebeius-eth commented 6 months ago

1d9327ecca37871d1132cd731a070d5565c1ce25