Utilisateur:Roby/monobook.js

Une page de Wikipédia, l'encyclopédie libre.
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.
/**
 * Script de ajoutant une option de prévisualisation rapide.
 * 
 *
 * English: Add a Quick View option on the Edit pages.
 * This script add 2 new buttons into the "editButtons" div.
 * When QuickPrev button is press, the content of edit window 
 * is retreived and parsed using regular expressions.
 *
 * @author: fr:user:aoineko
 * @version: 0.2
 */
function addQuickPreview() 
{
  var QuickPreviewBtnTitle  = "Prévisualisation rapide de vos modifications [Alt + Q]";
  var QuickPreviewBtnValue  = "Prévisualisation rapide";
  var QuickPrevHideBtnTitle = "Cacher la prévisualisation rapide [Alt + H]";
  var QuickPrevHideBtnValue = "Cacher";

  var div = document.getElementsByTagName('div');
  for(var i = 0; i < div.length ; i++)
  {
    if(div[i].className == "editButtons") // search "editButtons" div
    {
      div[i].appendChild(document.createElement("br")); // add a <br/>

      var wpQuick = document.createElement("input"); // create and set the "QuickPrev" button
      wpQuick.setAttribute("id",        "wpQuick");
      wpQuick.setAttribute("name",      "wpQuick");
      wpQuick.setAttribute("title",     QuickPreviewBtnTitle);
      wpQuick.setAttribute("value",     QuickPreviewBtnValue);
      wpQuick.setAttribute("type",      "button");
      wpQuick.setAttribute("onclick",   "doQuickPreview();");
      wpQuick.setAttribute("tabindex",  "8");
      wpQuick.setAttribute("accesskey", "Q");
      div[i].appendChild(wpQuick);

      var wpHide = document.createElement("input"); // create and set the "Hide" button
      wpHide.setAttribute("id",        "wpHide");
      wpHide.setAttribute("name",      "wpHide");
      wpHide.setAttribute("title",     QuickPrevHideBtnTitle);
      wpHide.setAttribute("value",     QuickPrevHideBtnValue);
      wpHide.setAttribute("type",      "button");
      wpHide.setAttribute("onclick",   "hideQuickPreview();");
      wpHide.setAttribute("tabindex",  "9");
      wpHide.setAttribute("accesskey", "H");
      div[i].appendChild(wpHide);
    }
  }
}

/// Retrieve current code and parse it
function doQuickPreview() 
{
  var wpQuickPreview = document.getElementById("wpQuickPreview");
  if(!wpQuickPreview) 
  {
    /*var l = document.getElementsByTagName('div');
    for(var i = 0; i < l.length ; i++)
      if(l[i].classList.contains("previewnote"))
        wpQuickPreview = l;
    
    if(!wpQuickPreview)*/
    {
      wpQuickPreview = document.createElement("div");
      wpQuickPreview.setAttribute("style", "border:solid 1px gray; width:100%; margin-top:1em; margin-bottom:1em; padding:0.5em;");
      var wpSummaryLabel = document.getElementById("wpSummaryLabel");
      wpSummaryLabel.parentNode.insertBefore(wpQuickPreview, wpSummaryLabel);
    }
    wpQuickPreview.setAttribute("id",    "wpQuickPreview");
  }
  wpQuickPreview.style.display = 'block';

  wpTextbox1 = document.getElementById("wpTextbox1");
  var str = "=Prévisualisation rapide=\n" + wpTextbox1.value;
  var line = str.split(/\n/);
  var output = "";

  var list = 0;
  var tab  = 0;
  var pre  = false;

  for(var i = 0; i < line.length ; i++)
  {
    if(line[i][0] == ' ')
    {
      if(!pre)
      {
        pre = true;
        output += "<pre>\n";
      }
    }
    else if(pre)
    {
      pre = false;
      output += "</pre>\n";
    }

    output += line[i]

// Sign //
    .replace(/24 janvier 2006 à 07:33 (CET)/g, Date())
    .replace(/[[Utilisateur:Aoineko|A<small>☮</small>ineko]] [[Discussion Utilisateur:Aoineko|✍]] 24 janvier 2006 à 07:33 (CET)/g, "<span style='padding:0.2em; margin:0.5em; border:dashed 1px lightgreen;'>Signature</span> "+Date())
    .replace(/[[Utilisateur:Aoineko|A<small>☮</small>ineko]] [[Discussion Utilisateur:Aoineko|✍]]/g, "<span style='padding:0.2em; margin:0.5em; border:dashed 1px lightgreen;'>Signature</span>")

// Style //
    .replace(/'''''(.*?)''(.*?)'''/g, "<strong><em>$1</em>$2</strong>")
    .replace(/'''''(.*?)'''(.*?)''/g, "<em><strong>$1</strong>$2</em>")
    .replace(/'''(.*?)''(.*?)'''''/g, "<strong>$1<em>$2</em></strong>")
    .replace(/'''''(.*?)''''/g,       "<strong><em>'$1</em></strong>")
    .replace(/''''(.*?)''''/g,        "<strong><em>$1</em></strong>")
    .replace(/''''(.*?)'''/g,         "<strong>'$1</strong>")
    .replace(/'''(.*?)'''/g,          "<strong>$1</strong>")
    .replace(/'''(.*?)''/g,           "<em>'$1</em>")
    .replace(/''(.*?)''/g,            "<em>$1</em>")

// Title //
    .replace(/^=====(.*)=====/g, "<h5>$1</h5>")
    .replace(/^====(.*)====/g,   "<h4>$1</h4>")
    .replace(/^===(.*)===/g,     "<h3>$1</h3>")
    .replace(/^==(.*)==/g,       "<h2>$1</h2>")
    .replace(/^=(.*)=/g,         "<h1>$1</h1>")

// List //
    .replace(/^\*(.*)/g,  "<li>$1</li>")
    .replace(/^#(.*)/g,   "<li>$1</li>")
    .replace(/^:(.*)/g,   "<li>$1</li>")

// Link //
    .replace(/\{\{([^\|]*).*}}/g, "<span style='padding:0.2em; margin:0.5em; border:dashed 1px lightgreen;'>Modèle : $1</span>")
    .replace(/\[\[[Ii]mage:([^\|]*)[^\[]*\]\]/g, "<span style='padding:0.2em; margin:0.5em; border:dashed 1px lightblue;'>Image : $1</span>")
    .replace(/\[\[[Cc]atégorie:([^\|]*)[^\[]*\]\]/g, "<span style='padding:0.2em; margin:0.5em; border:dashed 1px #FF8080;'>Catégorie : $1</span>")
    .replace(/\[\[([^\[.]*)\|([^\[.]*)\]\]/g, "<a href='/wiki/$1' title='$1'>$2</a>")
    .replace(/\[\[([^\[.]*)\]\]/g,      "<a href='/wiki/$1' title='$1'>$1</a>")
/*
// Special //
    .replace(/\n\n/g,          "\n\n<br/>")
    .replace(/(^|\n)-{4}(?!~)/g, "<hr/>")

// Table //
    .replace(/(^|\n)\{\|(.*)/g, "$1<table $2>")
    .replace(/(^|\n)\|}/g, "$1</table>")
    .replace(/(^|\n)(\|.*)\|\|/g, "$1$2</td><td>")
    .replace(/(^|\n)\|[^-}](.*)/g, "$1</td>$2<td>")
    .replace(/(^|\n)(!.*)!!/g, "$1$2</th><th>")
    .replace(/(^|\n)![^-](.*)/g, "$1</th>$2<th>")
*/
    ;

    output += "\n";
  }
  wpQuickPreview.innerHTML = output;
}

/// Hide
function hideQuickPreview() 
{
  var wpQuickPreview = document.getElementById("wpQuickPreview");
  if(wpQuickPreview) 
  {
    wpQuickPreview.style.display = 'none';
  }
}

$(addQuickPreview);


// Onglet Purge

function OngletPurge() {
  var a = document.getElementById("p-cactions");
        if (a) 
        {
          var pageName = document.title.replace(" - Wikipédia", ""); 
          b = a.getElementsByTagName("ul");
                  
          if(b.length > 0)
          {
            b[0].innerHTML = b[0].innerHTML
            + '<li id="ca-nstab-user">'
            + '<a href="/w/index.php?action=purge&title=' + pageName + '">purger</a>'
            + '</li>';
          }
        }
      }

// Onglet Purge

$(OngletPurge);