diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..0a5da79 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,45 @@ +name: Publish to Chrome Web Store + +on: + release: + types: [published] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Create extension zip + run: | + zip -r extension.zip \ + manifest.json \ + content.js \ + icon16.png \ + icon48.png \ + icon128.png + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: extension + path: extension.zip + + publish: + needs: build + runs-on: ubuntu-latest + steps: + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: extension + + - name: Upload to Chrome Web Store + uses: mnao305/chrome-extension-upload@v5.0.0 + with: + file-path: extension.zip + extension-id: ${{ secrets.CHROME_EXTENSION_ID }} + client-id: ${{ secrets.CHROME_CLIENT_ID }} + client-secret: ${{ secrets.CHROME_CLIENT_SECRET }} + refresh-token: ${{ secrets.CHROME_REFRESH_TOKEN }} diff --git a/README.md b/README.md index 7e89323..461c843 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ A Chrome extension that adds useful modifications to the GitHub pull request interface. +https://chromewebstore.google.com/detail/github-ui-mods/fnmaeopgcjnpkimkknpeoimkdjaahfla + +![Screenshot](screenshot.png) + ## Features ### 1. Copy PR Link Button diff --git a/content.js b/content.js index 9e25f83..f8edd9d 100644 --- a/content.js +++ b/content.js @@ -4,101 +4,107 @@ (function() { 'use strict'; - // Feature 1: Add "Copy PR Link" button next to PR title + // Feature 1: Add "Copy PR Link" button next to the copy branch button function addCopyPRLinkButton() { - // Find the PR title element - const titleElement = document.querySelector('.js-issue-title'); - if (!titleElement) { - return false; - } - // Check if button already exists if (document.getElementById('copy-pr-link-btn')) { return true; } - // Create the button + // Find the copy branch button (IconButton with octicon-copy next to branch name) + // Look for the button that has a tooltip about copying the head branch name + // The button is inside .prc-PageHeader-Description-w-ejP (non-sticky header) + const headerDescription = document.querySelector('.prc-PageHeader-Description-w-ejP'); + let copyBranchBtn = null; + if (headerDescription) { + copyBranchBtn = headerDescription.querySelector('button.prc-Button-IconButton-fyge7 .octicon-copy')?.closest('button'); + } + // Fallback to legacy selector + if (!copyBranchBtn) { + copyBranchBtn = document.querySelector('.gh-header-meta clipboard-copy'); + } + if (!copyBranchBtn) { + return false; + } + + // Get PR title for copying - try new React header first, then legacy + const titleElement = document.querySelector('.prc-PageHeader-Title-p0Mgh .markdown-title') || + document.querySelector('h1 .markdown-title') || + document.querySelector('.js-issue-title'); + if (!titleElement) { + return false; + } + + // Create the button - match the style of the existing IconButton const button = document.createElement('button'); button.id = 'copy-pr-link-btn'; - button.className = 'btn btn-sm'; - button.style.marginLeft = '8px'; - button.style.verticalAlign = 'middle'; + button.type = 'button'; + // Use the same class as the copy branch button for consistent styling + button.className = 'prc-Button-ButtonBase-9n-Xk prc-Button-IconButton-fyge7'; + button.setAttribute('data-loading', 'false'); + button.setAttribute('data-no-visuals', 'true'); + button.setAttribute('data-size', 'small'); + button.setAttribute('data-variant', 'invisible'); + button.title = 'Copy PR link'; + button.style.cssText = 'margin-left: 4px;'; button.innerHTML = ` -