Graphite to GitHub Redirector

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

  1. // ==UserScript==
  2. // @name Graphite to GitHub Redirector
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @license MIT
  6. // @description Redirects from graphite.dev GitHub PR page to GitHub's PR page
  7. // @author Walker Hildebrand
  8. // @match https://app.graphite.dev/github/pr/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to extract information from the current URL
  16. function extractInfoFromURL() {
  17. const match = window.location.pathname.match(/^\/github\/pr\/([\w-]+)\/([\w-]+)\/(\d+)/);
  18. if (match) {
  19. const org = match[1];
  20. const repo = match[2];
  21. const prNumber = match[3];
  22. return { org, repo, prNumber };
  23. } else {
  24. console.log('Invalid URL format for GitHub PR.');
  25. return null;
  26. }
  27. }
  28.  
  29. // Function to redirect to GitHub PR page
  30. function redirectToGitHub() {
  31. const info = extractInfoFromURL();
  32. if (info) {
  33. const { org, repo, prNumber } = info;
  34. const githubURL = `https://github.com/${org}/${repo}/pull/${prNumber}`;
  35. console.log('Redirecting to GitHub:', githubURL);
  36. window.location.href = githubURL;
  37. }
  38. }
  39.  
  40. // Execute the redirect function when the page is loaded
  41. window.addEventListener('load', redirectToGitHub);
  42. })();