User:Thundercraft5/common.js

/** User:Thundercraft5/common.js * Licensed Under CC-BY-SA-3.0. * * =====Contents===== * *Personal Adjustments *	*Upper icons adjustment *	*Top Menu *	* * * Major Scripts *	*blockListLookup *	*rangeBlockLinks *	*blockListTools

/* global mw, test, mediaWiki, ace */ /* jshint esversion: 5, forin: true, immed: true, indent: 4, latedef: false, newcap: true, noarg: true, undef: true, undef: true, unused: true, browser: true, jquery: true, onevar: true, eqeqeq: true, multistr: true, maxerr: 999999

//#==================================================# //# PERSONAL ADJUSTMENTS //#==================================================# window.dontWantRoleSpecificJS = true; mw.requestIdleCallback = function(callback) { setTimeout(callback, 0); }; mw.requestIdleCallbackInternal = mw.requestIdleCallback;

window.test = new Proxy({	test: "$", }, {	deleteProperty: function(o, k) {		throw new TypeError(o, k);	}, }); try { delete test.test; } catch (e) { console.warn(e); } mw.loader.using('mediawiki.Uri', function {	if (mw.config.get('wgPageName').startsWith('Special:Comment')) {		var split = mw.config.get('wgPageName').split('/').slice(1);		if (!split.length) return;		window.location.replace(new mw.Uri('/wiki/' + split[0] + "?" + $.param({ commentId: split[1], replyId: split[2] })));	} });

$(document.body).on('click', 'ul[class^="ActionDropdown_list__"] > li:first-of-type, [class^="Comment_wrapper__"]', function(e) {	if (e.ctrlKey) {		if ($('[class^="EditorForm_editor-form"]').length) return;		var el = $(e.target).parents('[class^="Comment_wrapper__"]');		var replyId = el.attr('data-reply-id');

window.navigator.clipboard.writeText('comment"); } });

document.addEventListener('keydown', function(e) {	var key = e.key.toLowerCase;	if (key === "l" && e.ctrlKey) {		e.preventDefault;		document.querySelector('.oo-ui-iconElement-icon.oo-ui-icon-gotoLine').click;	} else if (key === "s" && e.ctrlKey) {		e.preventDefault;		document.querySelector('.oo-ui-iconElement-icon.oo-ui-icon-pilcrow').click;	} });

// Wiki button customization $('div.wds-community-header__wiki-buttons > .createpage') .off('click') .html($(' ', { class: "wds-icon top-note__message-icon wds-icon-small", html: $(' ', {				"xlink:href": "#wds-icons-comment-small",			}), }))		.attr('href', mw.util.getUrl('Special:SociaActivity')) .removeClass('createpage') .attr('title', 'View the wiki\'s social activity') .addClass('wds-button-socialactivity-link') .remove .insertAfter('.wds-community-header__wiki-buttons > a:first-child') .next .clone .html($(' ', { class: "wds-icon wds-icon-small", html: $(' ', {					"xlink:href": "#wds-icons-poll",				}), }))			.attr('title', 'View the wiki\'s abuse log') .attr('href', mw.util.getUrl('Special:AbuseLog')) .addClass('wds-button-abuselog-link') .insertAfter('.wds-button-socialactivity-link');

var pagePathname = mw.config.get('wgArticlePath').replace('$1', ''), sitename = mw.config.get('wgSiteName'), // jshint ignore:line userGroups = mw.config.get('wgUserGroups'), // jshint ignore:line namespace = mw.config.get("wgNamespaceNumber"), // jshint ignore:line pagename = mw.config.get('wgPageName'), // jshint ignore:line wikiUrl = mw.config.get('wgServer').replace(/https?:\/\//g, ''), // jshint ignore:line server = mw.config.get('wgServer'); // jshint ignore:line

var inter = setInterval(function {	if (namespace !== 828) {		clearInterval(inter);		return;	}	if ($('.ace_content').length && namespace === 828) {		clearInterval(inter);	} else {		return;	}	var histList = [''], 		histPos = 0, 		question, input, output, $spinner, 		sessionContent = null, 		sessionKey = null, 		pending = false, 		clearNextRequest = false,		debugConsole,		session;	function refocus { // jshint ignore:line		debugConsole.blur;		debugConsole.focus;	}	function initConsole { // jshint ignore:line		input = document.getElementById('mw-scribunto-input');		output = document.getElementById('mw-scribunto-output');		$spinner = $.createSpinner({ size: 'small', type: 'block', id: "consoleSpinner", });		println(mw.msg('scribunto-console-intro'), 'mw-scribunto-message');		debugConsole = ace.edit('debugConsole');		ace.console = {};		ace.console.editor = debugConsole;		session = debugConsole.session;		debugConsole.resize;		debugConsole.getSession.setMode('ace/mode/lua');		session.on('change', function { var size = debugConsole.session.getScreenLength * debugConsole.renderer.lineHeight + debugConsole.renderer.scrollBar.getWidth; $('#debugConsole').css('height', size); debugConsole.resize; });		debugConsole.setOptions({ enableSnippets: true, enableLiveAutocompletion: true, enableBasicAutocompletion: true, });		// Toggle enableLiveAutocompletion (Ctrl-S)		debugConsole.commands.addCommand({ name: 'toggleAutocomplete', bindKey: {win: 'Ctrl-S'}, exec: function(editor) { var on = editor.$enableLiveAutocompletion === true; editor.setOptions({					enableLiveAutocompletion: !editor.$enableLiveAutocompletion,				}); if (on) editor.completer.detach; }		});		// Clear Console (Ctrl-Alt-C)		debugConsole.commands.addCommand({ name: 'clearConsole', bindKey: {win: 'Ctrl-Alt-C'}, exec: function { clearOutput; }		});		// Clear Console State (Ctrl-Shift-C)		debugConsole.commands.addCommand({ name: 'clearConsoleState', bindKey: {win: 'Ctrl-Shift-C'}, exec: function { onClearClick; }		});		// Replace Spaces (Ctrl-Shift-S)		debugConsole.commands.addCommand({ name: 'replaceSpaces', bindKey: {win: 'Ctrl-Shift-S'}, exec: function(editor) { var pos = editor.getCursorPosition; editor.find('	'); editor.replaceAll('\t'); editor.moveCursorToPosition(pos); }		});

session.on('focus', inputFocus); // Submit (Ctrl-Enter) debugConsole.commands.addCommand({			name: 'consoleSubmit',			bindKey: {win: 'Ctrl-Enter'},			exec: function {				go;			}		}); // Go To previous history entry (UpArrow) debugConsole.commands.addCommand({			name: 'navigateUp',			bindKey: { win: 'Up' },			exec: function(editor) {				if (caretInFirstLine) {					hist('up');				} else {					// If cursor is not in first posistion, dont suppress default behavior					editor.navigateUp;				}			},		}); // Go To next history entry (DownArrow) debugConsole.commands.addCommand({			name: 'navigateDown',			bindKey: { win: 'Down' },			exec: function(editor) {				if (caretInLastLine) {					hist('down');				} else {					// If cursor is not in last posistion, dont suppress default behavior					editor.navigateDown;				}			},		}); }	function inputFocus { // jshint ignore:line if (sessionContent === null) { return; }		if (clearNextRequest) { return; }		if (getContent !== sessionContent) { printClearBar('scribunto-console-cleared'); clearNextRequest = true; }	}	function caretInFirstLine { // jshint ignore:line return debugConsole.getCursorPosition.row === 0; }	function caretInLastLine { // jshint ignore:line return debugConsole.getCursorPosition.row+1 === debugConsole.session.getLength; }	function println(s, type) { // jshint ignore:line var newdiv; if ((s = String(s))) { newdiv = document.createElement('div'); newdiv.appendChild(document.createTextNode(s)); newdiv.className = type; output.appendChild(newdiv); return newdiv; }	}	function printClearBar(msg) { // jshint ignore:line $(' ').attr('class', 'mw-scribunto-clear').text(mw.msg(msg)).appendTo(output); }	function hist(direction) {// jshint ignore:line var L = histList.length; var session = debugConsole.session; if (L === 1) { return; }		if (direction === 'up') { if (histPos === L - 1) { histList[histPos] = session.getValue; }			if (histPos > 0) { histPos--; setTimeout(function {					session.setValue('');					session.setValue(histList[histPos]);				}, 0); }		} else { if (histPos < L - 1) { histPos++; session.setValue(histList[histPos]); } else if (histPos === L - 1) { if (session.getValue) { histList[histPos] = session.getValue; ++histPos; session.setValue(''); }			}		}	}	function printQuestion(q) { // jshint ignore:line println(q.match(/^=/) ? q.replace(/^=/, '') : q, 'mw-scribunto-input' + (q.match(/^=/) ? ' exp' : '')); }	function printError(er) { // jshint ignore:line var lineNumberString; if (er.name) { lineNumberString = (er.lineNumber !== undefined) ? (' on line ' + er.lineNumber + ': ') : ': '; println(er.name + lineNumberString + er.message, 'mw-scribunto-error'); } else { println(er, 'mw-scribunto-error'); }	}	function setPending { // jshint ignore:line pending = true; debugConsole.setOptions({			readOnly: true,		}); $spinner.insertBefore($('#debugConsole').parent); }	function clearPending { // jshint ignore:line $spinner.remove; pending = false; debugConsole.setOptions({			readOnly: false,		}); }	function go { // jshint ignore:line var params, api, content, sentContent; if (pending) { return; }		question = debugConsole.session.getValue; if (question === '') { return; }		histList[histList.length - 1] = question; histList[histList.length] = ''; histPos = histList.length - 1; debugConsole.session.setValue(''); setTimeout(function {			debugConsole.session.setValue('');		}, 0); printQuestion(question); params = { action: 'scribunto-console', title: mw.config.get('wgPageName'), question: question };		content = getContent; sentContent = false; if (!sessionKey || sessionContent !== content) { params.clear = true; params.content = content; sentContent = true; }		if (sessionKey) { params.session = sessionKey; }		if (clearNextRequest) { params.clear = true; clearNextRequest = false; }		api = new mw.Api; setPending; api.post(params).done(function(result) {			if (result.sessionIsNew ===  && !sentContent) {				printClearBar('scribunto-console-cleared-session-lost');				sessionContent = null;				clearPending;				debugConsole.setValue(params.question);				go;				return;			}			sessionKey = result.session;			sessionContent = content;			if (result.type === 'error') {				$(' ')					.addClass('mw-scribunto-error')					.html(result.html)					.appendTo(output);			} else {				if (result.print !== ) {					println(result.print, 'mw-scribunto-print');				}				if (result.return !== '') {					println(result.return, 'mw-scribunto-normalOutput');				}			}			clearPending;			setTimeout(refocus, 0);		}).fail(function(code, result) {			if (result.error && result.error.info) {				printError(result.error.info);			} else if (result.exception) {				printError('Error sending API request: ' + result.exception);			} else { mw.log(result); printError('Error sending API request: ' + code); }			clearPending; setTimeout(refocus, 0); });	}	function getContent { // jshint ignore:line		var $textarea = $('#wpTextbox1'),			context = $textarea.data('wikiEditor-context');		if (context === undefined || context.codeEditor === undefined) {			return $textarea.val;		} else {			return $textarea.textSelection('getContents');		}	}	function onClearClick {// jshint ignore:line		$('#mw-scribunto-output').empty;		clearNextRequest = true;		refocus;	}	function clearOutput {// jshint ignore:line		$('#mw-scribunto-output').empty;		refocus;	}	function initEditPage { // jshint ignore:line		$('#mw-scribunto-console').first.remove;		var $wpTextbox1, 			$console = $('#mw-scribunto-console');		mw.messages.set('scribunto-console-clear-output', 'Clear Console Output');		mw.messages.set('scribunto-console-clear', 'Clear Console State');		mw.messages.set('scribunto-console-submit', 'Submit');		if (!$console.length) {			$wpTextbox1 = $('#wpTextbox1'); $console = $(' ').attr({				id: 'mw-scribunto-console'			}); $('.editOptions').before($console); }		$(' ')			.attr('class', 'mw-scribunto-console-fieldset') .append($(' ')				.text(mw.msg('scribunto-console-title'))			) .append($(' ')) .append($(' ').append( $(' ', {					id: "debugConsole",					css: {						'width': 'calc(-webkit-fill-available+100px)',						'font-size': '14px',						'line-height': '18px',						'min-height': '100px',						'max-height': '400px',					}				}) ))			.append($(' ').append( $(' ')					.attr({						type: 'button',						value: 'Clear Console Output'					}) .on('click', clearOutput), $(' ')					.attr({						type: 'button',						value: mw.msg('scribunto-console-clear')					}) .on('click', onClearClick), $(' ')					.attr({						type: 'button',						value: mw.msg('scribunto-console-submit')					}) .on('click', function(e) {						e.preventDefault;						go;					}) ))			.wrap(' ') .appendTo($console); initConsole; }	$(function {		var action = mw.config.get('wgAction');		if (action === 'edit' || action === 'submit' || action === 'editredlink') {			initEditPage;		}	}); });