Clean Font Weights

Make website font-weights standard (400) if below 400

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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         Clean Font Weights
// @namespace    cleanFonts_kk
// @description  Make website font-weights standard (400) if below 400
// @version      0.7
// @author       Kai Krause <[email protected]>
// @include      *
// @run-at       document-idle
// @grant        none
// ==/UserScript==

var cachedElements = [];
var fontCheck = '';
function font() {
	if (fontCheck.length < 1) {
		var fontOverride_kk = document.createElement("style");
		fontOverride_kk.innerText = ".fontOverride_kk{font-weight: 400 !important;}";
		document.head.appendChild(fontOverride_kk);
		fontCheck = document.getElementsByClassName("fontOverride_kk");
	}

	var allElements = document.querySelectorAll('*');
	for (var i = 0; i < allElements.length; i++) {
		if (cachedElements.indexOf(allElements[i]) > -1) continue;
		cachedElements.push(allElements[i]);
		applyFont(allElements, i);
	}
}

function applyFont (allElements, i) {
	setTimeout(function(){
		var css = window.getComputedStyle(allElements[i], null);
		var fontWeight = css.getPropertyValue("font-weight");
		if (fontWeight && fontWeight < 400) {
			allElements[i].classList.add("fontOverride_kk");
		}
	}, Math.random(4,12));
}

// Page Load
font();

// Peformant Dynamic function wrapper
var oldScrollPos = 0;
function dynamicScroll (f) {
	window.addEventListener("scroll", (function(){
		var scrollDifference = Math.abs(oldScrollPos-window.scrollY);
		if (scrollDifference > 500) {
			window.requestAnimationFrame(f);
			oldScrollPos = window.scrollY;
		}
	}), false);
}
dynamicScroll(font);