Storable Convar

Save and automatically apply the options what you set in Diep.io console

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Storable Convar
// @namespace    https://github.com/No-Eul
// @version      1.0
// @description  Save and automatically apply the options what you set in Diep.io console
// @author       NoEul
// @license      MIT License - https://github.com/No-Eul/scripts/raw/master/LICENSE.txt
// @source       https://github.com/No-Eul/scripts
// @supportURL   https://github.com/No-Eul/scripts/issues
// @match        *://diep.io/*
// @icon         https://diep.io/favicon.ico
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_listValues
// @grant        GM_deleteValue
// ==/UserScript==

function getInputObject() {
	return new Promise(resolve => {
		if (unsafeWindow.input) resolve(unsafeWindow.input);

		let interval = setInterval(() => {
			if (unsafeWindow.input) {
				clearInterval(interval);
				resolve(unsafeWindow.input);
			}
		});
	});
}

function modifyStoringConvar() {
	document.getElementById("textInput")
		.addEventListener("change", event => {
			let pair = event.target.value.split(/\s+/g);
			if (unsafeWindow.input.get_convar(pair[0]))
				GM_setValue(pair[0], pair[1]);
		});

	let set_convar = unsafeWindow.input.set_convar;
	unsafeWindow.input.set_convar = function (key, value) {
		if (unsafeWindow.input.get_convar(key))
			GM_setValue(key, value);
		set_convar.apply(unsafeWindow.input, arguments);
	}

	let execute = unsafeWindow.input.execute;
	unsafeWindow.input.execute = function (command) {
		let pair = command.split(/\s+/g);
		if (unsafeWindow.input.get_convar(pair[0]))
			GM_setValue(pair[0], pair[1]);
		execute.apply(unsafeWindow.input, arguments);
	}
}

(function init() {
	getInputObject()
		.then(modifyStoringConvar)
		.then(() => GM_listValues().forEach(key => unsafeWindow.input.set_convar(key, GM_getValue(key))));
})();