Graphite "Go to Github" button

Add a "Go to Github" button on Graphite PRs

2023-01-16 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Graphite "Go to Github" button
// @namespace    https://app.graphite.dev
// @version      0.1
// @description  Add a "Go to Github" button on Graphite PRs
// @author       Topher Brown
// @match        https://app.graphite.dev/github/pr/*/*/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    addButton('Github PR')

    function getPrGithubUrl () {
        // Finds and returns the URL for this PR in Github
        // example match: https://app.graphite.dev/github/pr/ORG/REPO/PR_NUMBER/PR_TITLE
        var pathname = window.location.pathname
        var match = pathname.match(/[^/?]*[^/?]/g)
        var org = match[2]
        var repo = match[3]
        var prNumber = match[4]
        return `https://www.github.com/${org}/${repo}/pull/${prNumber}`
    }

    function addButton(text, onclick, cssObj) {
        cssObj = cssObj || {position: 'absolute', top: '11%', right:'4%', 'z-index': 3}
        let button = document.createElement('a'), btnStyle = button.style
        document.body.appendChild(button)
        button.innerHTML = text
        button.setAttribute("href", getPrGithubUrl())

        Object.keys(cssObj).forEach(key => btnStyle[key] = cssObj[key])
        return button
    }
})();