User:OldBee/SkinManager.js
Appearance
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
//<source lang=javascript>
window.SkinManager_Init = function() {
/////////////////////////////////////////////// PARTIE PERSONNALISABLE ////////////////////////////////////////////////////////////////////////////////////////////
var myNameText = "Surligner mon pseudo";
var nomyNameText = "Ne plus surligner mon pseudo";
var showlinksText = "Afficher";
var hidelinkText = "Masquer";
var linkText = " les liens de cette page";
var nofullscreenText = "mode Normal";
var fullscreenText = "mode Plein écran";
var GetFavorisText = "Afficher";
var HideFavorisText = "Masquer";
var FavorisText = " les favoris";
/////////////////////////////////////////////// FIN DE LA PARTIE PERSONNALISABLE ////////////////////////////////////////////////////////////////////////////////////////////
if(["monobook","modern","vector"].indexOf(mw.config.get('skin')) !== -1){
var Favoris = document.getElementById("p-fav");
if(!Favoris) SkinManager_AddFavoritesPortlet() ;
}
var SkinManagerlinkDiv = document.getElementById('Skin_Manager_Div');
if(!SkinManagerlinkDiv){
SkinManagerlinkDiv = document.createElement("div");
SkinManagerlinkDiv.className = "Skin_Manager";
SkinManagerlinkDiv.id = "Skin_Manager_Div";
var sitenoticeDiv = document.getElementById("siteNotice");
if(!sitenoticeDiv) return;
sitenoticeDiv.parentNode.insertBefore(SkinManagerlinkDiv,sitenoticeDiv);
var LiensManager = document.createElement('ul');
LiensManager.id = "Skin_Manager_Ul";
SkinManagerlinkDiv.appendChild(LiensManager);
}
SkinManagerlinkDiv.style.display = "none";
addLinkToSkinManager( fullscreenText , 'javascript:SkinManager_fullscreen()' , fullscreenText);
addLinkToSkinManager( nofullscreenText , 'javascript:SkinManager_nofullscreen()' , nofullscreenText, '/');
addLinkToSkinManager();
addLinkToSkinManager( showlinksText , 'javascript:SkinManager_AffLink()' , showlinksText);
addLinkToSkinManager( hidelinkText , 'javascript:SkinManager_MasLink()' , hidelinkText, '/', linkText);
addLinkToSkinManager();
addLinkToSkinManager( myNameText , 'javascript:SkinManager_myName()' , myNameText);
addLinkToSkinManager( nomyNameText , 'javascript:SkinManager_nomyName()' , nomyNameText, '/');
addLinkToSkinManager();
addLinkToSkinManager( GetFavorisText , 'javascript:SkinManager_GetFavoris()' , GetFavorisText);
addLinkToSkinManager( HideFavorisText , 'javascript:SkinManager_HideFavoris()' , HideFavorisText, '/', FavorisText);
}
///////////////////////////////// AJOUT D'UN LIEN AU SKIN MANAGER ///////////////////////
window.addLinkToSkinManager = function( TextLink, HrefLink, TitleLink, TextBefore, TextAfter, Position){
if(!Position) Position = -1;
var LiensManager = document.getElementById('Skin_Manager_Ul');
if(!LiensManager) return;
var NewLinkInSkinManager = document.createElement('li');
if((!TextLink)&&(!HrefLink)){
NewLinkInSkinManager.innerHTML = " ";
}else{
if(!TitleLink) TitleLink = HrefLink;
if(!TextBefore) TextBefore = "";
if(!TextAfter) TextAfter = "";
if(HrefLink.indexOf("javascript:")==-1) HrefLink = "/wiki/" + HrefLink.replace(/ /g,"_");
var NewLink = document.createElement('a');
NewLink.href = HrefLink;
NewLink.title = TitleLink;
NewLink.appendChild(document.createTextNode(TextLink));
NewLinkInSkinManager.appendChild(document.createTextNode(TextBefore));
NewLinkInSkinManager.appendChild(NewLink);
NewLinkInSkinManager.appendChild(document.createTextNode(TextAfter));
}
if(Position==-1){
LiensManager.appendChild(NewLinkInSkinManager);
}else{
var Cible = LiensManager.getElementsByTagName('li')[Position];
if(!Cible){
}else{
LiensManager.insertBefore(NewLinkInSkinManager, Cible);
}
}
}
///////////////////////////////// FONCTION PLEIN ECRAN ///////////////////////
window.SkinManager_fullscreen = function() {
if( mw.config.get('skin') == "monobook" ){
var fullLink1 = document.getElementById("column-one");
if(!fullLink1){
var fullLink1 = document.getElementById("sidebox");
}
fullLink1.setAttribute( "style","display:none");
var fullLink2 = document.getElementById("footer");
fullLink2.setAttribute( "style","display:none");
var fullLink3 = document.getElementById("p-cactions");
fullLink3.setAttribute( "style","display:none");
var fullLink4 = document.getElementById("p-personal");
fullLink4.setAttribute( "style","display:none");
var fullLink5 = document.getElementById("column-content");
fullLink5.setAttribute( "style","margin: 0 0 0 0");
var fullLink6 = document.getElementById("content");
fullLink6.setAttribute( "style","margin: 0 0 0 0");
}
if( mw.config.get('skin') == "vector" ){
var fullLink1 = document.getElementById("mw-head");
fullLink1.setAttribute( "style","display:none");
var fullLink2 = document.getElementById("mw-panel");
fullLink2.setAttribute( "style","display:none");
var fullLink3 = document.getElementById("footer");
fullLink3.setAttribute( "style","display:none");
var fullLink5 = document.getElementById("content");
fullLink5.setAttribute( "style","margin: 0 0 0 0");
var fullLink5 = document.getElementById("page-base");
fullLink5.setAttribute( "style","height:0em");
}
if( mw.config.get('skin') == "modern" ){
var fullLink1 = document.getElementById("mw_portlets");
fullLink1.setAttribute( "style","display:none");
var fullLink2 = document.getElementById("p-cactions");
fullLink2.setAttribute( "style","display:none");
var fullLink3 = document.getElementById("p-personal");
fullLink3.setAttribute( "style","display:none");
var fullLink4 = document.getElementById("footer");
fullLink4.setAttribute( "style","display:none");
var fullLink5 = document.getElementById("mw_contentwrapper");
fullLink5.setAttribute( "style","margin-left: 0em ");
var fullLink6 = document.getElementById("mw_content");
fullLink6.setAttribute( "style","margin: 0 0 0 0");
}
}
window.SkinManager_nofullscreen = function() {
if( mw.config.get('skin') == "monobook" ){
var fullLink1 = document.getElementById("column-one");
if(!fullLink1){
var fullLink1 = document.getElementById("sidebox");
}
fullLink1.setAttribute( "style","display:block");
var fullLink2 = document.getElementById("footer");
fullLink2.setAttribute( "style","display:block");
var fullLink3 = document.getElementById("p-cactions");
fullLink3.setAttribute( "style","display:block");
var fullLink4 = document.getElementById("p-personal");
fullLink4.setAttribute( "style","display:block");
var fullLink5 = document.getElementById("column-content");
fullLink5.setAttribute( "style","margin: 0 0 .6em -12.2em");
var fullLink6 = document.getElementById("content");
fullLink6.setAttribute( "style","margin: 2.8em 0 0 12.2em");
}
if( mw.config.get('skin') == "vector" ){
var fullLink1 = document.getElementById("mw-head");
fullLink1.setAttribute( "style","display:block");
var fullLink2 = document.getElementById("mw-panel");
if($(fullLink2).hasClass("dbx-group")){
fullLink2.setAttribute( "style","position: absolute ! important; top: 0pt; left: 0pt; display: block;");
}else{
fullLink2.setAttribute( "style","display:block");
}
var fullLink3 = document.getElementById("footer");
fullLink3.setAttribute( "style","display:block");
var fullLink4 = document.getElementById("content");
fullLink4.setAttribute( "style","margin-left: 10em");
var fullLink5 = document.getElementById("page-base");
fullLink5.setAttribute( "style","height:5em");
}
if( mw.config.get('skin') == "modern" ){
var fullLink1 = document.getElementById("mw_portlets");
fullLink1.setAttribute( "style","display:block");
var fullLink2 = document.getElementById("p-cactions");
fullLink2.setAttribute( "style","display:block");
var fullLink3 = document.getElementById("p-personal");
fullLink3.setAttribute( "style","display:block");
var fullLink4 = document.getElementById("footer");
fullLink4.setAttribute( "style","display:block");
var fullLink5 = document.getElementById("mw_contentwrapper");
fullLink5.setAttribute( "style","margin: 0 0 0 -15em");
var fullLink6 = document.getElementById("mw_content");
fullLink6.setAttribute( "style","margin: 0 0 0 14em");
}
}
///////////////////////////////// AFFICHAGE/MASQUAGE FAVORIS ///////////////////////
window.SkinManager_GetFavoris = function(){
var fullLink1 = document.getElementById("p-fav");
fullLink1.setAttribute( "style","display:block");
}
window.SkinManager_HideFavoris = function(){
var fullLink1 = document.getElementById("p-fav");
fullLink1.setAttribute( "style","display:none");
}
///////////////////////////////// AFFICHAGE/MASQUAGE LIENS ///////////////////////
window.SkinManager_AffLink = function() {
var bodyContentNode = document.getElementById('bodyContent');
if(!bodyContentNode) bodyContentNode = document.getElementById('article');
if(!bodyContentNode) bodyContentNode = document.getElementById('mw_contentwrapper');
if(!bodyContentNode) return;
var Link1 = bodyContentNode.getElementsByTagName("A");
for(var i=0; i<Link1.length; i++)
$(Link1[i]).removeClass('Lien_Noir');
}
window.SkinManager_MasLink = function() {
var bodyContentNode = document.getElementById('bodyContent');
if(!bodyContentNode) bodyContentNode = document.getElementById('article');
if(!bodyContentNode) bodyContentNode = document.getElementById('mw_contentwrapper');
if(!bodyContentNode) return;
var Link2 = bodyContentNode.getElementsByTagName("A");
for(var i=0; i<Link2.length; i++)
$(Link2[i]).addClass('Lien_Noir');
}
///////////////////////////////// SURLIGNAGE PSEUDO ///////////////////////
window.SkinManager_highlightmyname = function(n,p) {
while(n!=null){
if(n.nodeType==3){
if(n.data.toLowerCase().indexOf(mw.config.get('wgUserName').toLowerCase())!=-1){
var ix=n.data.toLowerCase().indexOf(mw.config.get('wgUserName').toLowerCase());
var t1=ix?document.createTextNode(n.data.substr(0,ix)):null;
var t2=document.createTextNode(n.data.substr(ix,mw.config.get('wgUserName').length));
var t3=ix+mw.config.get('wgUserName').length==n.data.length?null:
document.createTextNode(n.data.substr(ix+mw.config.get('wgUserName').length));
var s1=document.createElement("span");
s1.style.backgroundColor="#DDBBBB";
s1.appendChild(t2);
var s2=document.createElement("span");
if(t1!=null) s2.appendChild(t1);
s2.appendChild(s1);
if(t3!=null) s2.appendChild(t3);
p.replaceChild(s2,n);
if(t3!=null) SkinManager_highlightmyname(t3,s2); //find remaining occurences in the new nodes
n=s2.nextSibling;
} else {
n=n.nextSibling;
}
} else {
if(n.firstChild!=null) SkinManager_highlightmyname(n.firstChild,n);
n=n.nextSibling;
}
}
}
window.SkinManager_myName = function() {
if( mw.config.get('skin') == "monobook" ){
SkinManager_highlightmyname(document.getElementById('bodyContent').firstChild,
document.getElementById('bodyContent'));
}
if( mw.config.get('skin') == "vector" ){
SkinManager_highlightmyname(document.getElementById('bodyContent').firstChild,
document.getElementById('bodyContent'));
}
if( mw.config.get('skin') == "modern" ){
SkinManager_highlightmyname(document.getElementById('mw_content').firstChild,
document.getElementById('bodyContent'));
}
}
window.SkinManager_nohighlightmyname = function(n,p) {
while(n!=null){
if(n.nodeType==3){
if(n.data.toLowerCase().indexOf(mw.config.get('wgUserName').toLowerCase())!=-1){
var ix=n.data.toLowerCase().indexOf(mw.config.get('wgUserName').toLowerCase());
var t1=ix?document.createTextNode(n.data.substr(0,ix)):null;
var t2=document.createTextNode(n.data.substr(ix,mw.config.get('wgUserName').length));
var t3=ix+mw.config.get('wgUserName').length==n.data.length?null:
document.createTextNode(n.data.substr(ix+mw.config.get('wgUserName').length));
var s1=document.createElement("span");
s1.style.backgroundColor="#FFFFFF";
s1.appendChild(t2);
var s2=document.createElement("span");
if(t1!=null) s2.appendChild(t1);
s2.appendChild(s1);
if(t3!=null) s2.appendChild(t3);
p.replaceChild(s2,n);
if(t3!=null) SkinManager_nohighlightmyname(t3,s2); //find remaining occurences in the new nodes
n=s2.nextSibling;
} else {
n=n.nextSibling;
}
} else {
if(n.firstChild!=null) SkinManager_nohighlightmyname(n.firstChild,n);
n=n.nextSibling;
}
}
}
window.SkinManager_nomyName = function() {
if( mw.config.get('skin') == "monobook" ){
SkinManager_nohighlightmyname(document.getElementById('bodyContent').firstChild,
document.getElementById('bodyContent'));
}
if( mw.config.get('skin') == "vector" ){
SkinManager_nohighlightmyname(document.getElementById('bodyContent').firstChild,
document.getElementById('bodyContent'));
}
if( mw.config.get('skin') == "modern" ){
SkinManager_nohighlightmyname(document.getElementById('mw_content').firstChild,
document.getElementById('bodyContent'));
}
}
///////////////////////////////// FAVORIS ///////////////////////
/////////////////////////////// PARTIE PERSONNALISABLE
// ------------------- POPUPS
// popup titre //
window.PopupTitle_fav = "Cliquer pour ajouter la page courante aux favoris" ;
// popup aide (?) //
window.PopupHelp_fav = "INFORMATION : Cette liste est stockée sur un cookie local. Si vous effacez vos cookies, cette liste disparaîtra." ;
// popup retrait [-] //
window.PopupRemove_fav = "Cliquer pour retirer de la liste la page : " ;
// ------------------- TEXTES
// titre de la boîte //
window.Title_fav = "Ajouter aux favoris" ;
// texte de la boîte vide //
window.NoFavorites_fav = "Vous n'avez pas de favoris." ;
// ------------------- PARAMÈTRES
// début de l'URL des liens //
window.Path_fav = mw.config.get('wgServer') + mw.config.get('wgArticlePath').split('$1').join(''); ;
// affichage de l'aide (icône (?) à droite du titre) //
window.ShowHelp_fav = false;
/////////////////////////////// FIN DE LA PARTIE PERSONNALISABLE
// * création du panneau *
window.SkinManager_AddFavoritesPortlet = function() {
var span_fav = document.createElement( "span" );
span_fav.setAttribute( "title",PopupTitle_fav );
span_fav.setAttribute( "fixdabsx","3");
span_fav.setAttribute( "requireclick","off");
var a_fav = document.createElement( "a" );
a_fav.setAttribute( "href", "javascript:SkinManager_storePage()" );
var title_fav = document.createTextNode( Title_fav ) ;
a_fav.appendChild( title_fav ) ;
span_fav.appendChild( a_fav ) ;
if (ShowHelp_fav == true){
var spanhelp_fav = document.createElement( "span" );
spanhelp_fav.setAttribute( "title", PopupHelp_fav );
spanhelp_fav.setAttribute( "fixdabsx","3");
spanhelp_fav.setAttribute( "requireclick","off");
spanhelp_fav.setAttribute( "style","cursor:pointer");
var help_fav = document.createTextNode( " (?)" ) ;
spanhelp_fav.appendChild( help_fav ) ;
}
var h5_fav = document.createElement( "h3" );
h5_fav.appendChild( span_fav ) ;
if (ShowHelp_fav == true){
h5_fav.appendChild( spanhelp_fav ) ;
}
var ul_fav = document.createElement( "ul" );
ul_fav.id = "FavoriList";
// * insertion du panneau (suivant le mw.config.get('skin') actif) *
if((mw.config.get('skin')=="monobook")||(mw.config.get('skin')=="chick")||(mw.config.get('skin')=="myskin")||(mw.config.get('skin')=="simple")){
var Portlet_ClassName = "portlet";
var PBody_ClassName = "pBody";
var Element_Id = 'p-search';
}else if(mw.config.get('skin')=="modern"){
var Portlet_ClassName = "portlet";
var PBody_ClassName = "pBody";
var Element_Id = 'p-search';
}else if(mw.config.get('skin')=="vector"){
var Portlet_ClassName = "portal";
var PBody_ClassName = "body";
var Element_Id = 'p-tb'
}else{
var Portlet_ClassName = false;
}
if(!Portlet_ClassName) return;
var Element = document.getElementById(Element_Id);
if(!Element) return;
var div_fav = document.createElement( "div" );
div_fav.className = PBody_ClassName ;
div_fav.appendChild( ul_fav ) ;
var portlet_fav = document.createElement( "div" ) ;
portlet_fav.className = Portlet_ClassName ;
portlet_fav.id = "p-fav" ;
portlet_fav.appendChild( h5_fav ) ;
portlet_fav.appendChild( div_fav ) ;
Element.parentNode.insertBefore( portlet_fav, Element);
SkinManager_UpdateFavoritesList("FavoriList");
}
// * mise à jour de la liste de favoris *
window.SkinManager_UpdateFavoritesList = function(UL){
var ul_fav = document.getElementById(UL);
if(!ul_fav) return;
while(ul_fav.firstChild){ul_fav.removeChild(ul_fav.firstChild);}
var pageListTitle = SkinManager_getCookie("pageListTitle");
if (pageListTitle != "" && pageListTitle != null) {
pSplitTitle = pageListTitle.split('SPLIT');
for (a=0;a<pSplitTitle.length;a++) {
if (pSplitTitle[a] != '' && pSplitTitle[a] != 'null') {
var Title = decodeURIComponent(pSplitTitle[a]).replace(/_/g," ");
var EncodedTitle = encodeURIComponent(Title);
var li_fav = document.createElement( "li" );
li_fav.id = "n-fav_"+[a] ;
li_fav.className = "favorite" ;
var spanaCR_fav = document.createElement( "span" );
spanaCR_fav.setAttribute( "title", PopupRemove_fav + Title );
spanaCR_fav.setAttribute( "fixdabsx","3");
spanaCR_fav.setAttribute( "requireclick","off");
spanaCR_fav.setAttribute( "style","cursor:pointer");
var aCR_fav = document.createElement( "a" );
aCR_fav.setAttribute( "href", "javascript:SkinManager_removePage('" + Title.replace(/'/g, "\\'") + "')" );
var smallR_fav = document.createElement( "small" );
var font_fav = document.createElement( "font" );
font_fav.setAttribute( "color", "red" );
var textaCR_fav = document.createTextNode( "[-]");
font_fav.appendChild( textaCR_fav );
smallR_fav.appendChild( font_fav );
aCR_fav.appendChild( smallR_fav );
spanaCR_fav.appendChild( aCR_fav ) ;
var spanaC_fav = document.createElement( "span" );
spanaC_fav.setAttribute( "title", "" + Title + "");
spanaC_fav.setAttribute( "fixdabsx","3");
spanaC_fav.setAttribute( "requireclick","off");
spanaC_fav.setAttribute( "style","cursor:pointer");
var aC_fav = document.createElement( "a" );
aC_fav.setAttribute( "href", "" + Path_fav + Title +"");
var smallT_fav = document.createElement( "small" );
Raccourci = pSplitTitle[a]
Raccourci = Raccourci.replace(/Spécial:/g,"Sp:");
Raccourci = Raccourci.replace(/Utilisateur:/g,"Ut:");
Raccourci = Raccourci.replace(/Wikipédia:/g,"Wp:");
Raccourci = Raccourci.replace(/Fichier:/g,"F:");
Raccourci = Raccourci.replace(/Catégorie:/g,"Cat:");
Raccourci = Raccourci.replace(/Aide:/g,"A:");
Raccourci = Raccourci.replace(/MediaWiki:/g,"MW:");
Raccourci = Raccourci.replace(/Modèle:/g,"Mod:");
Raccourci = Raccourci.replace(/Portail:/g,"Pt:");
Raccourci = Raccourci.replace(/Projet:/g,"Pj:");
Raccourci = Raccourci.replace(/^Discussion/g,"D");
Raccourci = Raccourci.replace(/_/g," ");
var textaC_fav = document.createTextNode( "" + Raccourci + "") ;
smallT_fav.appendChild( textaC_fav ) ;
aC_fav.appendChild( smallT_fav );
spanaC_fav.appendChild( aC_fav ) ;
li_fav.appendChild( spanaCR_fav );
li_fav.appendChild( spanaC_fav );
ul_fav.appendChild( li_fav );
}
}
} else {
var li_fav = document.createElement( "li" );
var nofav_fav = document.createTextNode( NoFavorites_fav );
li_fav.appendChild( nofav_fav );
ul_fav.appendChild( li_fav );
}
}
// * Ajout d'une page à la liste de favoris *
window.SkinManager_storePage = function(){
thisPageTitle = mw.config.get('wgPageName').replace(/_/g," ");
var pageListTitle = SkinManager_getCookie("pageListTitle");
var linkFound = false;
if (pageListTitle != "" && pageListTitle != null) {
pSplit = pageListTitle.split('SPLIT');
for (a=0;a<pSplit.length;a++) {
if(pSplit[a] == thisPageTitle) linkFound = true;
}
}
if (!linkFound) {
if (pageListTitle == null || pageListTitle == 'SPLIT') {
pageListTitle = thisPageTitle;
} else {
pageListTitle += 'SPLIT' + thisPageTitle;
}
SkinManager_setCookie("pageListTitle",pageListTitle);
SkinManager_UpdateFavoritesList("FavoriList");
}
}
// * Suppression d'une page de la liste *
window.SkinManager_removePage = function(Title){
var pageListTitle = SkinManager_getCookie("pageListTitle");
var linkList = ""
if (pageListTitle != "" && pageListTitle != null) {
pSplitTitle = pageListTitle.split('SPLIT');
for (a=0;a<pSplitTitle.length;a++) {
pSplitTitle[a] = pSplitTitle[a].replace(/_/g," ");
if (pSplitTitle[a] != Title && pSplitTitle[a] != '') linkList += 'SPLIT' + pSplitTitle[a];
}
SkinManager_setCookie("pageListTitle",linkList);
SkinManager_UpdateFavoritesList("FavoriList");
}
}
// * Mise à jour du cookie *
window.SkinManager_setCookie = function(cookieName, cookieValue){
var now = new Date();
var nextYear = new Date(now.getTime() + 1000 * 60 * 60 * 24 * 365 );
return mw.cookie.set(cookieName, cookieValue, {expires:nextYear, path:"/"});
}
// * Interrogation du cookie *
window.SkinManager_getCookie = function(cookieName){
return mw.cookie.get(cookieName);
}
///////////////////////////////// STYLES ///////////////////////
if(typeof(SkinManagerCSSLoaded)=="undefined"){
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:OldBee/SkinManager.css&action=raw&ctype=text/css', 'text/css');
var SkinManagerCSSLoaded = true;
}
///////////////////////////////// AFFICHAGE SKIN MANAGER ///////////////////////
$( function(){
mw.loader.using( 'mediawiki.cookie', SkinManager_Init );
});