Clean Font Weights

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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);