Skip to content

Fix About-section injection and default-branch detection - #84

Merged
DervexDev merged 1 commit into
mainfrom
cursor/fix-injection-and-branch-detection-601c
Sep 15, 2026
Merged

DervexDev merged 1 commit into
mainfrom
cursor/fix-injection-and-branch-detection-601c

Conversation

@DervexDev

@DervexDev DervexDev commented Sep 15, 2026

Copy link
Copy Markdown
Owner

This PR cherry-picks two specific fixes from PR #82 by @dongguacute while preserving the existing custom ghloc backend architecture.

Changes Included

1. Fix GitHub About Section Injection

  • More resilient DOM detection: Uses normalize-space(.)="About" XPath instead of text()="About" to handle varying whitespace in GitHub's DOM
  • MutationObserver support: Waits for the About section if it's not present on initial page load (handles dynamic content loading)
  • Prevent widget duplication: Reuses the existing #github-loc element on re-injection instead of creating duplicates

2. Fix Default Branch Detection

  • Smart branch detection: Checks tree/blob URL path first, then falls back to branch selector UI elements
  • Stop assuming "main": Returns empty string when no branch is detected, allowing the backend to resolve the repository's actual default branch
  • Proper URL encoding: Encodes branch parameter in Stat link and makes it optional when empty

Changes NOT Included

The following changes from PR #82 were intentionally left out to preserve the existing architecture:

  • ❌ Public API host swap (ghloc.dev / ghloc.ifels.dev)
  • fetchLocalLoc / fetchPublicLoc split
  • ❌ In-browser GitHub tree+blob counting
  • isPublic parameter driving API choice
  • ❌ Optional Ghloc-Authorization header

Why This Approach?

The custom ghloc backend (ghloc-api.vercel.app / ghloc.vercel.app) already supports private repositories via the user's GitHub token with the salt-based authentication flow. Switching to the public API would break this functionality.

These cherry-picked fixes address real issues:

  • The About section injection was failing on some GitHub pages due to DOM changes
  • The extension was getting 404 errors on repositories with default branches other than "main"

Credits: DOM and branch detection improvements extracted from PR #82 by @dongguacute

Generated by Grok Bot.

- Improve About section detection using normalize-space XPath for better DOM compatibility
- Add MutationObserver to handle cases where About section loads after initial page paint
- Reuse existing #github-loc element to prevent widget duplication on re-injection
- Improve branch detection by checking tree/blob path and branch selector with fallbacks
- Stop defaulting to 'main' branch - use empty string to let backend resolve default
- Handle empty branch in API URL and Stat link to support default branch resolution
- Encode branch parameter in Stat link for proper URL formatting

Changes extracted from PR #82 by dongguacute, keeping only DOM/branch fixes
while maintaining the existing custom ghloc backend with token support.
@DervexDev
DervexDev merged commit 3e4c432 into main Sep 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants