Last active
March 26, 2018 11:03
-
-
Save qrg/de603bf51458910916ad45492b9360d4 to your computer and use it in GitHub Desktop.
Replace specified font-family on the body element.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const EXCLUSIONS = [ | |
| 'Meiryo', | |
| 'メイリオ', | |
| '"MS PGothic"', | |
| '"MS ゴシック"', | |
| 'x-locale-body', | |
| 'system-ui', | |
| '"Yu Gothic UI"', | |
| '"YuGothic UI"' | |
| ].map(f => f.toLowerCase()); | |
| const ALT = '"游ゴシック Medium"'; | |
| const replaceFontFamily = () => { | |
| const css = (element, property) => window.getComputedStyle(element, null).getPropertyValue(property); | |
| const fonts = css(document.body, 'font-family').split(',').map(f => f.trim()); | |
| if (fonts.length === 0) return; | |
| console.log('Replace Specifiied Font Family: original font family:', fonts); | |
| const newFonts = [...new Set(fonts.map(f => { | |
| if (EXCLUSIONS.includes(f.toLowerCase())) { | |
| console.log('Replace Specifiied Font Family: ', 'found: ', f); | |
| return ALT; | |
| } | |
| return f; | |
| }))]; | |
| document.body.style.fontFamily = newFonts; | |
| console.log('Replace Specifiied Font Family: current font-family: ', newFonts); | |
| }; | |
| window.addEventListener('load', replaceFontFamily, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment