Last active
June 11, 2024 13:23
-
-
Save Fizzyhex/64c0714cd7b60a18d01b2c275bbcda44 to your computer and use it in GitHub Desktop.
GitHub Repository Size Viewer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name GitHub Repository Size | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-06-11 | |
// @description View the size of public GitHub repositories. | |
// @author Fizzyhex | |
// @match https://github.com/*/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net | |
// @version 1.0.0 | |
// @downloadURL https://gist.githubusercontent.com/Fizzyhex/64c0714cd7b60a18d01b2c275bbcda44/raw/85f5a4b5b9d9118c4b3464b85758d9b4de5c4af6/.js | |
// @uploadURL https://gist.githubusercontent.com/Fizzyhex/64c0714cd7b60a18d01b2c275bbcda44/raw/85f5a4b5b9d9118c4b3464b85758d9b4de5c4af6/.js | |
// @grant none | |
// ==/UserScript== | |
// https://github.com/oculus-samples/Unity-CrypticCabinet | |
(function() { | |
'use strict'; | |
const DONT_OBSERVE_TAG = "repo-size-dont-observe"; | |
function check(target, observer) { | |
for (const child of target.querySelectorAll("span.color-fg-muted")) { | |
if (child.innerText === "Tags") { | |
if (child.classList.contains(DONT_OBSERVE_TAG)) { | |
continue; | |
} | |
// add 'dont-observe class to prevent infinite loop' | |
child.classList.add(DONT_OBSERVE_TAG); | |
let template = child.parentElement.parentElement.parentElement.parentElement; | |
let tagContainer = template.cloneNode(true); | |
let nameDisplay = tagContainer.querySelector("span.color-fg-muted"); | |
nameDisplay.innerText = "Size"; | |
template.parentElement.appendChild(tagContainer); | |
let fileSizeDisplay = tagContainer.querySelector("strong.color-fg-default"); | |
fileSizeDisplay.innerText = "..."; | |
console.log("makin request to","https://api.github.com/repos" + window.location.pathname) | |
fetch("https://api.github.com/repos" + window.location.pathname) | |
.then(result => result.json()) | |
.then(out => { | |
let size = out.size; | |
let fileSizeDisplay = tagContainer.querySelector("strong.color-fg-default"); | |
fileSizeDisplay.innerText = Math.round(size / 1024) + " MB"; | |
}) | |
.catch(error => console.log(error)); | |
} | |
} | |
} | |
const onMutation = (mutationList, observer) => { | |
for (const mutation of mutationList) { | |
if (mutation.type === 'childList') { | |
check(mutation.target, observer); | |
} | |
} | |
} | |
new MutationObserver(onMutation).observe(document, { childList: true, subtree: true }) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment