Clear Torn LocalStorage

Adds a button to clear localStorage and refresh the page on torn.com

  1. // vim: set expandtab tabstop=2 shiftwidth=2 softtabstop=2
  2. // ==UserScript==
  3. // @name Clear Torn LocalStorage
  4. // @namespace http://tampermonkey.net/
  5. // @version 1.1
  6. // @description Adds a button to clear localStorage and refresh the page on torn.com
  7. // @author swrv [3069664]
  8. // @match https://www.torn.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Only run in the top window
  16. if (window !== window.top) return;
  17.  
  18. // Check if localStorage was just cleared
  19. if (sessionStorage.getItem('localStorageCleared')) {
  20. sessionStorage.removeItem('localStorageCleared');
  21. alert('localStorage has been cleared.');
  22. }
  23.  
  24. // Create the button
  25. const button = document.createElement('button');
  26. button.textContent = 'Clear LocalStorage';
  27. button.style.position = 'fixed';
  28. button.style.top = '10px';
  29. button.style.left = '10px';
  30. button.style.zIndex = '2147483647';
  31. button.style.padding = '5px 10px';
  32. button.style.fontSize = '12px';
  33. button.style.backgroundColor = '#f0f0f0';
  34. button.style.border = '1px solid #ccc';
  35. button.style.borderRadius = '3px';
  36. button.style.cursor = 'pointer';
  37.  
  38. // Add click event listener
  39. button.addEventListener('click', function() {
  40. localStorage.clear();
  41. sessionStorage.setItem('localStorageCleared', 'true');
  42. location.reload();
  43. });
  44.  
  45. // Add the button to the page
  46. document.body.appendChild(button);
  47. })();
  48.