Emoji favicons for the web
0
fork

Configure Feed

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

cleanup

+12 -17
+3 -11
source/content_script.ts
··· 9 9 import { defaultSettings, STORAGE_KEYS } from './types.ts'; 10 10 import Autoselector from './utilities/autoselector.ts'; 11 11 import browserAPI from './utilities/browser_api.ts'; 12 - import { 13 - appendFaviconLink, 14 - removeAllFaviconLinks, 15 - } from './utilities/favicon_helpers.ts'; 12 + import { appendFaviconLink } from './utilities/favicon_helpers.ts'; 16 13 const autoselector = new Autoselector(); 17 14 18 15 browserAPI.storage.sync.get( ··· 20 17 (result: Settings = defaultSettings) => { 21 18 const urlToCheck = location.href; 22 19 23 - const hasOverride = result.siteList.some( 20 + const shouldOverride = result.siteList.some( 24 21 (site: string) => urlToCheck.match(site), 25 22 ); 26 23 27 24 if (result.features.enableFaviconAutofill) { 28 25 const autoselected = autoselector.selectFavicon(location.host); 29 - appendFaviconLink(autoselected.emoji || '😀'); 30 - } 31 - 32 - if (hasOverride) { 33 - removeAllFaviconLinks(); 34 - appendFaviconLink('😀', { shouldOverride: true }); 26 + appendFaviconLink(autoselected.emoji || '😀', { shouldOverride }); 35 27 } 36 28 }, 37 29 );
+9 -6
source/utilities/favicon_helpers.ts
··· 17 17 const faviconURL = createFaviconURLFromChar(name || ''); 18 18 if (!faviconURL) return; 19 19 20 + if (shouldOverride) removeAllFaviconLinks(); 21 + 22 + // Already appended favicon; just update 20 23 if (appendedFavicon) { 21 24 appendedFavicon.setAttribute('href', faviconURL); 22 - } else if (shouldOverride || !(await faviconIsAvailable())) { 25 + } else if (await isFaviconMissing()) { 23 26 appendedFavicon = head.appendChild( 24 27 createLink(faviconURL, ICON_SIZE, 'image/png'), 25 28 ); ··· 27 30 } 28 31 29 32 // Return an array of link tags that have an icon rel 30 - export function getAllIconLinks(): HTMLLinkElement[] { 33 + function getAllIconLinks(): HTMLLinkElement[] { 31 34 return Array.prototype.slice 32 35 .call(document.getElementsByTagName('link')) 33 36 .filter(isIconLink); 34 37 } 35 38 36 - export async function faviconIsAvailable() { 39 + async function isFaviconMissing() { 37 40 const iconLinkFound = getAllIconLinks() 38 41 .concat(createLink('/favicon.ico')) // Browsers fallback to favicon.ico 39 42 .map(async ({ href }: HTMLLinkElement) => { ··· 41 44 throw new Error('not found'); 42 45 }); 43 46 try { 44 - return await Promise.any(iconLinkFound); 47 + return !(await Promise.any(iconLinkFound)); 45 48 } catch { 46 - return false; 49 + return true; 47 50 } 48 51 } 49 52 50 53 // Removes all icon link tags 51 - export function removeAllFaviconLinks(): void { 54 + function removeAllFaviconLinks(): void { 52 55 getAllIconLinks().forEach((link) => link.remove()); 53 56 appendedFavicon = null; 54 57 }