Skip to content

Instantly share code, notes, and snippets.

@paulonteri
Created August 3, 2020 06:59
Show Gist options
  • Save paulonteri/c7555e8dc5e0f8b9c60359d6a55f4f5c to your computer and use it in GitHub Desktop.
Save paulonteri/c7555e8dc5e0f8b9c60359d6a55f4f5c to your computer and use it in GitHub Desktop.
Detect Addition to localStorage/sessionStorage
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