Graphite to GitHub Redirector

Redirects from graphite.dev GitHub PR page to GitHub's PR page

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Graphite to GitHub Redirector
// @namespace    http://tampermonkey.net/
// @version      0.1
// @license      MIT
// @description  Redirects from graphite.dev GitHub PR page to GitHub's PR page
// @author       Walker Hildebrand
// @match        https://app.graphite.dev/github/pr/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to extract information from the current URL
    function extractInfoFromURL() {
        const match = window.location.pathname.match(/^\/github\/pr\/([\w-]+)\/([\w-]+)\/(\d+)/);
        if (match) {
            const org = match[1];
            const repo = match[2];
            const prNumber = match[3];
            return { org, repo, prNumber };
        } else {
            console.log('Invalid URL format for GitHub PR.');
            return null;
        }
    }

    // Function to redirect to GitHub PR page
    function redirectToGitHub() {
        const info = extractInfoFromURL();
        if (info) {
            const { org, repo, prNumber } = info;
            const githubURL = `https://github.com/${org}/${repo}/pull/${prNumber}`;
            console.log('Redirecting to GitHub:', githubURL);
            window.location.href = githubURL;
        }
    }

    // Execute the redirect function when the page is loaded
    window.addEventListener('load', redirectToGitHub);
})();