template downloader

This script downloads templates from classic pants, shirts and t-shirts. You can download it to steal it(get a free fake copy) or remake it.

// ==UserScript==
// @name template downloader
// @description This script downloads templates from classic pants, shirts and t-shirts. You can download it to steal it(get a free fake copy) or remake it.
// @match *.roblox.com/catalog/*
// @run-at document-idle
// @version 0.0.1.20240716065244
// @namespace https://greasyfork.org/users/1205341
// ==/UserScript==

let fullURL = window.location.toString();
let typeContent;

let checkExist = setInterval(function() {
   typeContent = document.getElementById('type-content');
   if (typeContent) {
      console.log("'type-content' exists!");
      clearInterval(checkExist);
      main();
   }
}, 100);

function findJSON(url) {
    fetch(url)
        .then(response => response.text())
        .then(data => extractXML(data.slice(13,67)));
}

function extractXML(url) {
    var xhttp = new XMLHttpRequest();
    var parser, xmlDoc, imgURL;
    parser = new DOMParser();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            xmlDoc = parser.parseFromString(xhttp.responseText,"text/xml");
            imgURL = xmlDoc.getElementsByTagName("url")[0].childNodes[0].nodeValue.match(/(\d+)/)[0];
            openURL(imgURL);
        }
    };
    xhttp.open("GET", url, true);
    xhttp.send();
}

function openURL(ID) {
    window.open('https://assetdelivery.roblox.com/v1/asset/?id=' + ID, "_blank");
    alert('DONT FORGET TO ADD .PNG OR .WEBP TO THE DOWNLOADED FILE!!!')
}

function main() {
    if (typeContent.textContent.toLowerCase() === 'pants' || typeContent.textContent.toLowerCase() === 'shirt' || typeContent.textContent.toLowerCase() === 't-shirt') {
        let button = document.createElement('button');
        button.innerHTML = 'Download template';
        button.style.backgroundColor = 'black';
        button.style.color = 'gray';
        button.onclick = function() {
            var assetID = fullURL.match(/(\d+)/)[0];
            var URL = 'https://assetdelivery.roblox.com/v1/assetId/' + assetID;
            findJSON(URL);
        };
        document.getElementsByClassName('right')[0].appendChild(button);
    }
}