From e1fd1f0df725ca61fccee3c500cc4fc8d56536dc Mon Sep 17 00:00:00 2001 From: Jiiks Date: Wed, 11 Jan 2017 12:43:46 +0200 Subject: [PATCH] Custom localStorage for old plugin compatibility --- js/main.js | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/js/main.js b/js/main.js index ad55f194..eb05974b 100644 --- a/js/main.js +++ b/js/main.js @@ -11,30 +11,53 @@ (function() { let __fs = window.require("fs"); - var data = {}; + let __data = {}; if(__fs.existsSync("localStorage.json")) { try { - data = JSON.parse(__fs.readFileSync("localStorage.json")); + __data = JSON.parse(__fs.readFileSync("localStorage.json")); }catch(err) { console.log(err); } } - let __ls = data; - __ls.setItem = function(i, v) { + var __ls = __data; + __ls.setItem = function(i, v) { __ls[i] = v; - __fs.writeFileSync("localStorage.json", JSON.stringify(__ls), null, 4); + this.save(); }; __ls.getItem = function(i) { return __ls[i]; }; - __ls.push = function() { - __fs.writeFileSync("localStorage.json", JSON.stringify(__ls), null, 4); + __ls.save = function() { + __fs.writeFileSync("localStorage.json", JSON.stringify(this), null, 4); }; - window.localStorage = __ls; + var __proxy = new Proxy(__ls, { + set: function(target, name, val, receiver) { + __ls[name] = val; + __ls.save(); + }, + get: function(target, name, receiver) { + return __ls[name]; + } + }); + + window.localStorage = __proxy; + })(); + +var g = Object; +var p = new Proxy(g, { + set: function(target,name,val,receiver) { + console.log(target); + console.log(name); + console.log(val); + console.log(receiver); + } +}); + + window.bdStorage = {}; window.bdStorage.get = function(i) { return betterDiscordIPC.sendSync('synchronous-message', { 'arg': 'storage', 'cmd': 'get', 'var': i });