Skip to content

Instantly share code, notes, and snippets.

@tobimori
Last active June 6, 2020 07:59
Show Gist options
  • Save tobimori/e0831c988454cf38fc4d61b44cdca959 to your computer and use it in GitHub Desktop.
Save tobimori/e0831c988454cf38fc4d61b44cdca959 to your computer and use it in GitHub Desktop.
πŸ“ Userscript to enable profile READMEs on GitHub 🌈 Requires Tampermonkey
// ==UserScript==
// @name GitHub Meta Repository
// @namespace https://moeritz.io
// @version 1.1.0
// @description Enables profile READMEs on GitHub
// @author Tobias MΓΆritz
// @match *://github.com/*
// ==/UserScript==
(() => {
let url = window.location.href;
const getReadMe = async () => {
const container = Object.assign(document.createElement("div"), {
id: "readme",
style: "margin-top: 25px",
});
document
.querySelector(
"#js-pjax-container > div > div:nth-child(3) > div.position-relative"
)
.prepend(container);
try {
const response = await fetch([window.location.href, ".github"].join("/"));
const text = await response.text();
container.innerHTML = new DOMParser()
.parseFromString(text, "text/html")
.getElementById("readme").outerHTML;
url = window.location.href;
} catch (error) {
console.error(error);
}
};
const shouldFetch = () =>
!(window.location.href.split("/")[4] && window.location.href.split("?")[1]);
if (shouldFetch()) {
getReadMe();
}
new MutationObserver(() => {
if (
!document.querySelector("#readme") &&
url === window.location.href &&
shouldFetch()
) {
getReadMe();
}
}).observe(document, {
childList: true,
subtree: true,
});
})();
@tobimori
Copy link
Author

tobimori commented Jun 3, 2020

GitHub Meta Repository

πŸ“ Enable upcoming profile meta repositories. 🌈

follow @tobimori on Twitter


πŸ’– Preview

πŸ“ How To

Create a .github repository and add a README file - fill it with content as you wish!

πŸ‘₯ Credits

Thanks to @ljosberinn for refactoring :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment