« MediaWiki:Common.js » : différence entre les versions
Jump to navigation
Jump to search
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| (17 versions intermédiaires par 3 utilisateurs non affichées) | |||
| Ligne 1 : | Ligne 1 : | ||
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */ |
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */ |
||
// ============================================================ |
// ============================================================ |
||
//////////// FONCTION : .indexOf (Patch IE) ////////////// |
|||
//////////////////////////////////////////////////// Patch extension WhosOnline (liens bleus -> rouges) |
|||
function WhosOnline_CheckNewPage(position){ |
|||
if (!Array.indexOf) { |
|||
var ListePresents = document.getElementById('WhosOnlineList'); |
|||
Array.prototype.indexOf = function(obj,idx) { |
|||
if(!ListePresents) return; |
|||
var len = this.length; |
|||
if(!position) position=0; |
|||
if (len == 0) return -1; |
|||
var Lien = ListePresents.getElementsByTagName('a')[position]; |
|||
if (!idx) idx = 0; |
|||
while (idx < 0) idx = len + idx; |
|||
for (var i = 0; i < len; i++) |
|||
LienHref = LienHref.split(wgServer).join('').split('/wiki/').join(''); |
|||
if (this[i] == obj) |
|||
return i; |
|||
var url = wgServer+'/w/api.php?action=query&redirects&titles='+LienHref; |
|||
return -1; |
|||
Requete.open('GET',url, true); |
|||
} |
|||
Requete.send(null); |
|||
} |
|||
Requete.onreadystatechange = function(){ |
|||
// ============================================================ |
|||
if((Requete.readyState == 4)&&(Requete.status == 200)){ |
|||
var Reponse = document.createElement('div'); |
|||
// ============================================================ |
|||
Reponse.innerHTML = Requete.responseText; |
|||
//////////// FONCTION : .HTMLize (évite des attaques XSS) ////////////// |
|||
var Spans = Reponse.getElementsByTagName('span')[7].innerHTML; |
|||
if(!String.HTMLize){ |
|||
if(Spans.indexOf('missing=""')!=-1){ |
|||
String.prototype.HTMLize = function() { |
|||
Lien.className = "new"; |
|||
var chars = new Array('&','<','>','"'); |
|||
} |
|||
var entities = new Array('amp','lt','gt','quot'); |
|||
WhosOnline_CheckNewPage((position+1)); |
|||
var string = this; |
|||
for (var i=0; i<chars.length; i++) { |
|||
var regex = new RegExp(chars[i], "g"); |
|||
string = string.replace(regex, '&' + entities[i] + ';'); |
|||
} |
|||
return string; |
|||
} |
|||
} |
|||
// ============================================================ |
|||
// ================================================================================================== |
|||
//////////// FONCTIONS RELATIVES AUX COOKIES ////////////// |
|||
function setCookie (cookieName, cookieValue, expires, path) { |
|||
document.cookie = escape(cookieName) + '=' + escape(cookieValue) + (expires ? '; EXPIRES=' + expires.toGMTString() : '') + "; PATH=/" ; |
|||
} |
|||
function getCookie(cookieName) { |
|||
var cookieValue = null; |
|||
var posName = document.cookie.indexOf(escape(cookieName) + '=' ); |
|||
if (posName != -1) { |
|||
var posValue = posName + (escape(cookieName) + '=' ).length; |
|||
var endPos = document.cookie.indexOf(';', posValue) ; |
|||
if (endPos != -1) { |
|||
cookieValue = unescape(document.cookie.substring(posValue, endPos)); |
|||
} else { |
|||
cookieValue = unescape(document.cookie.substring(posValue)); |
|||
} |
} |
||
} |
} |
||
return decodeURIComponent(cookieValue); |
|||
} |
|||
// ============================================================ |
|||
// ============================================================ |
|||
//////////// FONCTIONS : MANIPULATION DE CLASSES ////////////// |
|||
function hasClass(node, className) { |
|||
if (node.className == className) { |
|||
return true; |
|||
} |
|||
var reg = new RegExp('(^| )'+ className +'($| )') |
|||
if (reg.test(node.className)) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
function addClass(node, className) { |
|||
if (hasClass(node, className)) { |
|||
return false; |
|||
} |
|||
node.className += ' '+ className; |
|||
return true; |
|||
} |
|||
function removeClass(node, className) { |
|||
if (!hasClass(node, className)) { |
|||
return false; |
|||
} |
|||
node.className = eregReplace('(^|\\s+)'+ className +'($|\\s+)', ' ', node.className); |
|||
return true; |
|||
} |
|||
function eregReplace(search, replace, subject) { |
|||
return subject.replace(new RegExp(search,'g'), replace); |
|||
} |
|||
// ============================================================ |
|||
//////////// FONCTION : RECUPERE LE CONTENU TEXTUEL D'UN ELEMENT ////////////// |
|||
function getTextContent(oNode) { |
|||
if (typeof(oNode.textContent)!="undefined") {return oNode.textContent;} |
|||
switch (oNode.nodeType) { |
|||
case 3: // TEXT_NODE |
|||
case 4: // CDATA_SECTION_NODE |
|||
return oNode.nodeValue; |
|||
break; |
|||
case 7: // PROCESSING_INSTRUCTION_NODE |
|||
case 8: // COMMENT_NODE |
|||
if (getTextContent.caller!=getTextContent) { |
|||
return oNode.nodeValue; |
|||
} |
|||
break; |
|||
case 9: // DOCUMENT_NODE |
|||
case 10: // DOCUMENT_TYPE_NODE |
|||
case 12: // NOTATION_NODE |
|||
return null; |
|||
break; |
|||
} |
|||
var _textContent = ""; |
|||
oNode = oNode.firstChild; |
|||
while (oNode) { |
|||
_textContent += getTextContent(oNode); |
|||
oNode = oNode.nextSibling; |
|||
} |
|||
return _textContent; |
|||
} |
|||
// =============================================== |
|||
// =============================================== |
|||
//////////// FONCTION : INSERE UN ELEMENT APRES UN ELEMENT DE REFERENCE ////////////// |
|||
function insertAfter(element, reference) { |
|||
if(reference.nextSibling!=null){ |
|||
reference.parentNode.insertBefore(element, reference.nextSibling); |
|||
}else{ |
|||
reference.parentNode.appendChild(element); |
|||
} |
|||
} |
|||
// =============================================== |
|||
// =============================================== |
|||
//////////// FONCTION : DECODE LE HTML ISSU D'UNE REQUETE API ////////////// |
|||
function API_HTMLDecode(text){ |
|||
var EncodedCharacter = new Array(); |
|||
var DecodedCharacter = new Array(); |
|||
var CharacterCount = 0; |
|||
EncodedCharacter[CharacterCount] = "&"; |
|||
DecodedCharacter[CharacterCount] = "&"; |
|||
CharacterCount++; |
|||
EncodedCharacter[CharacterCount] = "'"; |
|||
DecodedCharacter[CharacterCount] = "'"; |
|||
CharacterCount++; |
|||
EncodedCharacter[CharacterCount] = """; |
|||
DecodedCharacter[CharacterCount] = '"'; |
|||
CharacterCount++; |
|||
for(var a=0;a<EncodedCharacter.length;a++){ |
|||
while(text.indexOf(EncodedCharacter[a])!=-1){ |
|||
text = text.split(EncodedCharacter[a]).join(DecodedCharacter[a]); |
|||
if(text.indexOf(EncodedCharacter[a])==-1) break; |
|||
} |
|||
} |
|||
return text; |
|||
} |
} |
||
addOnloadHook(WhosOnline_CheckNewPage); |
|||
// =============================================== |
// =============================================== |
||
Dernière version du 2 décembre 2023 à 14:36
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */
// ============================================================
//////////// FONCTION : .indexOf (Patch IE) //////////////
if (!Array.indexOf) {
Array.prototype.indexOf = function(obj,idx) {
var len = this.length;
if (len == 0) return -1;
if (!idx) idx = 0;
while (idx < 0) idx = len + idx;
for (var i = 0; i < len; i++)
if (this[i] == obj)
return i;
return -1;
}
}
// ============================================================
// ============================================================
//////////// FONCTION : .HTMLize (évite des attaques XSS) //////////////
if(!String.HTMLize){
String.prototype.HTMLize = function() {
var chars = new Array('&','<','>','"');
var entities = new Array('amp','lt','gt','quot');
var string = this;
for (var i=0; i<chars.length; i++) {
var regex = new RegExp(chars[i], "g");
string = string.replace(regex, '&' + entities[i] + ';');
}
return string;
}
}
// ============================================================
// ==================================================================================================
//////////// FONCTIONS RELATIVES AUX COOKIES //////////////
function setCookie (cookieName, cookieValue, expires, path) {
document.cookie = escape(cookieName) + '=' + escape(cookieValue) + (expires ? '; EXPIRES=' + expires.toGMTString() : '') + "; PATH=/" ;
}
function getCookie(cookieName) {
var cookieValue = null;
var posName = document.cookie.indexOf(escape(cookieName) + '=' );
if (posName != -1) {
var posValue = posName + (escape(cookieName) + '=' ).length;
var endPos = document.cookie.indexOf(';', posValue) ;
if (endPos != -1) {
cookieValue = unescape(document.cookie.substring(posValue, endPos));
} else {
cookieValue = unescape(document.cookie.substring(posValue));
}
}
return decodeURIComponent(cookieValue);
}
// ============================================================
// ============================================================
//////////// FONCTIONS : MANIPULATION DE CLASSES //////////////
function hasClass(node, className) {
if (node.className == className) {
return true;
}
var reg = new RegExp('(^| )'+ className +'($| )')
if (reg.test(node.className)) {
return true;
}
return false;
}
function addClass(node, className) {
if (hasClass(node, className)) {
return false;
}
node.className += ' '+ className;
return true;
}
function removeClass(node, className) {
if (!hasClass(node, className)) {
return false;
}
node.className = eregReplace('(^|\\s+)'+ className +'($|\\s+)', ' ', node.className);
return true;
}
function eregReplace(search, replace, subject) {
return subject.replace(new RegExp(search,'g'), replace);
}
// ============================================================
//////////// FONCTION : RECUPERE LE CONTENU TEXTUEL D'UN ELEMENT //////////////
function getTextContent(oNode) {
if (typeof(oNode.textContent)!="undefined") {return oNode.textContent;}
switch (oNode.nodeType) {
case 3: // TEXT_NODE
case 4: // CDATA_SECTION_NODE
return oNode.nodeValue;
break;
case 7: // PROCESSING_INSTRUCTION_NODE
case 8: // COMMENT_NODE
if (getTextContent.caller!=getTextContent) {
return oNode.nodeValue;
}
break;
case 9: // DOCUMENT_NODE
case 10: // DOCUMENT_TYPE_NODE
case 12: // NOTATION_NODE
return null;
break;
}
var _textContent = "";
oNode = oNode.firstChild;
while (oNode) {
_textContent += getTextContent(oNode);
oNode = oNode.nextSibling;
}
return _textContent;
}
// ===============================================
// ===============================================
//////////// FONCTION : INSERE UN ELEMENT APRES UN ELEMENT DE REFERENCE //////////////
function insertAfter(element, reference) {
if(reference.nextSibling!=null){
reference.parentNode.insertBefore(element, reference.nextSibling);
}else{
reference.parentNode.appendChild(element);
}
}
// ===============================================
// ===============================================
//////////// FONCTION : DECODE LE HTML ISSU D'UNE REQUETE API //////////////
function API_HTMLDecode(text){
var EncodedCharacter = new Array();
var DecodedCharacter = new Array();
var CharacterCount = 0;
EncodedCharacter[CharacterCount] = "&";
DecodedCharacter[CharacterCount] = "&";
CharacterCount++;
EncodedCharacter[CharacterCount] = "'";
DecodedCharacter[CharacterCount] = "'";
CharacterCount++;
EncodedCharacter[CharacterCount] = """;
DecodedCharacter[CharacterCount] = '"';
CharacterCount++;
for(var a=0;a<EncodedCharacter.length;a++){
while(text.indexOf(EncodedCharacter[a])!=-1){
text = text.split(EncodedCharacter[a]).join(DecodedCharacter[a]);
if(text.indexOf(EncodedCharacter[a])==-1) break;
}
}
return text;
}
// ===============================================
Ce que tu peux faire
Outils

Outils personnels