Krysti.Engineer Official Chat
You are viewing an inferior version of the site because your browser does not support WebP. Do upgrade to something like Chrome or Firefox. Loading websites like this causes them to require a fallback set of images and they are almost always lower quality and larger in size.

Ko-fi Floating Button Deferred Load

This is an attempt to make friendly the ko-fi widget. I found it annoying at least, so I figured maybe others would too.
2022-07-19T:00:00:00+00:00 July 20 2022 00:00:00

<script>
var loadck = 0;
var preck = 0;
var timerfly = 0;
var kofiConfig = {
	user:'youruser',
	label:'Support Us'
}
function kofiWidget() {
	if(typeof(kofiWidgetOverlay) == 'undefined') {
		if(preck==0) {
			var head= document.getElementsByTagName('head')[0];
			var script= document.createElement('script');
			script.src= 'https://storage.ko-fi.com/cdn/scripts/overlay-widget.js';
			head.appendChild(script);
			preck=1;
		}		
		if((loadck==0)&&(timerfly==0)) { 
			setTimeout(function() { 
				kofiWidget();
				timerfly=0; 
			},1000); 
			timerfly=1;
		}
	} else {
		if(loadck==0) {
			kofiWidgetOverlay.draw(kofiConfig.user, {
				'type': 'floating-chat',
				'floating-chat.donateButton.text': kofiConfig.label,
				'floating-chat.donateButton.background-color': '#ff38b8',
				'floating-chat.donateButton.text-color': '#fff'
			});
			loadck = 1;
		}
	}
}
document.addEventListener('scroll',function(e) {
	var sh = parseInt(document.body.offsetHeight - window.pageYOffset);
	var ck = parseInt(sh * 0.8);
	if((window.scrollY>ck)&&(loadck==0)) {
		kofiWidget();
	}
});
</script>

This will load the script resource for the widget then wait until it's resource is ready and finally will appear at about 80% down the page when the user arrives there, essentially not wasting any script loading on the widget for less interested visitors.

Contact Krysti

@itskrystibitch Twitter Photo
Twitter:
@KrystiOnline
Facebook:
@KrystiOnline
IRC:
Official Chat
Direct.Me:
@Krysti
Ko-fi:
@Krysti
Photos:
Virtual Krysti
E-Mail / Notify of errors:
coder [@] krysti.engineer
Please be patient contacting me, I don't really check much of social media or anything. If you use the IRC be sure to stick around because that's how IRC works, silly. :P