Advertisement
Guest User

Untitled

a guest
Jul 12th, 2024
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Database configuration
  2. const dbName = 'keyval-store';
  3. const dbVersion = 1;
  4. const storeName = 'keyval';
  5.  
  6. // Open a connection to the IndexedDB
  7. let request = indexedDB.open(dbName, dbVersion);
  8.  
  9. request.onerror = function(event) {
  10.   console.error('Error opening IndexedDB', event);
  11. };
  12.  
  13. request.onsuccess = function(event) {
  14.   let db = event.target.result;
  15.  
  16.   // Get a transaction and object store reference
  17.   const transaction = db.transaction([storeName], 'readwrite');
  18.   const objectStore = transaction.objectStore(storeName);
  19.  
  20.   // Read the "pizzax::base" key
  21.   const getKeyRequest = objectStore.get('pizzax::base');
  22.  
  23.   getKeyRequest.onsuccess = function(event) {
  24.     const existingData = event.target.result || {};
  25.  
  26.     // Update the data with the new property
  27.     existingData['nsfw'] = 'ignore';
  28.     existingData['highlightSensitiveMedia'] = false;
  29.     existingData['loadRawImages'] = true;
  30.  
  31.     // Put the updated data back into the store
  32.     const putRequest = objectStore.put(existingData, 'pizzax::base');
  33.  
  34.     putRequest.onsuccess = function() {
  35.       console.log('Data updated successfully');
  36.     };
  37.  
  38.     putRequest.onerror = function(event) {
  39.       console.error('Error updating data', event);
  40.     };
  41.   };
  42.  
  43.   getKeyRequest.onerror = function(event) {
  44.     console.error('Error reading data', event);
  45.   };
  46. };
  47.  
  48.  
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement