Skip to content

Instantly share code, notes, and snippets.

@JosePedroDias
Created July 13, 2020 18:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JosePedroDias/6599623878546ce496784f39bb084f08 to your computer and use it in GitHub Desktop.
Save JosePedroDias/6599623878546ce496784f39bb084f08 to your computer and use it in GitHub Desktop.
tampermonkey userscripts for cookies and localStorage
// ==UserScript==
// @name debug localStorage.setItem()
// @namespace https://josepedrodias.com/
// @version 0.1
// @description yada yada
// @author jose.pedro.dias@gmail.com
// @match https://putyoursitehere/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// based on https://gist.github.com/mynameislau/b7eabfcdc0a17ac41cdc0b974f94d807
const ignores = [
'test'
];
Object.defineProperty(window, 'localStorage', {
configurable: true,
enumerable: true,
value: new Proxy(localStorage, {
set: function (ls, prop, value) {
if (ignores.indexOf(prop) === -1) {
//console.error(`LS direct assignment of ${prop}`);
debugger;
}
ls[prop] = value;
return true;
},
get: function (ls, prop) {
if (prop !== 'setItem') {
if (typeof ls[prop] === 'function') {
return ls[prop].bind(ls);
} else {
return ls[prop];
}
}
return (...args) => {
const key = args[0];
if (ignores.indexOf(key) === -1) {
//console.error(`LS setItem(${key})`);
debugger;
}
ls.setItem.apply(ls, args);
};
},
}),
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment