PvPRP Auto-Download

Automatically downloads PvPRP texture packs for you

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==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);
	}
})();