Jump to content

User:Aaron Liu/Seckedit.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.
// Forked from [[User:The Voidwalker/alwaysEditSectionLink.js]]
// Makes edit section links appear everywhere they don't exist but probably should.
// Only probably; they might turn up in unexpected places.
// Will incorrectly add to transcluded headings and fail if run after copySectHeadings.

( () => {
	const $heads = $( '.mw-heading' );
	if ( mw.config.get( 'wgAction' ) === 'view' && $heads[ 0 ] && !$( '.mw-editsection', $heads[ 0 ] )[ 0 ] && mw.config.get( 'wgIsProbablyEditable' ) ) {
		$heads.each( ( i, head ) => {
			$( head ).append(
				$( '<span>' )
					.addClass( 'mw-editsection' )
					.append(
						$( '<span>' ).addClass( 'mw-editsection-bracket' ).text( '[' ),
						$( '<a>' )
							.attr( 'href', mw.util.getUrl( mw.config.get( 'wgPageName' ), { action: 'edit', section: i + 1 } ) )
							.text( 'kedit' ),
						$( '<span>' ).addClass( 'mw-editsection-bracket' ).text( ']' )
					)
			);
		} );
	}
} )();