Skip to content

Instantly share code, notes, and snippets.

@terminalnode
Created September 29, 2023 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terminalnode/c595dad7b0f5890a9e48cc2f9ad698b6 to your computer and use it in GitHub Desktop.
Save terminalnode/c595dad7b0f5890a9e48cc2f9ad698b6 to your computer and use it in GitHub Desktop.
Spicy JavaScript on Github
// ==UserScript==
// @name Spicy JavaScript on GitHub
// @namespace https://github.com
// @description Replace TypeScript with Spicy JavaScript on GitHub pages
// @version 1.0
// @grant none
// @include https://github.com/*
// ==/UserScript==
(function() {
'use strict';
const replaceText = (element, findText, replaceText) => {
for (let node of element.childNodes) {
if (node.nodeType === Node.TEXT_NODE) {
if (node.textContent.includes(findText)) {
node.textContent = node.textContent.replace(findText, replaceText);
}
} else if (node.nodeType === Node.ELEMENT_NODE) {
replaceText(node, findText, replaceText);
}
}
};
const main = () => {
// For the main programming language label
for (let elem of document.querySelectorAll('span[itemprop="programmingLanguage"]')) {
replaceText(elem, 'TypeScript', 'Spicy JavaScript');
}
// For the language statistics
for (let elem of document.querySelectorAll('span[aria-label*="TypeScript"]')) {
elem.setAttribute('aria-label', elem.getAttribute('aria-label').replace('TypeScript', 'Spicy JavaScript'));
}
// For the language list below statistics
for (let elem of document.querySelectorAll('span.color-fg-default.text-bold')) {
replaceText(elem, 'TypeScript', 'Spicy JavaScript');
}
};
// Run initially
main();
// Listen for changes in the DOM
new MutationObserver(main).observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment