PvPRP Auto-Download

Automatically downloads PvPRP texture packs for you

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         PvPRP Auto-Download
// @namespace    https://tampermonkey.net/
// @version      0.31
// @description  Automatically downloads PvPRP texture packs for you
// @author       darraghd493 (github.com/darraghd493)
// @match        *://*.pvprp.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=pvprp.com
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
	"use strict";

	var removedYoutubeElement = false;
	var clickedDownloadElement = false;

	// Initialise the script
	log("Loading pvprp Auto Download.js");

	// Wait for the website to load
	log("Waiting for website to load");

	var parentInterval = setInterval(function () {
		if (document.readyState === "complete") {
			// Get the subscribe element by its div
			var subscribeDiv = document.getElementById("fullstep-1");

			// Check if it has any <a> tags
			if (subscribeDiv != null && subscribeDiv.getElementsByTagName("a") != null && subscribeDiv.getElementsByTagName("a").length && !removedYoutubeElement) {
				var subscribeElement = subscribeDiv.getElementsByTagName("a")[0];
				log("Found subscribe element: " + subscribeElement);

				// Remove the href attribute
				if (subscribeElement && subscribeElement.tagName.toLowerCase() === "a") {
					subscribeElement.removeAttribute("href");
					log("Removed href attribute from subscribe element");

					subscribeElement.click();
					log("Clicked subscribe element");

					removedYoutubeElement = true;
				}
			}

			// Create an interval and search for the download link
			if (!clickedDownloadElement) {
				var downloadInterval = setInterval(function () {
					// Go through all hrefs and find the one that contains "/packs/"
					var elements = document.querySelectorAll("a");

					for (var i = 0; i < elements.length; i++) {
						var element = elements[i];
						var href = element.getAttribute("href");
						if (href) {
							if (href.startsWith("assets/packs") && !clickedDownloadElement) { // Double check to prevent duplicate downloods
								log("Found download link: " + href);

								// Click the element
								element.click();
								clickedDownloadElement = true;

								// Clear the intervals
								clearInterval(parentInterval);
								clearInterval(downloadInterval);
								break;
							}
						}
					}
				}, 100);
			}
		}
	}, 100);

	// Functions
	function log(str) {
		console.log("%c%s", "color: red; font: 1.2rem/1 Tahoma;", str);
	}
})();