clear

Clears local storage and indexedDB data

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
  1. // ==UserScript==
  2. // @name clear
  3. // @version 1.1
  4. // @description Clears local storage and indexedDB data
  5. // @match https://www.genschat.com/*
  6. // @match https://www.characterwaifu.com/*
  7. // @grant none
  8. // @license MIT
  9. // @namespace Violentmonkey Scripts
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Specify the name of the IndexedDB database you want to clear
  16. const databaseName = 'localforage';
  17.  
  18.  
  19. // Specify the time interval between clearing each object store, in milliseconds
  20. const loopDelay = 20;
  21.  
  22. // Open the IndexedDB database
  23. const request = indexedDB.open(databaseName);
  24.  
  25. // Event handler for successful database opening
  26. request.onsuccess = function(event) {
  27. const db = event.target.result;
  28.  
  29. // Get a list of object store names in the database
  30. const objectStoreNames = Array.from(db.objectStoreNames);
  31.  
  32. // Define a function to clear the next object store
  33. const clearNextObjectStore = function() {
  34. if (objectStoreNames.length > 0) {
  35. const objectStoreName = objectStoreNames.shift();
  36. const transaction = db.transaction(objectStoreName, 'readwrite');
  37. const objectStore = transaction.objectStore(objectStoreName);
  38. const clearRequest = objectStore.clear();
  39.  
  40. clearRequest.onsuccess = function() {
  41. console.log(`Cleared all data in object store: ${objectStoreName}`);
  42. // Call the function again after a delay
  43. setTimeout(clearNextObjectStore, loopDelay);
  44. };
  45.  
  46. clearRequest.onerror = function(event) {
  47. console.error(`An error occurred while clearing data in object store: ${objectStoreName}`, event.target.error);
  48. };
  49. } else {
  50. console.log('All data in the IndexedDB database has been cleared.');
  51. }
  52. };
  53.  
  54. // Start the loop
  55. clearNextObjectStore();
  56. };
  57.  
  58. // Event handler for database errors
  59. request.onerror = function(event) {
  60. console.error('An error occurred while opening the IndexedDB database:', event.target.error);
  61. };
  62. localStorage.clear();
  63. })();