Font Substitution v3

Substitutes arbitrary fonts on webpages

ของเมื่อวันที่ 26-08-2015 ดู เวอร์ชันล่าสุด

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name           Font Substitution v3
// @description    Substitutes arbitrary fonts on webpages
// @author         Alan Davies
// @copyright      2015, Alan Davies
// @version        3.0.0
// @date           2015-08-26
// @namespace      FontSub3
// @include        *
// @grant          GM_addStyle
// @run-at         document-start
// ==/UserScript==

var globalDebug = false;

if (globalDebug) console.log("Font substitution start");

var fontMap = new Map([
	[ "arial",			"Verdana" ],
	[ "helvetica",		"Verdana" ],
	[ "courier",		"Consolas" ],
	[ "courier new",	"Consolas" ]
]);

function OverrideFontFaces()
{
	for (let fontSub of fontMap)
	{
		let style = "@font-face { font-family: \"" + fontSub[0] + "\"; src: local(\"" + fontSub[1] + "\") !important }";

		if (globalDebug) console.log("Adding style: " + style);

		GM_addStyle(style);
	}
}

var done = false;

// create an observer instance
var observer = new MutationObserver(function(mutations) {
	if (globalDebug) console.log("Mutation event");
	
	// Add the font face overrides once we have a body element
	if (!done && (null != document.body))
	{
		observer.disconnect();
		OverrideFontFaces();
		done = true;
	}
});

observer.observe(document, { childList: true, attributes: false, characterData: false, subtree: true });