Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add links to explore GitHub repository in GitHub1s or CodeSandbox
// ==UserScript==
// @name GitHub Explorer
// @namespace https://seanmcp.com
// @version 0.1
// @description Add links to explore GitHub repository in GitHub1s or CodeSandbox
// @author Sean McPherson
// @match *://github.com/*/*
// @grant none
// ==/UserScript==
(function githubExplorer() {
"use strict";
try {
const id = "__githubExplorer";
if (document.getElementById(id)) {
return;
}
console.log("GitHub Explorer is running");
const label = document.querySelector("h1 .Label");
if (label && label.textContent === "Private") {
return;
}
const fileNavigation = document.querySelector(".file-navigation");
const spacer = fileNavigation.querySelector(".flex-auto");
const explorer = document.createElement("details");
explorer.id = id;
explorer.classList.add(
"details-overlay",
"details-reset",
"position-relative",
"d-block"
);
explorer.innerHTML = `
<summary class="btn ml-2">
<span>Explore</span>
<span class="dropdown-caret ml-1"></span>
</summary>
<ul class="dropdown-menu dropdown-menu-sw">
<li>
<a class="dropdown-item btn-link" href="${window.location.href.replace(
"github.com",
"github1s.com"
)}" target="_blank" rel="noreferrer" style="font-size:14px;">
GitHub1s
</a>
</li>
<li>
<a class="dropdown-item btn-link" href="${window.location.href.replace(
"github.com",
"githubbox.com"
)}" target="_blank" rel="noreferrer" style="font-size:14px;">
CodeSandbox
</a>
</li>
</ul>
`;
fileNavigation.insertBefore(explorer, spacer.nextSibling);
} catch (err) {
console.info("GitHub Explorer error:", err);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment