Last active
June 6, 2020 07:59
-
-
Save tobimori/e0831c988454cf38fc4d61b44cdca959 to your computer and use it in GitHub Desktop.
π Userscript to enable profile READMEs on GitHub π Requires Tampermonkey
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 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, | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GitHub Meta Repository
π Enable upcoming profile meta repositories. π
π Preview
π How To
Create a
.github
repository and add aREADME
file - fill it with content as you wish!π₯ Credits
Thanks to @ljosberinn for refactoring :)