random bun scripts that dont fit anywhere else

feat: add cache

dunkirk.sh e075dd2d fa98587c

verified
+75 -1
+75 -1
bluesky-community-verifications.js
··· 8 8 // Mark script as initialized 9 9 window.bskyTrustedUsersInitialized = true; 10 10 11 - // Define a storage key for trusted users 11 + // Define storage keys 12 12 const TRUSTED_USERS_STORAGE_KEY = "bsky_trusted_users"; 13 + const VERIFICATION_CACHE_STORAGE_KEY = "bsky_verification_cache"; 14 + const CACHE_EXPIRY_TIME = 24 * 60 * 60 * 1000; // 24 hours 13 15 14 16 // Function to get trusted users from local storage 15 17 const getTrustedUsers = () => { ··· 38 40 saveTrustedUsers(updatedUsers); 39 41 }; 40 42 43 + // Cache functions 44 + const getVerificationCache = () => { 45 + const cache = localStorage.getItem(VERIFICATION_CACHE_STORAGE_KEY); 46 + return cache ? JSON.parse(cache) : {}; 47 + }; 48 + 49 + const saveVerificationCache = (cache) => { 50 + localStorage.setItem(VERIFICATION_CACHE_STORAGE_KEY, JSON.stringify(cache)); 51 + }; 52 + 53 + const getCachedVerifications = (user) => { 54 + const cache = getVerificationCache(); 55 + return cache[user] || null; 56 + }; 57 + 58 + const cacheVerifications = (user, records) => { 59 + const cache = getVerificationCache(); 60 + cache[user] = { 61 + records, 62 + timestamp: Date.now(), 63 + }; 64 + saveVerificationCache(cache); 65 + }; 66 + 67 + const isCacheValid = (cacheEntry) => { 68 + return cacheEntry && Date.now() - cacheEntry.timestamp < CACHE_EXPIRY_TIME; 69 + }; 70 + 71 + const clearCache = () => { 72 + localStorage.removeItem(VERIFICATION_CACHE_STORAGE_KEY); 73 + console.log("Verification cache cleared"); 74 + }; 75 + 41 76 // Store all verifiers for a profile 42 77 let profileVerifiers = []; 43 78 ··· 62 97 try { 63 98 // Helper function to fetch all verification records with pagination 64 99 const fetchAllVerifications = async (user) => { 100 + // Check cache first 101 + const cachedData = getCachedVerifications(user); 102 + if (cachedData && isCacheValid(cachedData)) { 103 + console.log(`Using cached verification data for ${user}`); 104 + return cachedData.records; 105 + } 106 + 107 + console.log(`Fetching fresh verification data for ${user}`); 65 108 let allRecords = []; 66 109 let cursor = null; 67 110 let hasMore = true; ··· 85 128 } 86 129 } 87 130 131 + // Save to cache 132 + cacheVerifications(user, allRecords); 88 133 return allRecords; 89 134 }; 90 135 ··· 466 511 padding-top: 15px; 467 512 `; 468 513 514 + // Create cache control buttons 515 + const cacheControls = document.createElement("div"); 516 + cacheControls.style.cssText = ` 517 + margin-top: 15px; 518 + padding-top: 15px; 519 + border-top: 1px solid #eee; 520 + `; 521 + 522 + const clearCacheButton = document.createElement("button"); 523 + clearCacheButton.textContent = "Clear Verification Cache"; 524 + clearCacheButton.style.cssText = ` 525 + padding: 8px 15px; 526 + background-color: #735A5A; 527 + color: white; 528 + border: none; 529 + border-radius: 4px; 530 + cursor: pointer; 531 + margin-right: 10px; 532 + `; 533 + clearCacheButton.addEventListener("click", () => { 534 + clearCache(); 535 + alert( 536 + "Verification cache cleared. Fresh data will be fetched on next check.", 537 + ); 538 + }); 539 + 540 + cacheControls.appendChild(clearCacheButton); 541 + 469 542 // Create close button 470 543 const closeButton = document.createElement("button"); 471 544 closeButton.textContent = "Close"; ··· 482 555 modalContent.appendChild(modalHeader); 483 556 modalContent.appendChild(form); 484 557 modalContent.appendChild(trustedUsersList); 558 + modalContent.appendChild(cacheControls); 485 559 modalContent.appendChild(closeButton); 486 560 settingsModal.appendChild(modalContent); 487 561