Created
August 3, 2020 06:59
-
-
Save paulonteri/c7555e8dc5e0f8b9c60359d6a55f4f5c to your computer and use it in GitHub Desktop.
Detect Addition to localStorage/sessionStorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sessionStorage.setItem = function (key, value) { | |
var event = new Event("itemInserted"); | |
event.value = value; // Optional.. | |
event.key = key; // Optional.. | |
document.dispatchEvent(event); | |
originalSetItem.apply(this, arguments); | |
}; | |
var sessionStorageSetHandler = function (e) { | |
console.log(e.key); | |
console.log(e.value); | |
}; | |
document.addEventListener("itemInserted", sessionStorageSetHandler, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment