this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use URL.parse with polyfill

+62 -52
+1
.prettierrc
··· 7 7 "^[^.].*.css$", 8 8 "index.css$", 9 9 ".css$", 10 + "./polyfills", 10 11 "<THIRD_PARTY_MODULES>", 11 12 "/assets/", 12 13 "^../",
+2 -2
src/components/account-info.jsx
··· 231 231 232 232 const accountInstance = useMemo(() => { 233 233 if (!url) return null; 234 - const domain = punycode.toUnicode(new URL(url).hostname); 234 + const domain = punycode.toUnicode(URL.parse(url).hostname); 235 235 return domain; 236 236 }, [url]); 237 237 ··· 1655 1655 1656 1656 function niceAccountURL(url) { 1657 1657 if (!url) return; 1658 - const urlObj = new URL(url); 1658 + const urlObj = URL.parse(url); 1659 1659 const { host, pathname } = urlObj; 1660 1660 const path = pathname.replace(/\/$/, '').replace(/^\//, ''); 1661 1661 return (
+1 -1
src/components/account-sheet.jsx
··· 58 58 if (result.accounts.length) { 59 59 return result.accounts[0]; 60 60 } else if (/https?:\/\/[^/]+\/@/.test(account)) { 61 - const accountURL = new URL(account); 61 + const accountURL = URL.parse(account); 62 62 const { hostname, pathname } = accountURL; 63 63 const acct = 64 64 pathname.replace(/^\//, '').replace(/\/$/, '') +
+3 -3
src/components/compose.jsx
··· 3292 3292 width = (width / height) * 100; 3293 3293 height = 100; 3294 3294 } 3295 - const urlObj = new URL(url); 3295 + const urlObj = URL.parse(url); 3296 3296 const strippedURL = urlObj.origin + urlObj.pathname; 3297 3297 let strippedWebP; 3298 3298 if (webp) { 3299 - const webpObj = new URL(webp); 3299 + const webpObj = URL.parse(webp); 3300 3300 strippedWebP = webpObj.origin + webpObj.pathname; 3301 3301 } 3302 3302 return ( ··· 3306 3306 onClick={() => { 3307 3307 const { mp4, url } = original; 3308 3308 const theURL = mp4 || url; 3309 - const urlObj = new URL(theURL); 3309 + const urlObj = URL.parse(theURL); 3310 3310 const strippedURL = urlObj.origin + urlObj.pathname; 3311 3311 onClose(); 3312 3312 onSelect({
+7 -9
src/components/link.jsx
··· 22 22 23 23 // Handle encodeURIComponent of searchParams values 24 24 if (!!hash && hash !== '/' && hash.includes('?')) { 25 - try { 26 - const parsedHash = new URL(hash, location.origin); // Fake base URL 27 - if (parsedHash.searchParams.size) { 28 - const searchParamsStr = Array.from(parsedHash.searchParams.entries()) 29 - .map(([key, value]) => `${key}=${encodeURIComponent(value)}`) 30 - .join('&'); 31 - hash = parsedHash.pathname + '?' + searchParamsStr; 32 - } 33 - } catch (e) {} 25 + const parsedHash = URL.parse(hash, location.origin); // Fake base URL 26 + if (parsedHash?.searchParams?.size) { 27 + const searchParamsStr = Array.from(parsedHash.searchParams.entries()) 28 + .map(([key, value]) => `${key}=${encodeURIComponent(value)}`) 29 + .join('&'); 30 + hash = parsedHash.pathname + '?' + searchParamsStr; 31 + } 34 32 } 35 33 36 34 const isActive = hash === to || decodeURIComponent(hash) === to;
+2 -6
src/components/media.jsx
··· 674 674 } 675 675 676 676 function getURLObj(url) { 677 - try { 678 - // Fake base URL if url doesn't have https:// prefix 679 - return new URL(url, location.origin); 680 - } catch (e) { 681 - return null; 682 - } 677 + // Fake base URL if url doesn't have https:// prefix 678 + return URL.parse(url, location.origin); 683 679 } 684 680 685 681 export default Media;
+6 -4
src/components/status.jsx
··· 2535 2535 2536 2536 if (hasText && (image || (type === 'photo' && blurhash))) { 2537 2537 const domain = punycode.toUnicode( 2538 - new URL(url).hostname.replace(/^www\./, '').replace(/\/$/, ''), 2538 + URL.parse(url) 2539 + .hostname.replace(/^www\./, '') 2540 + .replace(/\/$/, ''), 2539 2541 ); 2540 2542 let blurhashImage; 2541 2543 const rgbAverageColor = ··· 2662 2664 } 2663 2665 if (hasText && !image) { 2664 2666 const domain = punycode.toUnicode( 2665 - new URL(url).hostname.replace(/^www\./, ''), 2667 + URL.parse(url).hostname.replace(/^www\./, ''), 2666 2668 ); 2667 2669 return ( 2668 2670 <a ··· 2863 2865 const mediaURL = previewMediaURL || sourceMediaURL; 2864 2866 2865 2867 const sourceMediaURLObj = sourceMediaURL 2866 - ? new URL(sourceMediaURL) 2868 + ? URL.parse(sourceMediaURL) 2867 2869 : null; 2868 2870 const isVideoMaybe = 2869 2871 type === 'unknown' && ··· 3188 3190 3189 3191 function nicePostURL(url) { 3190 3192 if (!url) return; 3191 - const urlObj = new URL(url); 3193 + const urlObj = URL.parse(url); 3192 3194 const { host, pathname } = urlObj; 3193 3195 const path = pathname.replace(/\/$/, ''); 3194 3196 // split only first slash
+2
src/compose.jsx
··· 2 2 3 3 import './app.css'; 4 4 5 + import './polyfills'; 6 + 5 7 import { render } from 'preact'; 6 8 import { useEffect, useState } from 'preact/hooks'; 7 9
+2 -13
src/main.jsx
··· 2 2 3 3 import './cloak-mode.css'; 4 4 5 + import './polyfills'; 6 + 5 7 // Polyfill needed for Firefox < 122 6 8 // https://bugzilla.mozilla.org/show_bug.cgi?id=1423593 7 9 // import '@formatjs/intl-segmenter/polyfill'; ··· 12 14 13 15 if (import.meta.env.DEV) { 14 16 import('preact/debug'); 15 - } 16 - 17 - // AbortSignal.timeout polyfill 18 - // Temporary fix from https://github.com/mo/abortcontroller-polyfill/issues/73#issuecomment-1541180943 19 - // Incorrect implementation, but should be good enough for now 20 - if ('AbortSignal' in window) { 21 - AbortSignal.timeout = 22 - AbortSignal.timeout || 23 - ((duration) => { 24 - const controller = new AbortController(); 25 - setTimeout(() => controller.abort(), duration); 26 - return controller.signal; 27 - }); 28 17 } 29 18 30 19 render(
+1 -1
src/pages/account-statuses.jsx
··· 467 467 468 468 const accountInstance = useMemo(() => { 469 469 if (!account?.url) return null; 470 - const domain = new URL(account.url).hostname; 470 + const domain = URL.parse(account.url).hostname; 471 471 return domain; 472 472 }, [account]); 473 473 const sameInstance = instance === accountInstance;
+2 -2
src/pages/catchup.jsx
··· 1111 1111 publishedAt, 1112 1112 } = card; 1113 1113 const domain = punycode.toUnicode( 1114 - new URL(url).hostname 1115 - .replace(/^www\./, '') 1114 + URL.parse(url) 1115 + .hostname.replace(/^www\./, '') 1116 1116 .replace(/\/$/, ''), 1117 1117 ); 1118 1118 let accentColor;
+1 -1
src/pages/status.jsx
··· 569 569 if (!heroStatus) return; 570 570 const { url } = heroStatus; 571 571 if (!url) return; 572 - return new URL(url).hostname; 572 + return URL.parse(url).hostname; 573 573 }, [heroStatus]); 574 574 const postSameInstance = useMemo(() => { 575 575 if (!postInstance) return;
+3 -1
src/pages/trending.jsx
··· 178 178 width, 179 179 } = link; 180 180 const domain = punycode.toUnicode( 181 - new URL(url).hostname.replace(/^www\./, '').replace(/\/$/, ''), 181 + URL.parse(url) 182 + .hostname.replace(/^www\./, '') 183 + .replace(/\/$/, ''), 182 184 ); 183 185 let accentColor; 184 186 if (blurhash) {
+24
src/polyfills.js
··· 1 + // AbortSignal.timeout polyfill 2 + // Temporary fix from https://github.com/mo/abortcontroller-polyfill/issues/73#issuecomment-1541180943 3 + // Incorrect implementation, but should be good enough for now 4 + if ('AbortSignal' in window) { 5 + AbortSignal.timeout = 6 + AbortSignal.timeout || 7 + ((duration) => { 8 + const controller = new AbortController(); 9 + setTimeout(() => controller.abort(), duration); 10 + return controller.signal; 11 + }); 12 + } 13 + 14 + // URL.parse() polyfill 15 + if ('URL' in window && typeof URL.parse !== 'function') { 16 + URL.parse = function (url, base) { 17 + if (!url) return null; 18 + try { 19 + return base ? new URL(url, base) : new URL(url); 20 + } catch (e) { 21 + return null; 22 + } 23 + }; 24 + }
+1 -1
src/utils/get-instance-status-url.js
··· 11 11 12 12 export function getInstanceStatusObject(url) { 13 13 // Regex /:username/:id, where username = @username or @username@domain, id = anything 14 - const { hostname, pathname } = new URL(url); 14 + const { hostname, pathname } = URL.parse(url); 15 15 // const [, username, domain, id] = pathname.match(statusRegex) || []; 16 16 for (const regex of statusPostRegexes) { 17 17 const [, id] = pathname.match(regex) || [];
+1 -1
src/utils/isMastodonLinkMaybe.jsx
··· 1 1 export default function isMastodonLinkMaybe(url) { 2 2 try { 3 - const { pathname, hash } = new URL(url); 3 + const { pathname, hash } = URL.parse(url); 4 4 return ( 5 5 /^\/.*\/\d+$/i.test(pathname) || 6 6 /^\/(@[^/]+|users\/[^/]+)\/(statuses|posts)\/\w+\/?$/i.test(pathname) || // GoToSocial, Takahe
+1 -1
src/utils/open-compose.js
··· 1 1 export default function openCompose(opts) { 2 - const url = new URL('/compose/', window.location); 2 + const url = URL.parse('/compose/', window.location); 3 3 const { width: screenWidth, height: screenHeight } = window.screen; 4 4 const left = Math.max(0, (screenWidth - 600) / 2); 5 5 const top = Math.max(0, (screenHeight - 450) / 2);
+2 -6
src/utils/unfurl-link.jsx
··· 59 59 theURL = `https://${finalURL}`; 60 60 } 61 61 62 - let urlObj; 63 - try { 64 - urlObj = new URL(theURL); 65 - } catch (e) { 66 - return; 67 - } 62 + const urlObj = URL.parse(theURL); 63 + if (!urlObj) return; 68 64 const domain = urlObj.hostname; 69 65 const path = urlObj.pathname; 70 66 // Regex /:username/:id, where username = @username or @username@domain, id = post ID