24行代码gh star 14k,什么鬼?

78 阅读1分钟

日常打开新标签页,逛掘金github 今日热门中,突然发现一个代码仓,'not-paid',我以为是判断当前设备是否为paid呢!

点击去看描述:Client did not pay? Add opacity to the body tag and decrease it every day until their site completely fades away,翻译后客户没有付款?将不透明度添加到body标记中,并每天降低它,直到它们的网站完全消失,不明觉厉...

看到star,omg,14.1k,我去,那这代码一定很牛逼吧!

赶紧点开学习一下

代码如下:

// Next time use letsdeel.com to make sure you get paid
(function(){
	/* change these variables as you wish */
	var due_date = new Date('2017-02-27');
	var days_deadline = 60;
	/* stop changing here */
	
	var current_date = new Date();
	var utc1 = Date.UTC(due_date.getFullYear(), due_date.getMonth(), due_date.getDate());
	var utc2 = Date.UTC(current_date.getFullYear(), current_date.getMonth(), current_date.getDate());
	var days = Math.floor((utc2 - utc1) / (1000 * 60 * 60 * 24));
	
	if(days > 0) {
		var days_late = days_deadline-days;
		var opacity = (days_late*100/days_deadline)/100;
			opacity = (opacity < 0) ? 0 : opacity;
			opacity = (opacity > 1) ? 1 : opacity;
		if(opacity >= 0 && opacity <= 1) {
			document.getElementsByTagName("BODY")[0].style.opacity = opacity;
		}
		
	}
	
})()

我当时的表情就和这个表情包一样

这段代码什么意思呢,说白了就是根据当前日期与指定截止日期的差异,动态调整网页的透明度,每天让body 透明度减少一点

什么鬼,这就14k了,让人摸不着头脑

不可能,不可能,一定有什么其他的玄机,仔细找找,issue、pr,没发现什么玄机。又看了readme 里的wordpress版本代码,好吧!确实没什么玄机

仓库地址:kleampa/not-paid

这是怎么做到的!