Created
July 13, 2020 18:02
-
-
Save JosePedroDias/6599623878546ce496784f39bb084f08 to your computer and use it in GitHub Desktop.
tampermonkey userscripts for cookies and localStorage
This file contains 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
// ==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