Skip to content

fix: jianshu detection logic#175

Merged
timerring merged 1 commit into
mainfrom
dev
Feb 8, 2026
Merged

fix: jianshu detection logic#175
timerring merged 1 commit into
mainfrom
dev

Conversation

@timerring
Copy link
Copy Markdown
Member

Summary

This PR adds Jianshu (简书) platform detection support by implementing a new detector that uses Jianshu's settings API to retrieve user information.

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

  • Added new platform detector file packages/detection/src/platforms/jianshu.js
  • Implemented detectJianshuUser() function that fetches user data from Jianshu's settings API endpoint
  • Added import for convertAvatarToBase64 utility function
  • Registered Jianshu detector in packages/detection/src/detect.js
  • Added 'jianshu' platform to PLATFORM_DETECTORS map

Implementation Details

The Jianshu detector works as follows:

  1. Fetches https://www.jianshu.com/settings/basic.json with authenticated credentials
  2. Sends GET request with:
    • Method: GET
    • Credentials: include (to send cookies)
    • Headers: Accept application/json
  3. Validates the response status - returns { loggedIn: false } if request fails
  4. Parses the JSON response and validates the data structure
  5. Extracts username from json.data.nickname field
  6. Extracts avatar URL from json.data.avatar field
  7. If avatar URL contains 'jianshu.io', converts it to base64 format using convertAvatarToBase64() with referrer 'https://www.jianshu.com/'
  8. Returns the complete user information: { loggedIn: true, username, avatar }
  9. Catches and logs any errors, returning { loggedIn: false, error: e.message } on failure

Key features:

  • Uses Jianshu's official JSON API instead of HTML parsing for more reliable detection
  • Properly handles authentication through credentials
  • Converts external avatar URLs to base64 to avoid CORS and referrer issues
  • Comprehensive error handling with logging
  • Graceful degradation when user is not logged in

Manual Testing Steps

  1. Log in to Jianshu (www.jianshu.com) with a valid account
  2. Navigate to any Jianshu page
  3. Verify that the extension correctly detects your logged-in status
  4. Verify that your username (nickname) is correctly displayed
  5. Verify that your avatar image is correctly fetched and displayed
  6. Test with a non-logged-in session to verify it returns { loggedIn: false }
  7. Check browser console for proper logging messages

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
Copy Markdown
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 8495345 into main Feb 8, 2026
@timerring timerring deleted the dev branch February 8, 2026 17:08
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