Участник:Stjn/editTopEverywhere.js

/**
 * Insert edit section link everywhere on the wikis
 * Supposed to work with [[:en:User:BrandonXLF/QuickEdit.js]] so you can use it everywhere.
 * Every visit to a new page with edit section links updates localStorage.
 *
 * Should not be used without a polyfill in Internet Explorer
 * See if you need one:
 * https://polyfill.io/v3/polyfill.min.js?features=String.prototype.replaceAll
 */
mw.loader.using( [
	'mediawiki.storage'
] ).then(function () {
	var lsKey = 'editTopEverywhere';
	var wgNamespaceNumber = mw.config.get( 'wgNamespaceNumber' );
	var editSection = document.querySelector( '.mw-heading .mw-editsection' );
	var firstHeading = document.querySelector( '.mw-first-heading' );
	
	// Do nothing on non-existing pages
	if ( !mw.config.get( 'wgArticleId' ) ) return;

	// Do nothing if not on a wikitext page
	if ( mw.config.get( 'wgPageContentModel' ) !== 'wikitext' ) return;

	// Do nothing on special pages
	if ( wgNamespaceNumber === -1 ) return;
	
	// Do nothing on non-view
	if ( mw.config.get( 'wgAction' ) !== 'view' ) return;

	// Update current version of the edit section link in localStorage and do nothing else
	if ( editSection !== null && mw.config.get( 'wgNamespaceNumber' ) === 0 && !editSection.classList.contains( 'iwrm-editsection' ) ) {
		var editSectionClone = decodeURI( editSection.outerHTML )
			.replaceAll( mw.config.get( 'wgPageName' ), '$1' )
			.replace( /section=T?-?\d+/g, 'section=0' )
			.replace( /\s*title="(.+?)"/g, '' );
		mw.storage.set( lsKey, editSectionClone );
		return;
	}

	// Do nothing if first heading already has an edit link
	if ( firstHeading.querySelector( '.mw-editsection' ) !== null ) return;

	// Insert localStorage link
	var lsEditsection = mw.storage.get( lsKey );
	if ( lsEditsection === null ) {
		return;
	}
	lsEditsection = lsEditsection.replaceAll( '$1', mw.config.get( 'wgPageName' ) );
	firstHeading.insertAdjacentHTML( 'beforeend', lsEditsection );
} );
Prefix: a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9

Portal di Ensiklopedia Dunia

Kembali kehalaman sebelumnya