alexmangoman / Better JTV Captchas

// ==UserScript==
// @name        Better JTV Captchas
// @namespace   Violentmonkey Scripts
// @match       https://jungletv.live/
// @grant       none
// @version     1.0
// @author      alexmangoman
// @description Replaces 'human' with 'monkey' in the captcha alert box
// @license     GPL-3.0-or-later; https://www.gnu.org/licenses/gpl-3.0.txt
// @updateURL    https://openuserjs.org/src/scripts/alexmangoman/Better_JTV_Captchas.user.js
// ==/UserScript==


function changeCaptchaText() {
  //replace the text describing the captcha
  document.querySelector(".space-x-2 > div:nth-child(1) > h3:nth-child(1)").textContent = "Are you monkey?";
  document.querySelector("p.text-gray-600").textContent = "To receive rewards, confirm that you are monkey.";
  
  //hide the old button
  const oldButton = document.querySelector(".inline-flex");
  oldButton.style.display = "none";
  
  //it's easier to create the new button with the new text from a string like this
  let div = document.createElement('div');
  div.innerHTML = `<button type="submit" class="inline-flex w-20 float-right items-center justify-center py-2 px-4
            border border-transparent shadow-sm text-sm font-medium rounded-md text-white
            bg-yellow-600 hover:bg-yellow-700 focus:ring-yellow-500
            focus:outline-none focus:ring-2 focus:ring-offset-2  hover:shadow ease-linear transition-all duration-150" >I am monkey</button>`;
  let newButton = div.firstChild;
  
  //make the newbutton click the old button when clicked
  newButton.addEventListener("click", () => oldButton.click());
  
  //add the new button to the page
  oldButton.parentNode.appendChild(newButton);
}

//runs when a captcha thing is added to the page
const messageCallback = function(mutationsList, observer) {
  for (const mutation of mutationsList) {
    for (const addedNode of mutation.addedNodes) {
      
      changeCaptchaText()
      
    }
  }
}
const observer = new MutationObserver(messageCallback);

//only start looking out for captchas when the page is loaded
window.addEventListener("load", function () {
  observer.observe(document.querySelector("div.svelte-1ugbf0z:nth-child(1)"), {childList: true});
  
  //when the page loads, try to replace the text in captchas that have already appeared
  try {changeCaptchaText()} catch {}
})