Utilisateur:Dr Brains/SourceCliquable.js
/*******************************
Dans les commentaires d'une balise <source> ou <syntaxhighlight>
Rendu des liens (internes/externes/modèles) cliquables (le rendu des liens externes pourrait être amélioré)
Rendu du texte en gras
Rendu du texte en italique
importScript('Utilisateur:Dr Brains/monobook.js');
*********************************/
//<nowiki>
///////////////////////////////////////////// TEST //////////////////////////////////////
/******************************************
* [[Utilisateur:Dr Brains/SourceCliquable.js]]
* [[Utilisateur:Dr Brains/SourceCliquable.js|SourceCliquable]]
* [http://fr.wikipedia.org/wiki/Utilisateur:Dr_Brains/SourceCliquable.js ext]
* ((!))
* ((ébauche|économie))
* Texte normal, '''Texte gras''', texte normal.
*******************************************/
//////////////////////////////////////////////////////////////////////////////////
// [[Utilisateur:Dr Brains/SourceCliquable.js]] //
// [[Utilisateur:Dr Brains/SourceCliquable.js|SourceCliquable]] //
// [http://fr.wikipedia.org/wiki/Utilisateur:Dr_Brains/SourceCliquable.js ext] //
// ((!)) //
// ((ébauche|économie)) //
// Texte normal, '''Texte gras''', ''texte italique''. //
//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////// TEST //////////////////////////////////////
function SyntaxHighlightLiensCliquables(){
var SiteURL = mw.config.get('wgServer') + "/wiki/";
var Spans = document.getElementsByTagName("span");
for(i=0;i<Spans.length;i++){
if ($(Spans[i]).hasClass("coMULTI") || $(Spans[i]).hasClass("co1") || Spans[i].className.match(/^diff/) ){
var Inside = Spans[i].innerHTML;
// Liens internes
Inside = Inside.replace(/\[\[:?([^\|\]]*)(?:\|([^\|\]]+))?\]\]/g, function(match, article, title, offset, s) {
return "<b><a href=\"" + SiteURL + article + "\">" + ((title) ? title : article) + "</a></b>";
});
// Liens externes
Inside = Inside.replace(/\[(((?:[^\]])|(?:[^ ]))+)/g, "<a href=\"$1\">$1</a>");
// Modèles
Inside = Inside.replace(/\{\{([^\}\|]+)(\|[^\}]+)?\}\}/g, "<b><a href=\"" + SiteURL + "Template:$1\">(($1$2))</a></b>");
// Texte gras
Inside = Inside.replace(/'''((?:[^']|'(?!''))+)'''/g, "'''<b>$1</b>'''");
// importScript()
Inside = Inside.replace(/importScript\('((?:[^'])+)/g, "importScript\('<a href=\"" + SiteURL + "$1\">$1</a>");
// obtenir()
Inside = Inside.replace(/obtenir\('((?:[^'])+)/g, "obtenir\('<a href=\"" + SiteURL + "MediaWiki:Gadget-$1.js\">$1</a>");
Spans[i].innerHTML = Inside;
}else{
continue;
}
}
}
$(SyntaxHighlightLiensCliquables);
function DiffLiensCliquables(){
var DiffCases = document.getElementsByTagName("td");
for(i=0;i<DiffCases.length;i++){
if (DiffCases[i].className.match(/^diff/) ){
var Inside = DiffCases[i].innerHTML;
Inside = Inside.replace(/\[\[:?([^\|\]]*)(?:\|([^\|\]]+))?\]\]/g, function(match, article, title, offset, s) { // Liens internes
return " <b><a href=\"" + SiteURL + article + "\"> " + ((title) ? title : article) + " </a></b> ";
});
Inside = Inside.replace(/\[http/g, " <b><a href=\"http"); // Liens externes
Inside = Inside.replace(/\ ext]/g, "\">Lien externe</a></b> "); // (doivent finir par " ext]")
Inside = Inside.replace(/\{\{([^\}\|]+)(\|[^\}]+)?\}\}/g, " <b><a href=\"" + SiteURL + "Template:$1\"> (($1$2)) </a></b> "); // Modèles
Inside = Inside.replace(/'''((?:[^']|'(?!''))+)'''/g, "<b>$1</b>"); // Texte gras
Inside = Inside.replace(/''((?:[^']|'(?!''))+)''/g, "<i>$1</i>"); // Texte italique
DiffCases[i].innerHTML = Inside;
}else{
continue;
}
}
}
$(DiffLiensCliquables);
//</nowiki>
Text is available under the CC BY-SA 4.0 license; additional terms may apply.
Images, videos and audio are available under their respective licenses.