DryadQuest Premium Emulation

Unlocks Premium Features through Emulation for DryadQuest

// ==UserScript==
// @name		DryadQuest Premium Emulation
// @namespace	https://greasyfork.org/en/scripts/512286-dryadquest-premium-emulation
// @version		2024-10-11|v0.2.0-1
// @description	Unlocks Premium Features through Emulation for DryadQuest
// @author		V.H.
// @copyright	V.H.
// @icon		https://icons.duckduckgo.com/ip2/dryadquest.com.ico
// @match		https://dryadquest.com/
// @grant		unsafeWindow
// @grant		GM_log
// @run-at		document-start
// @tag			hacks
// @license		MIT
// @connect		self
// @connect		tools.vallenh.serv00.net
// @webRequest	[{"selector":"/api/token","action":{"redirect":"data:application/json,{\"user\":{\"_id\":\"6s9a6t9a6n9\",\"name\":\"HaXor\",\"patronId\":666,\"patronTier\":666,\"privTier\":666,\"privilege\":666}}"}}]
// @webRequest	[{"selector":"/premium","action":{"redirect":"/"}}]
// @antifeature	Routes traffic through a mock-api
// ==/UserScript==

/**
 * This game is very well-developed, congratulations to the developer.
 * I'm very sorry for making this (futile) script, I hope it doesn't harm you.
 * 
 * If you edit & redistribute this script, please credit the author.
 */

"use strict";

const	orig		= {
	xhr:	XMLHttpRequest.prototype.open,
},		cbu			= "https://tools.vallenh.serv00.net/api/hacks/dryadquest/main?cb=";

XMLHttpRequest.prototype.open	= function open(...args) {
	if (args.length >= 2 && args[1].endsWith("/api/token"))
		args[1]		= "https://tools.vallenh.serv00.net/api/hacks/dryadquest/patronapi";	//mock api to return fixed fake premium account
	
	GM_log("XHR:\t" + args.join(", "));
	
	return orig.xhr.call(this, ...args);
}; //open

function dynload() {
	window.stop();
	document.open();
	document.write("PLEASE WAIT...");
	document.close();
	
	getPage("/").then(res => {
		res				= Document.parseHTMLUnsafe(res);
		
		const	main	= res.querySelector('script[src^="main."]');
		
		main.src		= encodeURI(cbu + encodeURIComponent(new URL(main.src, location.href + "data/").href));
		
		document.documentElement.innerHTML	= res.documentElement.getHTML();
		setTimeout(updateScripts, 1000);
	});
} //dynload

dynload();

function updateScripts() {
	for (let script of document.scripts) {
		if (script.hasAttribute("data-loaded"))
			continue;
		
		const	s			= document.createElement("script");
		
		s.id				= script.id;
		if (script.crossorigin)
			s.crossorigin	= script.crossorigin;
		if (script.type)
			s.type			= script.type;
		if (script.src)
			s.src			= script.src;
		if (script.text)
			s.text			= script.text;
		if (script.hasAttribute("defer"))
			s.setAttribute("defer", "");
		if (script.hasAttribute("async"))
			s.setAttribute("async", "");
		
		s.setAttribute("data-loaded", "");
		
		script.replaceWith(s);
	}
} //updateScripts

async function getPage(sc = "/") {
	let			out		= "";
	
	try {
		const	req		= await fetch(sc);
		
		out				= await req.text();
	} catch(e) {
		console.error(e);
	}
	
	return out;
} //getPage