Chat box exec

Executes apl code inside a chat box textarea!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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