Last active
June 6, 2024 18:50
-
-
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"
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 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