User:Dr Brains/Utilities.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Dr Brains/Utilities. |
/*
Fonctions standards issues de [[:fr:MediaWiki:Common.js]] ou de certains gadgets.
*/
if(typeof(addLoadEvent)=="undefined"){
function addLoadEvent(func) {
addOnloadHook(func);
}
}
if(typeof(loadJs)=="undefined"){
function loadJs(page) {
importScript(page);
}
}
if(typeof(obtenir)=="undefined"){
function obtenir(name) {
importScript('MediaWiki:Gadget-' + name + '.js');
}
}
if(typeof(getVarValue)=="undefined"){
function getVarValue(nom_variable, val_defaut){
var result = null;
try{
result = eval(nom_variable.toString());
}catch(e){
result = val_defaut;
}
return(result);
}
}
if(typeof(getStrDateToday)=="undefined"){
function getStrDateToday(format){
var str_mois = new Array();
with (str_mois) {
push("janvier");
push("février");
push("mars");
push("avril");
push("mai");
push("juin");
push("juillet");
push("août");
push("septembre");
push("octobre");
push("novembre");
push("décembre");
}
var today = new Date();
var day = today.getDate();
var year = today.getYear();
if (year < 2000) {
year = year + 1900;
}
var str_date = format;
//Création de la chaîne
var regex = /j/gi;
str_date = str_date.replace(regex, day.toString());
regex = /a/gi;
str_date = str_date.replace(regex, year.toString());
regex = /m/gi;
str_date = str_date.replace(regex, str_mois[today.getMonth()]);
return (str_date);
}
}
if(typeof(insertAfter)=="undefined"){
function insertAfter(parent, node, referenceNode) {
parent.insertBefore(node, referenceNode.nextSibling);
}
}
if(typeof(hasClass)=="undefined"){
function hasClass(node, className) {
if (node.className == className) {
return true;
}
var reg = new RegExp('(^| )'+ className +'($| )')
if (reg.test(node.className)) {
return true;
}
return false;
}
}
if(typeof(addClass)=="undefined"){
function addClass(node, className) {
if (hasClass(node, className)) {
return false;
}
node.className += ' '+ className;
return true;
}
}
if(typeof(removeClass)=="undefined"){
function removeClass(node, className) {
if (!hasClass(node, className)) {
return false;
}
node.className = eregReplace('(^|\\s+)'+ className +'($|\\s+)', ' ', node.className);
return true;
}
}
if(typeof(eregReplace)=="undefined"){
function eregReplace(search, replace, subject) {
return subject.replace(new RegExp(search,'g'), replace);
}
}
if(typeof(getTextContent)=="undefined"){
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;
}
}