Last active
          November 26, 2023 15:21 
        
      - 
      
 - 
        
Save mikenikles/60477869809092cb6b8e0300a6e2f638 to your computer and use it in GitHub Desktop.  
    Bookmarklets, use https://make-bookmarklets.com/ to add to your browser
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const get_issue_branch = () => { | |
| const number = document.querySelector("h1.gh-header-title span").textContent; | |
| const title = document.querySelector("h1.gh-header-title .js-issue-title").textContent; | |
| return `${number.substring(1)}-${title.toLowerCase().replaceAll(" ", "-").replaceAll(/[^-a-z]/g, "")}`; | |
| }; | |
| const get_pull_request_branch = () => document.querySelector(".commit-ref.head-ref a span").textContent; | |
| const copyBranchName = () => { | |
| if (window.location.host !== "github.com") return; | |
| let branch; | |
| const path = window.location.pathname; | |
| if (path.includes("issues/")) { | |
| branch = get_issue_branch(); | |
| } else if (path.includes("pull/")) { | |
| branch = get_pull_request_branch(); | |
| } | |
| alert(branch); | |
| }; | |
| copyBranchName(); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | window.open(window.location + "/port/5173", "_blank"); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const get_repo_url = () => { | |
| const regex = /^\/(?<owner>[^/]+)\/(?<repo>[^/]+)/; | |
| const { owner, repo } = window.location.pathname.match(regex).groups; | |
| return `${window.location.host}/${owner}/${repo}`; | |
| }; | |
| const get_issue_branch = () => { | |
| const number = document.querySelector("h1.gh-header-title span").textContent; | |
| const title = document.querySelector("h1.gh-header-title .js-issue-title").textContent; | |
| return `${number.substring(1)}-${title.toLowerCase().replaceAll(" ", "-").replaceAll(/[^-a-z]/g, "")}`; | |
| }; | |
| const get_pull_request_branch = () => document.querySelector(".commit-ref.head-ref a span").textContent; | |
| const open_devbox = () => { | |
| if (window.location.host !== "github.com") return; | |
| const repo_url = get_repo_url(); | |
| let branch; | |
| const path = window.location.pathname; | |
| if (path.includes("issues/")) { | |
| branch = get_issue_branch(); | |
| } else if (path.includes("pull/")) { | |
| branch = get_pull_request_branch(); | |
| } | |
| window.open(`https://devbox.sh/${repo_url}${branch ? `?branch=${branch}` : ""}`, "_blank"); | |
| }; | |
| open_devbox(); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment