js hook

时间:2021-06-02 10:33:51   收藏:0   阅读:0
//cookie hook
(function () {
    ‘use strict‘;
    var cookie_cache = document.cookie;
    Object.defineProperty(document, ‘cookie‘, {
        get: function () {
            console.log(cookie_cache);
            return cookie_cache;
        },
        set: function (val) {
            debugger
            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 + ";";
            }
        },
    });

})();
//hook console.log
(function(){
    console._log = console.log;
    var _log = function(arg){

    }
    Object.defineProperty(console, ‘log‘, {value:_log});
})()

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!