4

I have a switch that I'd like to turn on and off in my browser's localStorage using a bookmarklet.

What would be a good bookmarklet for toggling the value of a hard-coded key between "0" and "1"?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Rich Armstrong
  • 1,432
  • 2
  • 16
  • 20

1 Answers1

2
javascript:(function(){localStorage["key"]=(localStorage["key"]=="1"?"0":"1")})()

Note that the bookmarklet must be run while the browser is on a page in the domain that owns the localStorage value that you'd like to toggle.

Daniel LeCheminant
  • 50,583
  • 16
  • 120
  • 115