the home of serif.blue
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

bug: select last name since that is the latest profile

+103 -74
+103 -74
bluesky-community-verifications.user.js
··· 174 174 175 175 // If we have verifiers, display the badge 176 176 if (profileVerifiers.length > 0) { 177 - displayVerificationBadge(profileVerifiers); 177 + await displayVerificationBadge(profileVerifiers); 178 178 return true; 179 179 } 180 180 ··· 290 290 }); 291 291 }; 292 292 293 - // Legacy function kept for compatibility but redirects to the new implementation 294 - const addRecheckButton = () => { 295 - createPillButtons(); 293 + const findProfileHeaderWithRetry = (retryCount = 0, maxRetries = 10) => { 294 + const nameElements = document.querySelectorAll( 295 + '[data-testid="profileHeaderDisplayName"]', 296 + ); 297 + const nameElement = nameElements[nameElements.length - 1]; 298 + 299 + if (nameElement) { 300 + console.log("Profile header found"); 301 + return nameElement; 302 + } 303 + if (retryCount < maxRetries) { 304 + // Retry with exponential backoff 305 + const delay = Math.min(100 * 1.5 ** retryCount, 2000); 306 + console.log( 307 + `Profile header not found, retrying in ${delay}ms (attempt ${retryCount + 1}/${maxRetries})`, 308 + ); 309 + 310 + return new Promise((resolve) => { 311 + setTimeout(() => { 312 + resolve(findProfileHeaderWithRetry(retryCount + 1, maxRetries)); 313 + }, delay); 314 + }); 315 + } 316 + console.log("Failed to find profile header after maximum retries"); 317 + return null; 296 318 }; 297 319 298 320 // Function to display verification badge on the profile 299 - const displayVerificationBadge = (verifierHandles) => { 321 + const displayVerificationBadge = async (verifierHandles) => { 300 322 // Find the profile header or name element to add the badge to 301 - const nameElement = document.querySelector( 302 - '[data-testid="profileHeaderDisplayName"]', 303 - ); 323 + const nameElement = await findProfileHeaderWithRetry(); 324 + 325 + console.log(nameElement); 304 326 305 327 if (nameElement) { 306 - // Check if badge already exists 307 - if (!document.getElementById("user-trusted-verification-badge")) { 308 - const badge = document.createElement("span"); 309 - badge.id = "user-trusted-verification-badge"; 310 - badge.innerHTML = "✓"; 328 + // Remove existing badge if present 329 + const existingBadge = document.getElementById( 330 + "user-trusted-verification-badge", 331 + ); 332 + if (existingBadge) { 333 + existingBadge.remove(); 334 + } 335 + 336 + const badge = document.createElement("span"); 337 + badge.id = "user-trusted-verification-badge"; 338 + badge.innerHTML = "✓"; 311 339 312 - // Create tooltip text with all verifiers 313 - const verifiersText = 314 - verifierHandles.length > 1 315 - ? `Verified by: ${verifierHandles.join(", ")}` 316 - : `Verified by ${verifierHandles[0]}`; 340 + // Create tooltip text with all verifiers 341 + const verifiersText = 342 + verifierHandles.length > 1 343 + ? `Verified by: ${verifierHandles.join(", ")}` 344 + : `Verified by ${verifierHandles[0]}`; 317 345 318 - badge.title = verifiersText; 319 - badge.style.cssText = ` 320 - background-color: #0070ff; 321 - color: white; 322 - border-radius: 50%; 323 - width: 18px; 324 - height: 18px; 325 - margin-left: 8px; 326 - font-size: 12px; 327 - font-weight: bold; 328 - cursor: help; 329 - display: inline-flex; 330 - align-items: center; 331 - justify-content: center; 332 - `; 346 + badge.title = verifiersText; 347 + badge.style.cssText = ` 348 + background-color: #0070ff; 349 + color: white; 350 + border-radius: 50%; 351 + width: 18px; 352 + height: 18px; 353 + margin-left: 8px; 354 + font-size: 12px; 355 + font-weight: bold; 356 + cursor: help; 357 + display: inline-flex; 358 + align-items: center; 359 + justify-content: center; 360 + `; 333 361 334 - // Add a click event to show all verifiers 335 - badge.addEventListener("click", (e) => { 336 - e.stopPropagation(); 337 - showVerifiersPopup(verifierHandles); 338 - }); 362 + // Add a click event to show all verifiers 363 + badge.addEventListener("click", (e) => { 364 + e.stopPropagation(); 365 + showVerifiersPopup(verifierHandles); 366 + }); 339 367 340 - nameElement.appendChild(badge); 341 - } 368 + nameElement.appendChild(badge); 342 369 } 343 370 344 371 // Also add pill buttons when verification is found ··· 605 632 // Function to check the current profile 606 633 const checkCurrentProfile = () => { 607 634 const currentUrl = window.location.href; 608 - if (currentUrl.includes("bsky.app/profile/")) { 635 + // Only trigger on profile pages 636 + if ( 637 + currentUrl.match(/bsky\.app\/profile\/[^\/]+$/) || 638 + currentUrl.match(/bsky\.app\/profile\/[^\/]+\/follows/) || 639 + currentUrl.match(/bsky\.app\/profile\/[^\/]+\/followers/) 640 + ) { 609 641 const handle = currentUrl.split("/profile/")[1].split("/")[0]; 610 - console.log("Extracted handle:", handle); 642 + console.log("Detected profile page for:", handle); 611 643 612 644 // Create and add the settings UI (only once) 613 645 createSettingsUI(); ··· 624 656 const did = data.uri.split("/")[2]; 625 657 console.log("User DID:", did); 626 658 627 - // Now fetch the app.bsky.graph.verification data specifically 628 - fetch( 629 - `https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=${handle}&collection=app.bsky.graph.verification`, 630 - ) 631 - .then((response) => response.json()) 632 - .then((verificationData) => { 633 - console.log("Verification data:", verificationData); 634 - if ( 635 - verificationData.records && 636 - verificationData.records.length > 0 637 - ) { 638 - console.log( 639 - "User has app.bsky.graph.verification:", 640 - verificationData.records, 641 - ); 642 - } else { 643 - console.log("User does not have app.bsky.graph.verification"); 644 - } 645 - 646 - // Check if any trusted users have verified this profile using the DID 647 - checkTrustedUserVerifications(did); 648 - }) 649 - .catch((verificationError) => { 650 - console.error( 651 - "Error fetching verification data:", 652 - verificationError, 653 - ); 654 - }); 659 + // Check if any trusted users have verified this profile using the DID 660 + checkTrustedUserVerifications(did); 655 661 }) 656 662 .catch((error) => { 657 663 console.error("Error checking profile:", error); 658 664 }); 659 665 660 666 console.log("Bluesky profile detected"); 667 + } else { 668 + // Not on a profile page, reset state 669 + currentProfileDid = null; 670 + profileVerifiers = []; 671 + 672 + // Remove UI elements if present 673 + const existingBadge = document.getElementById( 674 + "user-trusted-verification-badge", 675 + ); 676 + if (existingBadge) { 677 + existingBadge.remove(); 678 + } 679 + 680 + const existingPill = document.getElementById( 681 + "trusted-users-pill-container", 682 + ); 683 + if (existingPill) { 684 + existingPill.remove(); 685 + } 661 686 } 662 687 }; 663 688 ··· 670 695 671 696 const observer = new MutationObserver(() => { 672 697 if (location.href !== lastUrl) { 698 + const oldUrl = lastUrl; 673 699 lastUrl = location.href; 674 - console.log("URL changed to:", location.href); 700 + console.log("URL changed from:", oldUrl, "to:", location.href); 701 + 702 + // Reset current profile DID 703 + currentProfileDid = null; 704 + profileVerifiers = []; 675 705 676 - // Remove any existing badges when URL changes 706 + // Clean up UI elements 677 707 const existingBadge = document.getElementById( 678 708 "user-trusted-verification-badge", 679 709 ); ··· 681 711 existingBadge.remove(); 682 712 } 683 713 684 - // Remove the pill container when URL changes 685 714 const existingPill = document.getElementById( 686 715 "trusted-users-pill-container", 687 716 ); ··· 690 719 } 691 720 692 721 // Check if we're on a profile page now 693 - checkCurrentProfile(); 722 + setTimeout(checkCurrentProfile, 500); // Small delay to ensure DOM has updated 694 723 } 695 724 }); 696 725