User:Guarapiranga/accessKeysCheatSheet.js

Source: Wikipedia, the free encyclopedia.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//  Adds alt+shift+? as an access key to show a list of all default access keys

$(() => {
	let dialog;
	$('<a>').attr('accesskey', '?').text('This access keys cheat sheet').hide().click(() => {
		if (dialog) {
			if (dialog.isOpened()) {
				dialog.close();
			} else {
				dialog.open({
					actions: [],
					size: 'medium'
				});
			}
			return false;
		}
		mw.loader.using('oojs-ui-windows', () => {
			let winMan = new OO.ui.WindowManager();
			winMan.$element.css('width', '35em').appendTo(document.body);
			dialog = new OO.ui.MessageDialog();
			winMan.addWindows([dialog]);
			$('<table>').addClass('wikitable').css('width', '100%').append(
				$('[accesskey]').map(function () {
					return $('<tr>').append(
						$('<th>').text(this.accessKey.toUpperCase()),
						$('<td>').text(
							this.getAttribute('aria-label') ||
							this.title.replace(/ \[.+?\]/, '') ||
							this.textContent ||
							this.value ||
							$(`label[for="${this.id}"]`).text()
						)
					);
				}).get()
			).appendTo(dialog.text.$element);
			dialog.open({
				actions: [],
				size: 'medium'
			});
		});
		return false;
	}).appendTo(document.body);
});