Show localStorage entries

Show localStorage entries for every web page you visit

  1. // ==UserScript==
  2. // @name Show localStorage entries
  3. // @namespace http://userscripts.org/users/75950
  4. // @description Show localStorage entries for every web page you visit
  5. // @include *
  6. // @match http://*/*
  7. // @version 1.1.7
  8. // ==/UserScript==
  9.  
  10. window.addEventListener('load', function() {
  11. var execute = true;
  12. var myBlockedDomains = [];
  13. if(GM_getValue("localStorageDomains")) {
  14. myBlockedDomains = GM_getValue("localStorageDomains").split(",");
  15. for(var j=0; j<myBlockedDomains.length; j++) {
  16. if(window.location.hostname == myBlockedDomains[j]) execute = false;
  17. }
  18. }
  19. if(execute) {
  20. var newCSS = "div.notification {position: fixed; top:0; left:0; width: 100%; border-bottom:3px solid white; color: white; background-color: red; padding: 10px; font-family: Verdana, Arial, sans-serif; font-size: 1em; z-index:200000; text-align: left;} ";
  21. newCSS += "input.notification {margin-left: 20px; font-size:0.7em;} ";
  22. newCSS += "table.notification{font-size: 1em; width: 750px; background-color: white; color: black;} ";
  23. newCSS += "table.notification th {color: white; background-color: black; font-weight: bold; padding: 5px;} ";
  24. newCSS += "table.notification td {padding: 5px; color: black;} ";
  25. newCSS += "h4.notification {font-size: 1em; font-weight: normal; color: white;} ";
  26. GM_addStyle(newCSS);
  27. if(localStorage.length >0) {
  28. var newNotification = document.createElement('div');
  29. newNotification.className = "notification";
  30. var newClose = document.createElement('img');
  31. newClose.src="http://mediacentre.steyr-traktoren.com/App_Themes/Dynamix/closeWhite.gif";
  32. newClose.style.cssText = "float: right; margin-right: 20px;";
  33. newNotification.appendChild(newClose);
  34. var newText = document.createTextNode("Something is stored in localStorage on this domain! Do you want to see it?");
  35. newNotification.appendChild(newText);
  36. var newButton = document.createElement('input');
  37. newButton.type = "button";
  38. newButton.className = "notification";
  39. newButton.value = "View localStorage for this domain";
  40. newNotification.appendChild(newButton);
  41. var newButton2 = document.createElement('input');
  42. newButton2.type = "button";
  43. newButton2.className = "notification";
  44. newButton2.value = "Never ask me again for this domain";
  45. newNotification.appendChild(newButton2);
  46. document.body.appendChild(newNotification);
  47. newClose.addEventListener('click', function() {
  48. newNotification.style.display = 'none';
  49. }, false);
  50. newButton.addEventListener('click', function() {
  51. newNotification.removeChild(newText);
  52. newNotification.removeChild(newButton);
  53. newNotification.removeChild(newButton2);
  54. var newHeading = document.createElement('h4');
  55. newHeading.className = "notification";
  56. var newHeadline = document.createTextNode('localStorage for ' + window.location.hostname);
  57. newHeading.appendChild(newHeadline);
  58. newNotification.appendChild(newHeading);
  59. var newTable = document.createElement('table');
  60. newTable.className = "notification";
  61. var newThead = document.createElement('thead');
  62. var newTR = document.createElement('tr');
  63. var newTH = document.createElement('th');
  64. newHeadline = document.createTextNode('key');
  65. newTH.appendChild(newHeadline);
  66. newTR.appendChild(newTH);
  67. newTH = document.createElement('th');
  68. newHeadline = document.createTextNode('value');
  69. newTH.appendChild(newHeadline);
  70. newTR.appendChild(newTH);
  71. newThead.appendChild(newTR);
  72. newTable.appendChild(newThead);
  73. var newTbody = document.createElement('tbody');
  74. for(var i=0; i<localStorage.length; i++) {
  75. newTR = document.createElement('tr');
  76.  
  77. var newTD = document.createElement('td');
  78. newHeadline = document.createTextNode(localStorage.key(i));
  79. newTD.appendChild(newHeadline);
  80. newTR.appendChild(newTD);
  81.  
  82. newTD = document.createElement('td');
  83. newHeadline = document.createTextNode(localStorage.getItem(localStorage.key(i)));
  84. newTD.appendChild(newHeadline);
  85. newTR.appendChild(newTD);
  86.  
  87. newTbody.appendChild(newTR);
  88. }
  89. newTable.appendChild(newTbody);
  90. newNotification.appendChild(newTable);
  91. }, false);
  92. newButton2.addEventListener('click', function() {
  93. myBlockedDomains.push(window.location.hostname);
  94. GM_setValue("localStorageDomains", myBlockedDomains.join(","));
  95. newNotification.style.display = 'none';
  96. }, false);
  97. }
  98. }
  99. }, false);