js hook
JSON
var my_stringify= JSON.stringify; JSON.stringify = function (params){ console.log("xxx",params); return my_stringify(params); }; var my_parse = JSON.parse; JSON.parse = function (params){ console.log("xxx",params); return my_parse(params); };
cookie
var cookie_cache = document.cookie; Object.defineProperty(document,'cookie',{ get:function(){ console.log('Getting cookie'); return cookie_cache; }, set : function(val){ console.log('Setting cookie',val); var cookie = val.split(';')[0]; var ncookie = cookie.split("="); var flag = false; var cache = cookie_cache.split("; "); cache = cache.map(function(a){ if (a.split("=")[0] === ncookie[0]){ flag = true; return cookie; } return a; }) cookie_cache = cache.join("; "); if (!flag){ cookie_cache += cookie + "; "; } this._value = val; return cookie_cache; } })
window 的属性
(function() { var token = ""; Object.defineProperty(window, 'GEERANDOMTOKEN', { set: function(val) { console.log('GEERANDOMTOKEN->', val); debugger; token = val; return val; }, get: function(){ return token; } }); })();