// ==UserScript==
// @name GitHub Enhanced Repo Buttons
// @version 1.0
// @description Enhances GitHub repository pages with buttons to view active forks and open the repo in a VSCode-like interface.
// @license MIT
// @author Mobile46
// @match https://github.com/*/*
// @icon https://www.google.com/s2/favicons?domain=github.com&sz=32
// @namespace https://greasyfork.org/users/1466082
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
function isValidRepoPage() {
const path = window.location.pathname.split('/');
return path.length >= 3 && !path[3];
}
function getRepoInfo() {
const path = window.location.pathname.split('/');
if (path.length >= 3) {
return {
owner: path[1],
repo: path[2]
};
}
return null;
}
function addButtons() {
if (!isValidRepoPage()) {
return;
}
const repoInfo = getRepoInfo();
if (!repoInfo) {
console.log('Could not extract repo info');
return;
}
const actionsArea = document.querySelector('.pagehead-actions');
if (!actionsArea) {
console.log('Actions area not found');
return;
}
const forksLi = document.createElement('li');
const forksButton = document.createElement('a');
forksButton.className = 'btn-sm btn';
forksButton.setAttribute('data-view-component', 'true');
forksButton.href = `https://techgaun.github.io/active-forks/index.html#${repoInfo.owner}/${repoInfo.repo}`;
forksButton.target = '_blank';
forksButton.rel = 'noopener noreferrer';
forksButton.innerHTML = `
Active Forks
`;
forksLi.appendChild(forksButton);
const vscodeLi = document.createElement('li');
const vscodeButton = document.createElement('a');
vscodeButton.className = 'btn-sm btn';
vscodeButton.setAttribute('data-view-component', 'true');
vscodeButton.href = `https://github1s.com/${repoInfo.owner}/${repoInfo.repo}`;
vscodeButton.target = '_blank';
vscodeButton.rel = 'noopener noreferrer';
vscodeButton.innerHTML = `
View in VSCode
`;
vscodeLi.appendChild(vscodeButton);
actionsArea.appendChild(forksLi);
actionsArea.appendChild(vscodeLi);
}
addButtons();
const observer = new MutationObserver(() => {
if (document.querySelector('.pagehead-actions') &&
!document.querySelector('a[href*="techgaun.github.io/active-forks"]') &&
!document.querySelector('a[href*="github1s.com"]')) {
addButtons();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
})();