Chat box exec

Executes apl code inside a chat box textarea!

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

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 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.

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

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         Chat box exec
// @version      1.0
// @description  Executes apl code inside a chat box textarea!
// @namespace    http://tampermonkey.net/
// @grant        GM_xmlhttpRequest
// @grant        GM_listValues
// @match        https://chat.stackexchange.com/*
// @run-at       document-start
// ==/UserScript==

window.addEventListener('DOMContentLoaded', (event) => {
	let bContainer = document.getElementById("chat-buttons");
	let tmp = document.createElement("div");
	tmp.innerHTML = "<button id=\"apl-execute\" class=\"button\" accesskey=\"x\">⍎</button>";
	bContainer.appendChild(tmp.firstChild);
	let exButton = document.getElementById("apl-execute");
	exButton.addEventListener('click', function (e) {
		exButton.classList.add("disabled");
		let field = document.getElementById("input");
		let code = field.value.split("\n")[0].trim();
		let output;
		console.log(code);
		let request = new XMLHttpRequest();
		request.open("POST", "https://tryapl.org/Exec", true);
		request.setRequestHeader("Content-Type", "application/json; charset=utf-8")
		request.send(JSON.stringify(["", 0, "", code]));
		request.onreadystatechange = function () {
			if (request.readyState === 4) {
				if (request.status === 200) {
					let result = JSON.parse(request.responseText)[3];
					result.unshift("      " + code);
					field.value = result.map(x => "    " + x).join("\n");
					field.focus();
					exButton.classList.remove("disabled");
				}
			}
		}
	});
});