Aller au contenu

Utilisateur:Antimuonium/DisplayLinks.js

Une page de Wikipédia, l'encyclopédie libre.
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;

Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
/// Code based on AppendDatabox (https://fr.wikipedia.org/wiki/Utilisateur:0x010C/script/AppendDatabox.js)

var DLvars_basetemplate = "{{Liens}}\n";

var DLvars_Texts = {
 "nowikidataitem"               : "Pas d'élément lié sur Wikidata",
 "showpreview"                  : "Afficher le modèle {{Liens}}",
 "hidepreview"                  : "Cesser d'afficher le modèle {{Liens}}",
};

mw.loader.using(['jquery.client', 'jquery.mwEmbedUtil', 'jquery.ui']);


$(function() {
	if (mw.config.get('wgNamespaceNumber') == 0 && mw.config.get('wgAction') == 'view') {
		if ($("#t-wikibase").length)
			displaylinks_initialize();
		else
			$('.printfooter').before('<div style="float:right;"><small>['+DLvars_Texts['nowikidataitem']+']</small></div>');
	}
});

function displaylinks_initialize() {
	$('.printfooter').before('<div style="float:right;" id="displaylinks_link1"><small>[<a href="javascript:displaylinks_showpreview();">'+DLvars_Texts['showpreview']+'</a>]</small></div>');
}

function displaylinks_showpreview() {
	$("#displaylinks_link1").html('<small>[<a href="javascript:displaylinks_hidepreview();">'+DLvars_Texts['hidepreview']+'</a>]</small>');
	$.ajax({
		url: mw.util.wikiScript('api'),
		method: 'GET',
		data: {
			action: 'expandtemplates',
			text: DLvars_basetemplate,
			prop: 'wikitext',
			title: mw.config.get('wgTitle'),
			format: 'json',
		},
	}).then(function(data) {
		$.ajax({
			url: mw.util.wikiScript('api'),
			method: 'POST',
			data: {
				action: 'parse',
				text: '<div id="displaylinks_preview">' + data.expandtemplates.wikitext + '</div>',
				contentmodel: 'wikitext',
				prop: 'text',
				format: 'json',
			},
			success: function(data) {
				$("#bandeau-portail").before(data.parse.text["*"]);
				if (typeof databoxeditor_changelinks == 'function')
					databoxeditor_changelinks();
			}
		});
	});
}

function displaylinks_hidepreview() {
	$("#displaylinks_preview").remove();
	$("#displaylinks_link1").html('<small>[<a href="javascript:displaylinks_showpreview();">'+DLvars_Texts['showpreview']+'</a>]</small>');
}