random bun scripts that dont fit anywhere else

feat: allow importing your verifications as trusted verifiers

dunkirk.sh 6dc2f87c 68b3edaf

verified
+136
+136
bluesky-community-verifications.user.js
··· 600 600 }); 601 601 }; 602 602 603 + // Function to import verifications from the current user 604 + const importVerificationsFromSelf = async () => { 605 + try { 606 + // Check if we can determine the current user 607 + const bskyStorageData = localStorage.getItem("BSKY_STORAGE"); 608 + let userData = null; 609 + 610 + if (bskyStorageData) { 611 + try { 612 + const bskyStorage = JSON.parse(bskyStorageData); 613 + if (bskyStorage.session.currentAccount) { 614 + userData = bskyStorage.session.currentAccount; 615 + } 616 + } catch (error) { 617 + console.error("Error parsing BSKY_STORAGE data:", error); 618 + } 619 + } 620 + 621 + if (!userData || !userData.handle) { 622 + alert( 623 + "Could not determine your Bluesky handle. Please ensure you're logged in.", 624 + ); 625 + return; 626 + } 627 + 628 + if (!userData || !userData.handle) { 629 + alert( 630 + "Unable to determine your Bluesky handle. Make sure you're logged in.", 631 + ); 632 + return; 633 + } 634 + 635 + const userHandle = userData.handle; 636 + 637 + // Show loading state 638 + const importButton = document.getElementById("importVerificationsBtn"); 639 + const originalText = importButton.textContent; 640 + importButton.textContent = "Importing..."; 641 + importButton.disabled = true; 642 + 643 + // Fetch verification records from the user's account with pagination 644 + let allRecords = []; 645 + let cursor = null; 646 + let hasMore = true; 647 + 648 + while (hasMore) { 649 + const url = cursor 650 + ? `https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=${userHandle}&collection=app.bsky.graph.verification&cursor=${cursor}` 651 + : `https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=${userHandle}&collection=app.bsky.graph.verification`; 652 + 653 + const verificationResponse = await fetch(url); 654 + const data = await verificationResponse.json(); 655 + 656 + if (data.records && data.records.length > 0) { 657 + allRecords = [...allRecords, ...data.records]; 658 + } 659 + 660 + if (data.cursor) { 661 + cursor = data.cursor; 662 + } else { 663 + hasMore = false; 664 + } 665 + } 666 + 667 + const verificationData = { records: allRecords }; 668 + 669 + if (!verificationData.records || verificationData.records.length === 0) { 670 + alert("No verification records found in your account."); 671 + importButton.textContent = originalText; 672 + importButton.disabled = false; 673 + return; 674 + } 675 + 676 + // Extract the handles of verified users 677 + const verifiedUsers = []; 678 + for (const record of verificationData.records) { 679 + console.log(record.value.handle); 680 + verifiedUsers.push(record.value.handle); 681 + } 682 + 683 + // Add all found users to trusted users 684 + let addedCount = 0; 685 + for (const handle of verifiedUsers) { 686 + const existingUsers = getTrustedUsers(); 687 + if (!existingUsers.includes(handle)) { 688 + addTrustedUser(handle); 689 + addedCount++; 690 + } 691 + } 692 + 693 + // Update the UI 694 + updateTrustedUsersList(); 695 + 696 + // Reset button state 697 + importButton.textContent = originalText; 698 + importButton.disabled = false; 699 + 700 + // Show result 701 + alert( 702 + `Successfully imported ${addedCount} verified users from your account.`, 703 + ); 704 + } catch (error) { 705 + console.error("Error importing verifications:", error); 706 + alert("Error importing verifications. Check console for details."); 707 + const importButton = document.getElementById("importVerificationsBtn"); 708 + if (importButton) { 709 + importButton.textContent = "Import Verifications"; 710 + importButton.disabled = false; 711 + } 712 + } 713 + }; 714 + 603 715 // Function to create the settings modal 604 716 const createSettingsModal = () => { 605 717 // Create modal container ··· 643 755 </div> 644 756 `; 645 757 758 + // Create import button 759 + const importContainer = document.createElement("div"); 760 + importContainer.style.cssText = ` 761 + margin-top: 10px; 762 + margin-bottom: 15px; 763 + `; 764 + 765 + const importButton = document.createElement("button"); 766 + importButton.id = "importVerificationsBtn"; 767 + importButton.textContent = "Import Your Verifications"; 768 + importButton.style.cssText = ` 769 + background-color: #2D578D; 770 + color: white; 771 + border: none; 772 + border-radius: 4px; 773 + padding: 8px 15px; 774 + cursor: pointer; 775 + width: 100%; 776 + `; 777 + 778 + importButton.addEventListener("click", importVerificationsFromSelf); 779 + importContainer.appendChild(importButton); 780 + 646 781 // Create trusted users list 647 782 const trustedUsersList = document.createElement("div"); 648 783 trustedUsersList.id = "trustedUsersList"; ··· 695 830 // Assemble modal 696 831 modalContent.appendChild(modalHeader); 697 832 modalContent.appendChild(form); 833 + modalContent.appendChild(importContainer); 698 834 modalContent.appendChild(trustedUsersList); 699 835 modalContent.appendChild(cacheControls); 700 836 modalContent.appendChild(closeButton);