Storable Convar

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

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.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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