Skip to content

Instantly share code, notes, and snippets.

@azdanov
Created February 21, 2025 07:46
Show Gist options
  • Save azdanov/709333918db4b7f360e35c34d01281a0 to your computer and use it in GitHub Desktop.
Save azdanov/709333918db4b7f360e35c34d01281a0 to your computer and use it in GitHub Desktop.
UserScript to swap the Facebook favicon with a custom emoji
// ==UserScript==
// @name Facebook Favicon Swap
// @namespace https://tampermonkey.net/
// @version 1.0
// @description Swaps the Facebook favicon with a custom emoji
// @match *://www.facebook.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Generates a data URL for a canvas with the given emoji
function generateEmojiFavicon(emoji, size) {
const canvas = document.createElement('canvas');
canvas.width = size;
canvas.height = size;
const context = canvas.getContext('2d');
context.font = `${size - 4}px sans-serif`;
context.textAlign = 'center';
context.textBaseline = 'middle';
context.fillText(emoji, size / 2, size / 2);
return canvas.toDataURL('image/png');
}
// Create a data URL for star emoji
const starDataUrl = generateEmojiFavicon('🔵', 30);
// Find the existing favicon or create one if not present
let faviconLink = document.querySelector("link[rel*='icon']");
if (!faviconLink) {
faviconLink = document.createElement('link');
faviconLink.rel = 'icon';
document.head.appendChild(faviconLink);
}
// Update the favicon with the star emoji data URL
faviconLink.href = starDataUrl;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment