Utente:Valepert/toplaintext.js

Da Wikipedia, l'enciclopedia libera.
Vai alla navigazione Vai alla ricerca

Questa pagina definisce alcuni parametri di aspetto e comportamento generale di tutte le pagine. Per personalizzarli vedi Aiuto:Stile utente.


Nota: dopo aver salvato è necessario pulire la cache del proprio browser per vedere i cambiamenti (per le pagine globali è comunque necessario attendere qualche minuto). Per Mozilla / Firefox / Safari: fare clic su Ricarica tenendo premuto il tasto delle maiuscole, oppure premere Ctrl-F5 o Ctrl-R (Command-R su Mac); per Chrome: premere Ctrl-Shift-R (Command-Shift-R su un Mac); per Konqueror: premere il pulsante Ricarica o il tasto F5; per Opera può essere necessario svuotare completamente la cache dal menù Strumenti → Preferenze; per Internet Explorer: mantenere premuto il tasto Ctrl mentre si preme il pulsante Aggiorna o premere Ctrl-F5.

importScriptURI('https://rawgit.com/joaomsa/txtwiki.js/master/txtwiki.js')
var isPlainText = false;

function getLastRevID() {
  info = $.ajax({
    url:  mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/api.php?" + "&action=query&indexpageids&titles=" + wgPageName + "&format=json",
    async: false,
    dataType: 'json',
    success: function (response) {
      isPlainText = true;
      return (response)
    }
  });

  lastID = info.responseJSON.query.pageids[0]
  return lastID
}

function getWikiText(revID) {
  result = $.ajax({
    url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/api.php?" + "&action=query&prop=revisions&rvprop=content&rvlimit=1&titles=" + wgPageName + "&format=json",
    async: false,
    dataType: 'json',
    success: function (response) {
      return (response)
    }
  });
  
  text = result.responseJSON.query.pages[revID].revisions[0]["*"]
  return text;
}

function getLastRevWikiText() {
  id = getLastRevID()
  var text
  
  if (id != -1) {
    text = getWikiText(id)
  }
  return text
}

function getPlainText() {
  var plainText
  if (!isPlainText) {
    wikiText = getLastRevWikiText()
    if (wikiText != undefined) {
      plainText = txtwiki.parseWikitext(wikiText)
    }
    return plainText
  }
}

function showPlainText() {
  if(isPlainText) {
    $("#plaintext").show()
  } else {
    plainText = getPlainText()
    $("#mw-content-text").after("<div id=\"plaintext\"></div>")
    $("#plaintext").append("<p>" + plainText + "</p>")
  }
  $("#mw-content-text").hide()
  $("#toplain").attr("href", "javascript:hidePlainText()")
}

function hidePlainText() {
  $("#mw-content-text").show()
  $("#plaintext").hide()
  $("#toplain").attr("href", "javascript:showPlainText()")
}

$("#p-namespaces").append(" <a id=\"toplain\" href=\"javascript:showPlainText()\">(~)</a>")