您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Add a button to go from app.graphite.dev to github.com
// ==UserScript== // @name Graphite GitHub button // @description Add a button to go from app.graphite.dev to github.com // @match https://app.graphite.dev/* // @version 0.3 // @run-at document-start // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @grant none // @license MIT // @namespace https://app.graphite.dev // ==/UserScript== const PATH_REGEX = /^\/github\/pr\/(\w+)\/(\w+)\/(\d+).*$/; const SELECTOR = '[class^="PullRequestTitleBar_container_"] > div:nth-child(1) > div:nth-child(2)'; const addButton = (toolbar) => { const [_, org, repo, pr] = window.location.pathname.match(PATH_REGEX); const gitHubLink = `https://github.com/${org}/${repo}/pull/${pr}`; if (document.getElementById("gitHubLink") != null) { return; } const anchorEl = document.createElement("a"); anchorEl.setAttribute("id", "gitHubLink"); anchorEl.setAttribute("href", gitHubLink); anchorEl.setAttribute( "style", "background: #f0f0f3; padding: 6px; border-radius: 4px; flex-shrink: 0;" ); anchorEl.appendChild(document.createTextNode("Open in GitHub")); toolbar.appendChild(anchorEl); }; const toolbarObserver = new MutationObserver((_, observer) => { const toolbar = document.querySelector(SELECTOR); if (toolbar) { observer.disconnect(); addButton(toolbar); } }); let lastPathname; const routeChangeObserver = new MutationObserver(() => { const { pathname } = window.location; if (pathname !== lastPathname) { lastPathname = pathname; if (pathname.match(PATH_REGEX)) { toolbarObserver.observe(document.body, { childList: true, subtree: true, }); } } }); routeChangeObserver.observe(document.body, { childList: true, subtree: true });