Emoji favicons for the web
0
fork

Configure Feed

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

cleanup favicon_helpers

+20 -29
+5 -2
source/content_script.ts
··· 18 18 browserAPI.storage.sync.get( 19 19 STORAGE_KEYS, 20 20 (result: Settings = defaultSettings) => { 21 - const hasOverride = (result?.siteList || []) 22 - .some((site: string) => location.href.match(site)); 21 + const urlToCheck = location.href; 22 + 23 + const hasOverride = result.siteList.some( 24 + (site: string) => urlToCheck.match(site), 25 + ); 23 26 24 27 if (result.features.enableFaviconAutofill) { 25 28 const autoselected = autoselector.selectFavicon(location.host);
+1 -1
source/utilities/create_emoji_favicon_url.ts source/utilities/create_favicon_url.ts
··· 25 25 * Heavily inspired by emoji-favicon-toolkit 26 26 * @source https://github.com/eligrey/emoji-favicon-toolkit/blob/master/src/emoji-favicon-toolkit.ts 27 27 */ 28 - export function createEmojiFaviconURL(char: string): string { 28 + export function createFaviconURLFromChar(char: string): string { 29 29 if (!char || !ctx) return ''; 30 30 31 31 // Calculate sizing
+14 -26
source/utilities/favicon_helpers.ts
··· 1 - import { isFirefox } from './browser_api.ts'; 2 - import { 3 - createEmojiFaviconURL, 4 - ICON_SIZE, 5 - } from './create_emoji_favicon_url.ts'; 1 + import { createFaviconURLFromChar, ICON_SIZE } from './create_favicon_url.ts'; 6 2 import { isIconLink } from './predicates.ts'; 7 3 8 - // Append new favicon links to the document head 9 - const documentHead = document.getElementsByTagName('head')[0]; 10 - const hasFavicon = Boolean(isFirefox() && getAllIconLinks().length); 11 - 12 - let existingFavicon: HTMLElement | null = null; 4 + const head = document.getElementsByTagName('head')[0]; 5 + const siteHasFavicon = Boolean(getAllIconLinks().length); 13 6 14 - if (getAllIconLinks().length) { 15 - existingFavicon = getAllIconLinks()[0]; 16 - } 7 + let appendedFavicon: HTMLElement | null = null; 17 8 18 9 interface Options { 19 10 shouldOverride?: boolean; ··· 22 13 // Given an emoji string, append it to the document head 23 14 export function appendFaviconLink(name: string, options?: Options | void) { 24 15 const { shouldOverride = false } = options || {}; 25 - const href = createEmojiFaviconURL(name || ''); 26 - if (!href) return; 27 - 28 - if (existingFavicon) { 29 - existingFavicon.setAttribute('href', href); 30 - } else if (!hasFavicon || shouldOverride) { 31 - const link = createLink(href, ICON_SIZE, 'image/png'); 32 - existingFavicon = documentHead.appendChild(link); 16 + const faviconURL = createFaviconURLFromChar(name || ''); 17 + if (!faviconURL) return; 33 18 34 - if (!shouldOverride) { 35 - const defaultLink = createLink('/favicon.ico'); 36 - documentHead.appendChild(defaultLink); 37 - } 19 + if (appendedFavicon) { 20 + appendedFavicon.setAttribute('href', faviconURL); 21 + } else if (!siteHasFavicon || shouldOverride) { 22 + appendedFavicon = head.appendChild( 23 + createLink(faviconURL, ICON_SIZE, 'image/png'), 24 + ); 25 + head.appendChild(createLink('/favicon.ico')); 38 26 } 39 27 } 40 28 ··· 48 36 // Removes all icon link tags 49 37 export function removeAllFaviconLinks(): void { 50 38 getAllIconLinks().forEach((link) => link.remove()); 51 - existingFavicon = null; 39 + appendedFavicon = null; 52 40 } 53 41 54 42 // Given a url, create a favicon link