Jump to content

User:Js/markZeroEdits.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//[[user:js/markZeroEdits]]

function markZeroEdits(){

var i = -1, j, k, entry, plusminus, isHRDone
var rows, td, aa, sp, step
var firstEditor, thisEditor, isRevert

 mzRevertRegExp = window.mzRevertRegExp || /^(BOT[ -]*)?Reverted|^Reverting|^Undid revision /
 appendCSS(window.mzCSS || 'table.revert-edit *, table.zero-edit * {color:#777799; }\
table.revert-edit td {text-decoration: line-through}')

 while (entry=document.getElementById('mw-rc-closearrow-'+(++i))){//loop through all multiple edits
 //jsMsg(i + ' ' + entry)
  //check if this is a  0 size diff
  while ((entry=entry.parentNode) && entry.nodeName!='TR');
  plusminus = entry.cells[1].getElementsByTagName('span')[0]
  if (!plusminus || plusminus.className!='mw-plusminus-null') continue
  
  //get all collapsed edits inside hidden DIV
  rows = document.getElementById('mw-rc-subentries-' + (i)).firstChild.rows
  //some initial values
  firstEditor = '' //first editor (who is possibly reverted later)

  //check all edits from bottom, i.e. by the timeline
  for (j=rows.length-1; j>=0; j--){
    //find editor
    td = rows[j].cells[1]
    aa = td.getElementsByTagName('a')
    for (k=0; k<aa.length && /&oldid=/.test(aa[k].href); k++);
    thisEditor = aa[k].href
    //compare with previous editor
    if (!firstEditor){ //this is a beginning of possible edit-revert block
      firstEditor = thisEditor
      isRevert = false
      continue
    }else if (thisEditor==firstEditor && j>0){ //first editor keeps making several edits
      continue 
    }
    //we now have either a different editor of the last edit
    //find edit summary
	sp = getElementsByClassName(td, 'span', 'comment')[0]
    if (!sp) break
    //check if this was a revert
    if (!mzRevertRegExp.test(ts_getInnerText(sp).substring(1))) break
    //by default do not trust self reverts and reverts by unregs
    if (thisEditor==firstEditor && !window.mzTrustSelfRv) break
    if (/Special:Contributions/.test(thisEditor) && !window.mzTrustUnregRv) break
    //all checks done, this looks like a revert after all
    isRevert = true
    firstEditor = '' //get ready for the next block of edits
  }
  
  //categorize the entry
  while ((entry=entry.parentNode) && entry.nodeName!='TABLE');
  if (isRevert){
    entry.className += 'revert-edit'
    if (window.mzMoveReverts)
     do{
       step = entry.nextSibling; entry.parentNode.appendChild(entry); entry = step
     }while (entry && entry.nodeName != 'TABLE' && entry.nodeName != 'HR')
  }else{
    entry.className += 'zero-edit'
  }
 
 }//while

}

$(markZeroEdits)