Jump to content

User:Zackmann08/scripts/jumpToText.js

From 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.
importScript('User:Zackmann08/scripts/wait.js');

$(document).ready(function() {
	if(mw.config.get('wgNamespaceNumber') != -1 && document.getElementsByName('wpTextbox1')[0]) {
		(async() => {
			var watchlist = await waitForElement('#pt-watchlist');
			watchlist.querySelector('a').removeAttribute('accesskey');
			$(document).keydown(function(event) {
				// Check if Control key is pressed (event.ctrlKey)
				// Check if Alt key is pressed (event.altKey)
				// Check if the 'L' key is pressed
				if (event.ctrlKey && event.altKey && event.code === 'KeyL') {
					// Prevent the default browser action for this key combination (e.g., opening developer tools)
					event.preventDefault();
					document.querySelector('#wikiPreview')?.remove();
					document.querySelector('#wikiDiff')?.remove();
				}
			});
		})();
	}
});


// Inserts a button that allows you to jump past the preview window directly to the textbox. 
mw.loader.using( [ 'oojs-ui-core' ] ).then(function() {
	if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' ) {
		var scrollButton = new OO.ui.ButtonWidget();
	
		scrollButton.setElementId( 'scrollButton' ).setIcon( 'download' ).setLabel( 'Scroll' );
			
		scrollButton.on( 'click', function () {
			document.querySelector('.wikiEditor-ui').scrollIntoView({ behavior: 'instant' });
		});
		$( '#jump-to-nav' ).append( scrollButton.$element );

		mw.loader.using( [ 'oojs-ui-core' ] ).then( function () {
			(async () => {
				var indentButton = await waitForElement("#wpIndent");
				try {
					var hideTextButton = new OO.ui.ButtonWidget();
					hideTextButton.setElementId( 'wpHideText' ).setIcon( 'noWikiText' ).setLabel( 'Hide text' );
					hideTextButton.on( 'click', function () {
						document.querySelector('#wikiPreview')?.remove();
						document.querySelector('#wikiDiff')?.remove();
						mw.notify('Diff and preview hidden', {type: 'success'});
					});
					hideTextButton.$element.insertBefore( $(indentButton.nextSibling) );
				} catch (err) {
					mw.notify('Failed to insert ButtonWidget: ' + err.message, {type: 'warn'});
					return;
				}
			})();
		});
	}
});