Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: medium avatar detection#173

Merged
timerring merged 1 commit intomainfrom
dev
Feb 8, 2026
Merged

fix: medium avatar detection#173
timerring merged 1 commit intomainfrom
dev

Conversation

@timerring
Copy link
Member

Summary

This PR fixes the Medium avatar detection mechanism by switching from HTML parsing to JSON data extraction.

Related Issue

N/A

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • Other (please describe):

Changes Made

  • Removed the old avatar extraction method that parsed HTML img tags using regex patterns based on shortened usernames
  • Implemented new avatar extraction logic that searches for imageId in JSON data embedded in the HTML
  • The new method extracts imageId from JSON objects containing user information and constructs the avatar URL using Medium's CDN format: https://miro.medium.com/v2/resize:fill:64:64/{imageId}
  • Supports two JSON structure patterns: imageId before username and username before imageId

Implementation Details

The avatar detection now works as follows:

  1. Extract username from the profile URL
  2. Search for JSON data in the HTML that contains both imageId and username fields
  3. Use regex to match either pattern: "imageId":"xxx"..."username":"user" or "username":"user"..."imageId":"xxx"
  4. Construct the avatar URL using the extracted imageId
  5. Return empty string if no match is found

This approach is more reliable as it extracts data from the structured JSON embedded in Medium's HTML response rather than parsing HTML elements.

Manual Testing Steps

  1. Navigate to a Medium page where you are logged in with a valid profile
  2. Verify that the avatar is correctly detected and displayed
  3. Test with different Medium profiles to ensure compatibility

Screenshots/Videos

If applicable, add screenshots or videos to demonstrate the changes

Reviewer Checklist

For reviewers to verify before merging:

  • Code follows the project's style guidelines
  • Changes are well-documented
  • No breaking changes or clearly documented if present

@timerring timerring self-assigned this Feb 8, 2026
@timerring timerring added the enhancement New feature or request label Feb 8, 2026
Copy link
Member Author

@timerring timerring left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@timerring timerring merged commit 4f3b978 into main Feb 8, 2026
@timerring timerring deleted the dev branch February 8, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant