User:Thundercraft5/ModuleIDE.js

/* jshint undef:true */ $.when(	$.get('/load.php?mode=articles&only=styles&articles=User:Thundercraft5/ModuleIDE.css/active.css'),	$.get('/load.php?mode=articles&only=styles&articles=User:Thundercraft5/ModuleIDE.css'),	$.Deferred(def => { let int = setInterval( => {			if ($('#debugConsole').length) def.resolve, clearInterval(int);			}); }),	mw.loader.using([ 'mediawiki.ForeignApi', 'mediawiki.util', 'mediawiki.api' ]) ).then((activeStyles, styles) => {	let style = $(mw.util.addCSS(activeStyles[0]).ownerNode).remove;	mw.util.addCSS(styles[0]);	let oldX, oldY;	mw.hook('dev.cgnb.change').add(collapsed => { let interval = setInterval( => {			ace.editor.resize;		}, 0); ace.editor.interval = interval; });	$('.global-navigation').on('trasitionend', => { clearInterval(ace.editor.interval); delete ace.editor.interval; });	let bodyStyles = getComputedStyle(document.documentElement);	let height = bodyStyles.getPropertyValue("--codeEditor-height").trim;

ui: { $('.page-side-tools').append($(' ', { html: $(' ', {				class: "wds-icon",				html: $(" ", { "xlink:href": "#wds-icons-zoom-in", html: ' ', }),			}),			click { oldX = window.scrollX; oldY = window.scrollY; window.scrollTo(0, 0); $([ace.editor.container, $('.ui-resizable')[0]]).css({					position: "absolute",					height,				}); style.appendTo('head'); ace.editor.resize; },			title: "Enter Code Editor fullscreen", class: "page-side-tool codeeditor-fullscreen", "data-wds-tooltip": "Collapse", "data-wds-tooltip-position": "right", "data-tooltip-attached": 1, }));		$('.codeEditor-status-message').append($(' ', { for: "codeeditor-consoletoggle", class: "codeeditor-consoletoggle-label", title: "Toggle Debug Console [alt-shift-d]", accesskey: "d", }));		$('#mw-scribunto-console').before($(' ', { id: "codeeditor-consoletoggle", name: "codeeditor-consoletoggle", type: "checkbox", class: "wds-is-hidden", change { $('.mw-editform').toggleClass('codeeditor-console-open'); },		}));	}	events: { $(window).on('keyup', e => {			if (e.key.toLowerCase === "escape") {				window.scrollTo(oldX, oldY);				style.remove;				$([ace.editor.container, $('.ui-resizable')[0]]).css({ position: "relative", height, });				ace.editor.resize;			}		}); }	scrollStyles: { let styles = window.getComputedStyle($('#mw-scribunto-output')[0]); let borderHeight = parseInt(styles.borderTopWidth) + parseInt(styles.borderBottomWidth); $('#mw-scribunto-output')[0].addEventListener('scroll', function {			let $this = $(this);			if (-Math.floor(this.scrollTop) < 5) 				$this.addClass('scroll-bottom').removeClass('scroll-top');			else if (Math.ceil(Math.floor((-$this.scrollTop)) + borderHeight + $this.innerHeight) + 5 > this.scrollHeight) 				$this.addClass('scroll-top').removeClass('scroll-bottom');			else $this.removeClass('scroll-bottom').removeClass('scroll-top');		}, { passive: true }); }	// Action buttons var worker = new Worker('https://hypixel-skyblock.fandom.com/wiki/User:Thundercraft5/ModuleIDE.js/formatter-worker.js?action=raw&ctype=text/javascript');

$('.ve-fd-header__title').after($(' ', { class: "ModuleIDE-action-buttons", html: [ $(' ', {				class: "ModuleIDE-format action-button",				title: "Format the code in this Module",				click {					let text = ace.editor.getValue;					let curLine = ace.editor.getCursorPosition;					var options = {						lineWidth: 120,						indentCount: 1,						useTabs: true,					};					worker.postMessage({ type: "format", text, options });					worker.addEventListener('message', e => { ace.editor.setValue(e.data.text); ace.editor.clearSelection; ace.editor.moveCursorToPosition(curLine); ace.editor.scrollToLine(curLine.row, true, true, $.noop); }, { once: true });				},			}), $(' ', {				class: "ModuleIDE-openrefviewer action-button",				title: "Open the MediaWiki lua reference manual",				click {					var html;					var modal = new mw.libs.QDmodal('ModuleIDE-referenceviewer');					function setHtml {						modal.$content							.remove('div')							.end							.addClass('page-content mw-content-text')							.html(html);					}					modal.show({ title: "Extension:Scribunto/Lua reference manual", buttons: [{ text: "Back to top", handler { $("#ModuleIDE-referenceviewer > section").animate({ scrollTop: 0 }, "slow"); },						}, {							text: "Close", handler { modal.hide; },						}],					});					modal.$content.append($(' ', { class: 'mw-ajax-loader' }));					if (!html) {						new mw.ForeignApi('https://www.mediawiki.org/w/api.php', { anonymous: true, }).get({ action: "parse", page: "Extension:Scribunto/Lua reference manual", format: "json", }).then(d => { html = $(d.parse.text['*']); html.find('.mw-pt-languages, .ombox-notice, .mw-editsection').remove; html.find('#toc').parent.replaceWith(html.find('#toc')); html.find('pre[style="background-color:#fcc"]').css({ 'background-color': '' }); html.find('a').each(function {								var $this = $(this);								if (!$this.attr('href').startsWith('#')) {									$this.attr('target', '_blank');								}							}); setHtml; }).catch(console.warn);					} else {						setHtml;						null					}				}			}), ],	}));	let el = document.getElementById('mw-scribunto-output'); let $el = $(el); new MutationObserver((mutations, observer) => {		if (el.scrollHeight > el.clientHeight) $el.addClass('scroll-visible');		else $el.removeClass('scroll-visible');	}).observe(el, {		subtree: true,		childList: true,	}); });