Benutzer:Ca$e/AutoRevert2

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

/*

*/
// Urheber:         Benutzer Plenz
// Modifiziert von: Benutzer Ca$e
// siehe http://greasemonkey.mozdev.org/

function CoRead(Label)                       // Label suchen, Wert zurueckgeben
{
   var co = document.cookie;
   var ii = co.indexOf(Label);
   if (ii < 0) {return -1}
   var ii = co.indexOf("=", ii + 2) + 1;
   var jj = co.indexOf(";", ii);
   if (jj < 0) (jj = 99999);
   co = co.slice(ii, jj);
   return co;
}


function BaseLink(li)
{
  if (li.search(/http:/) < 0)
  {
    if (li.substr(0, 1) == "/") {li = li.substr(1, 99)}   // Slash am Anfang weg
    var ba = window.location.href;
    ba = ba.substr(0, ba.search(/org\//) + 4);            // nur bis Slash
    li = ba + "/" + li;
  }
  return(li);
}




(function() {
  var ti, ul, li, va, da, ip, hr, i;
  ti = window.document.getElementsByTagName("TITLE")[0];
  ti = ti.firstChild.nodeValue;

  if (ti.search(/Beobachtungsliste/) > -1)
  {
    for (i = 1; i < 5; i++)
    {
      ip = window.document.getElementsByTagName("A")[i];
      if (ip.getAttribute("href").search(/Userlogin/) > -1)
      {
        ip = BaseLink(ip.getAttribute("HREF"));
        window.location.href = ip;
      }
    }
  }
/*
  if (ti.search(/Anmelden/) > -1)
  {
    ip = window.document.getElementById("wpName1");
    ip.value = "BenutzernameHierEintragen";
    ip = window.document.getElementById("wpPassword1");
    ip.value = "PasswortHierEintragen";
    ip = window.document.getElementById("wpRemember");
    ip.checked = 1;
    ip = window.document.getElementsByName("wpLoginattempt")[0];
    ip.click();
  }
*/
  if (ti.search(/Anmeldung erfolgreich/) > -1)
  {
    for (i = 1; i < 15; i++)
    {
      ip = window.document.getElementsByTagName("A")[i];
      if (ip.getAttribute("href").search(/Watchlist/) > -1)
      {
        window.location.href = BaseLink(ip.getAttribute("HREF"));
      }
    }
  }

  if (ti.search(/Versionen\/Autoren/) > -1)
  {
    ul = document.getElementById("pagehistory");
    li = ul.firstChild;                   // LI oder (Text)
    i = 1;                                // mache "(Revert)" unsichtbar
    while (li)
    {
      if (li.nodeType > 1) {li = li.nextSibling}  // (Text) --> LI
      if (! li) {break}                           // kein LI mehr
      ip = li.firstChild;                 // (Text)
      while (ip)
      {
        ip = ip.nextSibling;
        if (ip && ip.nodeName == "A" && ip.getAttribute("href").search(/&diff=/) < 0) {break}
      }
      if (ip)
      {
        hr = ip.getAttribute("href");       // Link auf diese Version
        da = ip.firstChild.data;            // Datum der Version
        va = document.createElement("A");
        va.appendChild(document.createTextNode("(Revert)"));
        if (i < 1)
        {
          va.setAttribute("title", "Revert auf diese Version");
          va.setAttribute("href", hr);
          va.setAttribute("onClick", "javascript:AutoRevert(\"" + da + "\")");
        }
        else
        {
          va.setAttribute("style", "visibility:hidden");
          i = 0;
        }
        li.insertBefore(va, ip);
        va = document.createTextNode(" ");
        li.insertBefore(va, ip);
        li = li.nextSibling;
      }
      else
      {
        alert("BREAK");
        break;
      }
    }
    ul = window.document.getElementsByTagName("HEAD")[0];
    li = document.createElement("SCRIPT");
    li.setAttribute("type", "text/javascript");
    va = "<!--\n";
    va = va + "function AutoRevert(datum)\n";
    va = va + "{\n";
    va = va + "  document.cookie = \"autorevert=1; path=/\";\n";
    va = va + "  document.cookie = \"autorevdat=\" + datum + \"; path=/\";\n";
    va = va + "}\n";
    va = va + "//-->\n";
    li.appendChild(document.createTextNode(va));
    ul.appendChild(li);
    //alert("appended");
  }


  if (CoRead("autorevert") > 0)       // fuer jede Seite: Autorevert-Cookie?
  {
    if (ti.search(/Bearbeiten von/) > -1)
    {
      document.cookie = "autorevert=0; path=/";
      ip = window.document.getElementsByName("wpSummary")[0];
      va = "Revert wegen Spam oder Vandalismus auf Version vom ";
      va = va +  CoRead("autorevdat");
      ip.value = va;
//      ip = window.document.getElementsByName("wpSave")[0];
//      ip.click();
    }
    else
    {
        ip1 = window.document.getElementById("ca-edit");      
        ip2 = ip1.getElementsByTagName("A");
        ip = ip2[0].getAttribute("href");
        if (ip2 && ip.search(/action=edit.oldid/) > -1)       
        {
          window.location.href = BaseLink(ip);  // --> Seite bearbeiten
        }
    }
  }


})();
/*

*/