Last active
September 28, 2024 10:43
-
-
Save BuonOmo/36bc425aeddae56fc36adfe70bd1c9e0 to your computer and use it in GitHub Desktop.
List all Github dependents of a project as JSON
This file contains hidden or 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
// Paste this in your developer console, in any tab | |
// of your repo (with insights available). Do it | |
// only if you trust me though. | |
// Go to 'dependants' tab if we're not there yet. | |
let url = window.location.href | |
if (!url.includes("/network/dependents")) { | |
url = url.match(/.*github\.com\/[^\/]+\/[^\/]+/)[0] + "/network/dependents" | |
} | |
let w = window.open(url, "_blank") | |
let result = [] | |
let loop = () => { | |
result.push( | |
...Array.from(w.document.querySelectorAll(".Box-row")).map((e) => { | |
let [name, stars, forks] = e.innerText.split("\n") | |
return { name, stars, forks } | |
}), | |
) | |
btns = Array.from(w.document.querySelectorAll("a.btn")) | |
btn = btns.find((e) => e.innerText.trim() == "Next") | |
w.close() | |
if (btn) { | |
w = window.open(btn.href, "_blank") | |
w.addEventListener("load", loop) | |
} else { | |
console.log(JSON.stringify(result)) | |
} | |
} | |
w.addEventListener("load", loop) | |
// Bonus: sort by stars and show top 10 | |
console.log( | |
JSON.stringify( | |
result | |
.sort((a, b) => b.stars - a.stars) | |
.slice(0, 10) | |
.map(({ name, stars }) => ({ name, stars })), | |
null, | |
"\t", | |
), | |
) | |
// Bonus: jq command alternative | |
// | |
// 'sort_by(.stars | tonumber) | reverse | .[0:10] | map({name, stars})' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment