MediaWiki:Gadget-interProjets.js
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) ;
Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5./**
* Extrait et affiche la liste
* des liens interprojets présents dans la page.
* auteur : https://fr.wikipedia.org/wiki/Utilisateur:Lgd
* licence : MIT
*
* Utilise : https://fr.wikipedia.org/wiki/MediaWiki:Gadget-interProjets.css
*
* Paramétrage: ajouter window.interprojetsPosition = 'left'; dans le common.js personnel
* pour afficher la liste dans le menu de gauche,
* ou window.interprojetsPosition = 'bottom'; pour l'afficher en pied de page.
*
* {{Catégorisation JS|InterProjets}}
*/
var interProjects = function ($) {
if (mw.config.get('wgNamespaceNumber') < 0) {return;}
var $content = $('#mw-content-text');
var $list = $('<ul></ul>');
var $kill = $content.find('.autres-projets');
var $interprojets = $content.find('.js-interprojets');
var targets = [
{$links: $interprojets.find('a[href*="commons.wikimedia.org"]'), project: 'Commons'},
{$links: $interprojets.find('a[href*="wiktionary.org"]'), project: 'Wiktionary'},
{$links: $interprojets.find('a[href*="wikinews.org"]'), project: 'Wikinews'},
{$links: $interprojets.find('a[href*="wikibooks.org"]'), project: 'Wikibooks'},
{$links: $interprojets.find('a[href*="wikiquote.org"]'), project: 'Wikiquote'},
{$links: $interprojets.find('a[href*="wikisource.org"]'), project: 'Wikisource'},
{$links: $interprojets.find('a[href*="wikiversity.org"]'), project: 'Wikiversity'},
{$links: $interprojets.find('a[href*="wikivoyage.org"]'), project: 'Wikivoyage'},
{$links: $interprojets.find('a[href*="species.wikimedia.org"]'), project: 'Wikispecies'},
];
var check = 0;
if (typeof interprojetsPosition !== 'undefined' && interprojetsPosition) {
var position = interprojetsPosition;
} else {
var position = 'top';
}
function makeList($links, project) {
if ($links.length !== 0) {
var duplicates = {};
$links.each(function () {
if (!duplicates[this.href]) {
var newLink = document.createElement('a');
newLink.href = this.href;
newLink.title = this.textContent + ' sur ' + project;
if (position === 'left') {
newLink.textContent = project;
} else {
newLink.textContent = this.textContent;
}
var $item = $('<li></li>').append(newLink);
$list.append($item);
duplicates[this.href] = true;
}
check++;
});
}
}
function displayList() {
if (position === 'left') {
var $portal = $('<div>')
.attr('id', 'p-coll-interprojects')
.attr('class', 'portal')
.append($('<h3>')
.text('Autres projets'))
.append($('<div>')
.attr('class', 'body')
.append($list));
$('#p-tb').after($portal);
} else if (position === 'bottom') {
var $portal = $('<div>')
.attr('class', 'gadget-interprojets gadget-interprojets-bottom')
.append($list);
$('#content').append($portal);
} else {
var $portal = $('<div>')
.attr('class', 'gadget-interprojets')
.append($list);
$('#content').prepend($portal);
}
}
function killThemAll() {
$kill.remove();
}
targets.forEach(function (target) {
makeList(target.$links, target.project);
});
if (check !== 0) {
displayList();
killThemAll();
}
};
$(interProjects);