Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
679 B
1
Indexable
Never
  const listenLocalStorage = (callback) => {
            if (typeof (window.Storage.prototype || {}).setItem === 'function') {
                const originalSetItem = window.Storage.prototype.setItem;
                const originalLocalSetItem = window.localStorage.setItem;

                window.Storage.prototype.setItem = function () {
                    callback(arguments[0]);

                    originalSetItem.apply(this, arguments);
                };

                window.localStorage.setItem = function () {
                    callback(arguments[0]);

                    originalLocalSetItem.apply(this, arguments);
                };
            }
        };
Leave a Comment