Skip to content

Instantly share code, notes, and snippets.

@fukayatsu
Last active December 9, 2019 01:01
Show Gist options
  • Save fukayatsu/c1f8b48434ee2023776ef6586ee9221e to your computer and use it in GitHub Desktop.
Save fukayatsu/c1f8b48434ee2023776ef6586ee9221e to your computer and use it in GitHub Desktop.
UserScript: macOS Catalina Chrome v78-79 Hiragino Font Fix
// ==UserScript==
// @name macOS Catalina Chrome v78-79 Hiragino Font Fix
// @namespace http://tampermonkey.net/
// @version 0.2
// @description This will no longer be needed after chrome v80.
// @author fukayatsu
// @match http://*/*
// @match https://*/*
// @grant GM_addStyle
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
const selectors = [
'.r-gwet1z', // twitter
'body' // default
];
const replaceFontPairs = {
"ヒラギノ角ゴ Pro W3": "HiraKakuPro-W3",
"Hiragino Maru Gothic Pro": "HiraMaruPro-W4"
}
const replaceFont = (selector) => {
const elem = document.querySelector(selector);
if (!elem) { return }
const originalFontFamily = window.getComputedStyle(elem)['font-family'];
let ff = originalFontFamily;
for (const key in replaceFontPairs) {
const fixedFont = replaceFontPairs[key];
if (ff.includes(fixedFont)) { continue; }
ff = ff.replace(key, replaceFontPairs[key]);
}
if (ff == originalFontFamily) { return }
const styleToAdd = `${selector} { font-family: ${ff} !important; }`;
GM_addStyle(styleToAdd);
console.log("New style added:", styleToAdd);
};
setTimeout(() => {
for (const selector of selectors) {
replaceFont(selector);
}
}, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment