Skip to content

Instantly share code, notes, and snippets.

@nzbr
Last active June 6, 2024 18:50
Show Gist options
  • Save nzbr/fa6839812d04fe8657db3c8282b260a6 to your computer and use it in GitHub Desktop.
Save nzbr/fa6839812d04fe8657db3c8282b260a6 to your computer and use it in GitHub Desktop.
User script to replace the text on the "Raw" button on GitHub with "Rawr"
// ==UserScript==
// @name Show Rawr
// @namespace Violentmonkey Scripts
// @match https://github.com/**
// @match https://gist.github.com/**
// @match https://codeberg.org/**
// @grant none
// @version 1.0
// @author nzbr
// @description Replaces the Raw button on GitHub with Rawr
// ==/UserScript==
// NOTE: This is (unfortunately) really unoptimized and will make your GitHub experience painfully slow
const retry = 10;
const interval = 1000;
const changeButtonText = (count) => () => {
const query = document.querySelectorAll('[data-testid=raw-button] [data-component=text], div.file-actions a span.Button-label, .file-header-right a.button');
if (query.length == 0) {
if (count < interval / retry) { // othervise a new cycle will be started anyway
setInterval(changeButtonText(count + 1), retry);
}
} else {
query.forEach((el) => {
if (el.innerText === 'Raw' || (el.href ?? '').includes('/raw/')) {
el.innerText = 'Rawr';
}
})
}
}
setInterval(changeButtonText(0), interval); // retry every $interval, because the script won't re-run on SPAs
changeButtonText(0); // start one right away
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment