User:Invitatious/unsigned2.js

//<pre><nowiki>

// Below (unsigned2.js version 1.3,) by Invitatious. Dual-licensed under the terms of the GFDL v1.2 or the GPL v2.
// New features in this version: you can now choose an edit from the last 16.
function addSigWikiCode() {
  // From revision 28011729 of [[en:Wikipedia:WikiProject_User_scripts/Scripts/Get_tidy_title]]
  function aswcGet_tidy_title() {
    var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
    // cut everything up to "title=" from the start and everything past "&action=edit" from the end
    editlk = editlk.substring(editlk.indexOf('title=') + 6, editlk.lastIndexOf('&action=edit'));
    return editlk;
  }
  // LOCALIZABLE STRINGS START.
  var lsMonth_names = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
  lsConflict = "Edit conflict.",
  lsDialog1 = "Please select an edit below:\n\n",
  lsDialog2 = "Unsigned edit number:",
  lsInvalid1 = "Please enter a valid number or cancel this operation.",
  lsInvalid2 = "This is not a valid choice. Please choose another option.",
  lsNoRev = "No revisions found. Does the page exist?",
  lsNoXMLHTTP = "Couldn't get XMLHTTP!";
  // LOCALIZABLE STRINGS END
  var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : false // Try to use native XMLHTTP
  if (!xmlhttp && window.ActiveXObject) {
 // ActiveX XMLHTTP
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
    if (!xmlhttp) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (xmlhttp) {
    xmlhttp.open("GET", "/w/query.php?format=xml&what=revisions&rvlimit=16&rvcomments&titles=" + aswcGet_tidy_title()); // Get timestamp, user, summary of last 16 edits
    xmlhttp.onreadystatechange = function() {


    if (xmlhttp.readyState != 4) return;
    var xmldoc = xmlhttp.responseXML;
    if (!xmldoc.documentElement && window.ActiveXObject) { // IE workaround suggested by [[User:Olliminatore]]
      document.body.style.backgroundColor = "#CCCCFF"; // Debugging aid
      xmldoc = new ActiveXObject("Microsoft.XMLDOM");
      xmldoc.async = false;
      xmldoc.loadXML(xmlhttp.responseText);
    } else {
      var revisions = xmldoc.documentElement.getElementsByTagName("rv"); // Get the revisions
    }
    if (revisions.length > 0) {
      var t = revisions[0].getAttribute("timestamp").replace(/[^0-9]/g, ""); // Get rid of non-numeric characters in timestamp
      if(t != document.editform.wpEdittime.value) { // Detect an edit conflict
        alert(lsConflict);
        return;
      }
      var dialog_text = lsDialog1;
      var edit_data = [];
      for (var n = 0; n < revisions.length; n++) { // Extract edit data and build dialog text
        if (revisions[n].getAttribute("minor") != null) continue; // Skip minor edits
        edit_data[n] = { timestamp: revisions[n].getAttribute("timestamp").replace(/[^0-9]/g, ""), 
                         user: revisions[n].getAttribute("user"),
                         comment: revisions[n].getAttribute("comment") };
        dialog_text += ("[" + n.toString(16).toUpperCase() + "] " + edit_data[n].timestamp + " " +
         edit_data[n].user + ": " + edit_data[n].comment).substring(0, 80) + "\n";
        
      }
      while (true) {
        if (navigator.product == "Gecko") {
          var unsigned_edit = prompt(dialog_text + "\n" + lsDialog2, "0"); // for Mozilla
        } else {
          alert(dialog_text); // for IE or other
          var unsigned_edit = prompt(lsDialog2, "0"); // for IE or other
        }
        if (unsigned_edit == null) { // Cancel button
          return;
        } else if (isNaN(unsigned_edit = parseInt(unsigned_edit, 16))) { // Non-numeric input
          alert(lsInvalid1);
        }
        else if (!(unsigned_edit = edit_data[unsigned_edit])) { // Non-existent edit
           alert(lsInvalid2);
        } else {
        t = unsigned_edit.timestamp; // So the full name doesn't have to be used
        // LOCALIZABLE STRINGS START (enwiki)
        insertTags("", " {{subst:unsigned2|" + t.substring(8, 10) + ":" + t.substring(10, 12) + ", " + (t.substring(6, 8) - 0) + " " + lsMonth_names[t.substring(4, 6) - 1] + " " + t.substring(0, 4) + "|" + unsigned_edit.user + "}}", "");
        // LOCALIZABLE STRINGS END
        return;
        }
      }
    } else { // No revisions
      alert(lsNoRev);
    }


    }; xmlhttp.send(null);
  } else {
    alert(lsNoXMLHTTP); // No XMLHTTP
    return;
  }
}
addOnloadHook(function(){
  // From revision 28011435 of [[en:Wikipedia:WikiProject_User_scripts/Scripts/Add_LI_link]]
  function aswcAddlilink(tabs, url, name, id, title, key) {
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    if(id) li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    if(id)
    {
        if(key && title)
        {
            ta[id] = [key, title];
        }
        else if(key)
        {
            ta[id] = [key, ''];
        }
        else if(title)
        {
            ta[id] = ['', title];
        }
    }
    // re-render the title and accesskeys from existing code in wikibits.js
    akeytt();
    return li;
} 
//
  if (/[&?]action=edit/.test(location.search)) {
    aswcAddlilink(document.getElementById('p-cactions').getElementsByTagName('ul')[0], "javascript:addSigWikiCode();", /* LOCALIZABLE STRINGS START */ "unsigned2" , "ca-unsigned2", "Mark unsigned comment", "" /* LOCALIZABLE STRINGS END */);
  }
});
// Above by Invitatious. Dual-licensed under the terms of the GFDL v1.2 or the GPL v2.
//</nowiki></pre>

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.