Skip to content

Commit

Permalink
replace system emojis with twemoji
Browse files Browse the repository at this point in the history
  • Loading branch information
fire332 committed Jan 22, 2025
1 parent 04bf2d6 commit 2148aa5
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 2 deletions.
66 changes: 64 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"homepage": "https://github.com/webosbrew/youtube-webos#readme",
"dependencies": {
"@babel/runtime-corejs3": "^7.26.0",
"@twemoji/api": "^15.1.0",
"core-js-pure": "^3.39.0",
"regenerator-runtime": "^0.14.1",
"tiny-sha256": "^1.0.2",
Expand Down
6 changes: 6 additions & 0 deletions src/emoji-font.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
img.emoji {
height: 1em;
width: 1em;
margin: 0 0.05em 0 0.1em;
vertical-align: -0.1em;
}
24 changes: 24 additions & 0 deletions src/emoji-font.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import twemoji from '@twemoji/api';

import './emoji-font.css';

const YT_FORMATTED_STR_TAG = 'yt-formatted-string';

const emojiObs = new MutationObserver((mutations) => {
mutations
.flatMap((mut) => Array.from(mut.addedNodes))
.filter((node) => node instanceof HTMLElement)
.flatMap((elem) =>
Array.from(
elem.querySelectorAll(YT_FORMATTED_STR_TAG) as NodeListOf<HTMLElement>
)
)
.forEach((elem) => void twemoji.parse(elem, { size: '72x72' }));
});

// twemoji expects the charset to be UTF-8
if (document.characterSet === 'UTF-8') {
emojiObs.observe(document.body, { childList: true, subtree: true });
} else {
console.warn('document charset not utf-8. Emoji replacement disabled.');
}
1 change: 1 addition & 0 deletions src/userScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ import './font-fix.css';
import './thumbnail-quality';
import './screensaver-fix';
import './yt-fixes.css';
import './emoji-font.ts';

0 comments on commit 2148aa5

Please sign in to comment.