Remarque: après avoir sauvegardé, vous devez vider le cache de votre navigateur pour que les changements prennent effet. Mozilla, cliquez sur Actualiser (ou ctrl-r). Internet Explorer / Opera: ctrl-f5. Safari: cmd-r. Konqueror ctrl-r.

// javascript pour modifier automatiquement les sections anciennes en sections modifiables
// (cf. [[Wiktionnaire:Prise de décision/Rendre toutes les sections modifiables]])
//<nowiki>

var wikibloc = document.getElementById( 'wpTextbox1' );

function maj_sections() {
	var
		wikicode_fragmente = wikibloc.value.split("\n"),
		
		sections = {
		/*******************************************************
		 * TYPES DE MOTS
		 ******************************************************/
		// ADJECTIFS, ADVERBES, CONJONCTIONS, DÉTERMINANTS
		"adj": {niveau:3,nom_maj:"adjectif",hasCode:1},
		"adjectif": {niveau:3,nom_maj:"adjectif",hasCode:1},
		"adv": {niveau:3,nom_maj:"adverbe",hasCode:1},
		"adverbe": {niveau:3,nom_maj:"adverbe",hasCode:1},
		"adv-int": {niveau:3,nom_maj:"adverbe interrogatif",hasCode:1},
		"adv-pron": {niveau:3,nom_maj:"adverbe pronominal",hasCode:1},
		"adv-rel": {niveau:3,nom_maj:"adverbe relatif",hasCode:1},
		"conj": {niveau:3,nom_maj:"conjonction",hasCode:1},
		"conj-coord": {niveau:3,nom_maj:"conjonction de coordination",hasCode:1},
		"adj-dém": {niveau:3,nom_maj:"adjectif démonstratif",hasCode:1},
		"dét": {niveau:3,nom_maj:"déterminant",hasCode:1},
		"adj-excl": {niveau:3,nom_maj:"adjectif exclamatif",hasCode:1},
		"adj-indéf": {niveau:3,nom_maj:"adjectif indéfini",hasCode:1},
		"adj-int": {niveau:3,nom_maj:"adjectif interrogatif",hasCode:1},
		"adj-num": {niveau:3,nom_maj:"adjectif numéral",hasCode:1},
		"adj-pos": {niveau:3,nom_maj:"adjectif possessif",hasCode:1},
		"art": {niveau:3,nom_maj:"article",hasCode:1},
		"article": {niveau:3,nom_maj:"article",hasCode:1},
		"art-déf": {niveau:3,nom_maj:"article défini",hasCode:1},
		"art-indéf": {niveau:3,nom_maj:"article indéfini",hasCode:1},
		"art-part": {niveau:3,nom_maj:"article partitif",hasCode:1},
		// NOMS, PRÉPOSITIONS, PRONOMS, VERBES
		"nom": {niveau:3,nom_maj:"nom",hasCode:1},
		"nom-fam": {niveau:3,nom_maj:"nom de famille",hasCode:1},
		"nom-pr": {niveau:3,nom_maj:"nom propre",hasCode:1},
		"nom-propre": {niveau:3,nom_maj:"nom propre",hasCode:1},
		"nom-sciences": {niveau:3,nom_maj:"nom scientifique",hasCode:1},
		"prénom": {niveau:3,nom_maj:"prénom",hasCode:1},
		"prép": {niveau:3,nom_maj:"préposition",hasCode:1},
		"pronom": {niveau:3,nom_maj:"pronom",hasCode:1},
		"pronom-dém": {niveau:3,nom_maj:"pronom démonstratif",hasCode:1},
		"pronom-indéf": {niveau:3,nom_maj:"pronom indéfini",hasCode:1},
		"pronom-int": {niveau:3,nom_maj:"pronom interrogatif",hasCode:1},
		"pronom-pos": {niveau:3,nom_maj:"pronom possessif",hasCode:1},
		"pronom-rel": {niveau:3,nom_maj:"pronom relatif",hasCode:1},
		"pronom-pers": {niveau:3,nom_maj:"pronom personnel",hasCode:1},
		"pronom-personnel": {niveau:3,nom_maj:"pronom personnel",hasCode:1},
		"verb": {niveau:3,nom_maj:"verbe",hasCode:1},
		"verbe": {niveau:3,nom_maj:"verbe",hasCode:1},
		"verb-pr": {niveau:3,nom_maj:"verbe pronominal",hasCode:1},
		//"aux": {niveau:3,nom_maj:"auxiliaire",hasCode:1},
		// EXCLAMATIONS, PARTIES, PHRASES
		"interj": {niveau:3,nom_maj:"interjection",hasCode:1},
		"interjection": {niveau:3,nom_maj:"interjection",hasCode:1},
		"onoma": {niveau:3,nom_maj:"onomatopée",hasCode:1},
		"onomatopée": {niveau:3,nom_maj:"onomatopée",hasCode:1},
		"onom": {niveau:3,nom_maj:"onomatopée",hasCode:1},
		"aff": {niveau:3,nom_maj:"affixe",hasCode:1},
		"circonf": {niveau:3,nom_maj:"circonfixe",hasCode:1},
		"inf": {niveau:3,nom_maj:"infixe",hasCode:1},
		"interf": {niveau:3,nom_maj:"interfixe",hasCode:1},
		"part": {niveau:3,nom_maj:"particule",hasCode:1},
		"particule": {niveau:3,nom_maj:"particule",hasCode:1},
		"part-num": {niveau:3,nom_maj:"particule numérale",hasCode:1},
		"post": {niveau:3,nom_maj:"postposition",hasCode:1},
		"postposition": {niveau:3,nom_maj:"postposition",hasCode:1},
		"préf": {niveau:3,nom_maj:"préfixe",hasCode:1},
		"préfixe": {niveau:3,nom_maj:"préfixe",hasCode:1},
		"radical": {niveau:3,nom_maj:"radical",hasCode:1},
		"suffixe": {niveau:3,nom_maj:"suffixe",hasCode:1},
		"suf": {niveau:3,nom_maj:"suffixe",hasCode:1},
		"gismu": {niveau:3,nom_maj:"gismu",hasCode:1},
		"pré-verbe": {niveau:3,nom_maj:"pré-verbe",hasCode:1},
		"pré-nom": {niveau:3,nom_maj:"pré-nom",hasCode:1},
		"phr": {niveau:3,nom_maj:"locution-phrase",hasCode:1},
		"prov": {niveau:3,nom_maj:"proverbe",hasCode:1},
		// DIVERS, CARACTÈRES
		"quantif": {niveau:3,nom_maj:"quantificateur",hasCode:1},
		"var-typo": {niveau:3,nom_maj:"variante typographique",hasCode:1},
		"lettre": {niveau:3,nom_maj:"lettre",hasCode:1},
		"symb": {niveau:3,nom_maj:"symbole",hasCode:1},
		"symbole": {niveau:3,nom_maj:"symbole",hasCode:1},
		"class": {niveau:3,nom_maj:"classificateur",hasCode:1},
		"classificateur": {niveau:3,nom_maj:"classificateur",hasCode:1},
		"numér": {niveau:3,nom_maj:"numéral",hasCode:1},
		"numéral": {niveau:3,nom_maj:"numéral",hasCode:1},
		"num": {niveau:3,nom_maj:"numéral",hasCode:1},
		"sinogramme": {niveau:3,nom_maj:"sinogramme",hasCode:1},
		"erreur": {niveau:3,nom_maj:"erreur",hasCode:1},
		
		/*****************************************************
		 * AUTRES SECTIONS
		 ****************************************************/
		 // NIVEAU 3
		"étymologie": {niveau:3,nom_maj:"étymologie"},
		"étym": {niveau:3,nom_maj:"étymologie"},
		"etym": {niveau:3,nom_maj:"étymologie"},
		"prononciation": {niveau:3,nom_maj:"prononciation"},
		"pron": {niveau:3,nom_maj:"prononciation"},
		"voir": {niveau:3,nom_maj:"voir aussi"},
		"références": {niveau:3,nom_maj:"références"},
		"réf": {niveau:3,nom_maj:"références"},
		"ref": {niveau:3,nom_maj:"références"},
		"anagrammes": {niveau:3,nom_maj:"anagrammes"},
		"anagr": {niveau:3,nom_maj:"anagrammes"},
		 
		// NIVEAU 4
		"abréviation": {niveau:4,nom_maj:"abréviations"},
		"abrév": {niveau:4,nom_maj:"abréviations"},
		"apparentés": {niveau:4,nom_maj:"apparentés"},
		"app": {niveau:4,nom_maj:"apparentés"},
		"apr": {niveau:4,nom_maj:"apparentés"},
		"compos": {niveau:4,nom_maj:"composés"},
		"diminutifs": {niveau:4,nom_maj:"diminutifs"},
		"dimin": {niveau:4,nom_maj:"diminutifs"},
		"dérivés": {niveau:4,nom_maj:"dérivés"},
		"drv": {niveau:4,nom_maj:"dérivés"},
		"drv-int": {niveau:4,nom_maj:"dérivés autres langues"},
		"exp": {niveau:4,nom_maj:"expressions"},
		"faux-amis": {niveau:4,nom_maj:"faux-amis"},
		"gent": {niveau:4,nom_maj:"gentilés"},
		"holo": {niveau:4,nom_maj:"holonymes"},
		"hypo": {niveau:4,nom_maj:"hyponymes"},
		"hyper": {niveau:4,nom_maj:"hyperonymes"},
		"méro": {niveau:4,nom_maj:"méronymes"},
		"noms-vern": {niveau:4,nom_maj:"noms vernaculaires"},
		"synonymes": {niveau:4,nom_maj:"synonymes"},
		"syn": {niveau:4,nom_maj:"synonymes"},
		"q-syn": {niveau:4,nom_maj:"quasi-synonymes"},
		"antonymes": {niveau:4,nom_maj:"antonymes"},
		"ant": {niveau:4,nom_maj:"antonymes"},
		"anto": {niveau:4,nom_maj:"antonymes"},
		"trad": {niveau:4,nom_maj:"traductions"},
		"trans": {niveau:4,nom_maj:"transcriptions"},
		"tran": {niveau:4,nom_maj:"transcriptions"},
		"tropo": {niveau:4,nom_maj:"troponymes"},
		"vidéo": {niveau:4,nom_maj:"image vidéo"},
		"voc": {niveau:4,nom_maj:"vocabulaire"},
		"var": {niveau:4,nom_maj:"variantes"},
		"var-ortho": {niveau:4,nom_maj:"variantes orthographiques"},
		"dial": {niveau:4,nom_maj:"variantes dialectales"},
		"décl": {niveau:4,nom_maj:"déclinaison"},
		"conjugaison": {niveau:4,nom_maj:"conjugaison"},
		"conjug": {niveau:4,nom_maj:"conjugaison"},
		"hist": {niveau:4,nom_maj:"attestations"},
		"homophones": {niveau:4,nom_maj:"homophones"},
		"homo": {niveau:4,nom_maj:"homophones"},
		"paronymes": {niveau:4,nom_maj:"paronymes"},
		"paro": {niveau:4,nom_maj:"paronymes"},
		"phrases": {niveau:4,nom_maj:"phrases"},
		
		// NIVEAU 5
		"note": {niveau:5,nom_maj:"notes"},
		"notes": {niveau:5,nom_maj:"notes"}
		},
	
		// Gestion des erreurs
		erreurs = [], // Tableau pour regrouper les erreurs qui sont elles-mêmes des tableaux sous le format [ligne_erronée, numero_ligne, explication_erreur]
		message_erreur,
		choix;
	
	function maj_section( texte_section, noLigne ) {
		var
			nom_section,
			code_langue,
			num,
			cle,
			genre,
			flexion = false,
			
			niveau = "",
			texte_final = "";
		
		// Cas spéciaux
		if ( /^\{\{trad-trier\}\} *$/.test(texte_section) ) {
			return "===== {{S|traductions à trier}} =====";
		}
		
		// Récupération du nom de la section
		nom_section = /\{\{-([^|}]+)-/.exec( texte_section );
		if (nom_section !== null) {
			nom_section = $.trim(nom_section[1]);
		} else {
			erreurs.push( [texte_section, noLigne, "car aucun nom de section n'a été reconnu par le gadget"] );
			return texte_section;
		}
		// Flexion ?
		if ( nom_section.indexOf('flex') === 0 && nom_section.length >= 6 ) {
			nom_section = nom_section.substring(5);
			flexion = true;
		}
		// On enlève le -loc
		if ( nom_section.indexOf('loc') === 0 && nom_section.length >= 5 ) {
			nom_section = nom_section.substring(4);
		}
		
		// Gestion du paramètre "s" de {-note-}
		if ( nom_section == "note" && /\|s=[^|}]/.exec( texte_section ) !== null ) {
			nom_section = "notes";
		}
		
		// Section non reconnue par le gadget
		if ( !sections[nom_section] ) {
			erreurs.push( [texte_section, noLigne, "car le gadget ne connaît pas ce nom de section"] );
			return texte_section;
		}
		
		// Récupération du code langue, si nécessaire
		if ( sections[nom_section].hasCode ) {
			code_langue = /\|([^|}=]+?)[|}]/.exec( texte_section );
			if (code_langue !== null) {
				code_langue = $.trim(code_langue[1]);
			} else {
				erreurs.push( [texte_section, noLigne, "car aucun code langue n'a été détecté"] );
				return texte_section;
			}
		}
		
		// Récupération du paramètre "num", si présent
		num = /num *=([^|}]+?)[|}]/.exec( texte_section );
		if (num !== null) {
			num = $.trim(num[1]);
		}
		
		// Récupération du paramètre "clé", si présent
		cle = /clé *=([^|}]+?)[|}]/.exec( texte_section );
		if (cle !== null) {
			cle = $.trim(cle[1]);
		}
		
		// Gestion du paramètre "genre" de {-prénom-}
		if ( nom_section == "prénom" && /genre *=([^|}]+?)[|}]/.exec( texte_section ) !== null ) {
			genre = /genre *=([^|}]+?)[|}]/.exec( texte_section )[1];
		}

		// Génération du texte final qui remplace l'ancienne ligne de section
		texte_final = "{{S|" + sections[nom_section].nom_maj;
		if ( code_langue ) texte_final += ("|" + code_langue);
		if ( flexion ) texte_final += "|flexion";
		if ( genre ) texte_final += ("|genre=" + genre);
		if ( cle ) texte_final += ("|clé=" + cle);
		if ( num ) texte_final += ("|num=" + num);
		texte_final += "}}";
		texte_final = ajoute_niveau( texte_final, sections[nom_section].niveau );
		return texte_final;
	}
	
	var ajoute_niveau = function( wikitext, niveau ) {

		switch (niveau) {
			case 3:
				niveau = "===";
				break;
			case 4:
				niveau = "====";
				break;
			case 5:
				niveau = "=====";
				break;
		}
		return niveau + " " + wikitext + " " + niveau;
	};
	
	// Pour assurer la compatibilité avec WikEd
	if (typeof(wikEdUseWikEd) != 'undefined') {
		if (wikEdUseWikEd === true) {
			WikEdUpdateTextarea();
		}
	}
	
	// Pour assurer la compatibilité avec la fonctionnalité (bêta en date du 31/08/2017) de colorisation syntaxique
	// On désactive la fonctionnalité un instant
	var codeMirror_was_activated = false;
	if ( $('#mw-editbutton-codemirror').length > 0 && $('.CodeMirror').length > 0 ) {
		codeMirror_was_activated = true;
		$('#mw-editbutton-codemirror').click();
	}
	
	for (var k = 0; k < wikicode_fragmente.length; k++) {
		if ( /^\{\{-[^|}]+-[^}]*?\}\} *$/.test(wikicode_fragmente[k])
			|| /^\{\{trad-trier\}\} *$/.test(wikicode_fragmente[k])
		   ) {
			wikibloc.value = wikibloc.value.replace(wikicode_fragmente[k], maj_section(wikicode_fragmente[k], k+1) );
		}
	}
	
	// Post traitement : espaces avant et après les sections
	// (repris de https://fr.wiktionary.org/w/index.php?title=Discussion_module:section/analyse/test&oldid=15457586 )
	wikibloc.value = wikibloc.value.replace( /[\r\n]+==/g, "\n\n==" );
	wikibloc.value = wikibloc.value.replace( /==[\r\n]+/g, "==\n" );
	
	// Rendre la main à WikEd
	if (typeof(wikEdUseWikEd) != 'undefined') {
		if (wikEdUseWikEd === true) {
			WikEdUpdateFrame();
		}
	}
	
	// Pour assurer la compatibilité avec la fonctionnalité (bêta en date du 31/08/2017) de colorisation syntaxique
	// On rend la main à la coloration syntaxique
	if ( $('#mw-editbutton-codemirror').length > 0 && $('.CodeMirror').length === 0 && codeMirror_was_activated) {
		$('#mw-editbutton-codemirror').click();
	}
	
	if ( erreurs.length >= 1 ) {
		message_erreur = erreurs.length == 1 ? "Une erreur détectée :\n\n" : erreurs.length + " erreurs détectées :\n\n";
		for ( var i = 0; i < erreurs.length; i++ ) {
			message_erreur += "⏩ Ligne " + erreurs[i][1] + " : " + erreurs[i][0] + " n’a pas été modifié " + erreurs[i][2] + ".\n";
		}
		choix = confirm( message_erreur );
		if (typeof(console) != 'undefined')
			console.log(message_erreur);
		if ( choix ) {
			return false;
		}
	}
	
	return true;
}

/******************************************************
 * Ajout d'un bouton à la barre vector (ou l'ancienne)
 * Crédit : [[w:en:User:V111P/js/addToolbarButtons]]
******************************************************/
var addToolbarButtonsUrl = '//en.wikipedia.org/w/index.php?title='
        + 'User:V111P/js/addToolbarButtons.js&action=raw&ctype=text/javascript'; 
 
var modif_section_button = {
		id: 'sections-modifiables',
		tooltip: 'Rendre les sections modifiables',
		callback: maj_sections,
		iconUrl: '//upload.wikimedia.org/wikipedia/commons/thumb/4/43/' +
		'Sections_modifiables_icone3.png/22px-Sections_modifiables_icone3.png'
};

// On s'assure que la barre d'édition avancée (WikiEditor) est activée dans les préférences de l'utilisateur
if (mw.user.options.get( 'usebetatoolbar' ) == 1) {
	if ( mw.libs.addToolbarButtons ) {
		mw.libs.addToolbarButtons(modif_section_button);
	} else {
        	var tbs = window.toolbarButtonsToAdd = window.toolbarButtonsToAdd || [];
		tbs.push(modif_section_button);
		$.ajax({
		url: addToolbarButtonsUrl,
		dataType: 'script',
		cache: true
		});
	}
}
/*****************************************************/

if ( $.inArray( mw.config.get('wgNamespaceNumber'), [ 0 ] ) !== -1 && $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
	$( '#editform' ).submit(function( event ) {
		if ( wikibloc && (/^\{\{-[^|}]+-[^}]*?\}\} *$/m.test(wikibloc.value) || /^\{\{trad-trier\}\} *$/m.test(wikibloc.value) ) ) {
			if ( !maj_sections() ) {
				event.preventDefault();
			}
		}
	});
}
//</nowiki>