User:Zenwhat/lifilter.js

var rightsLogOnly = (document.location.href.indexOf('type=rights')==-1 && document.location.href.indexOf('Log/rights')==-1) ? false : true if((wgPageName=='Special:Log') || (wgPageName=='Special:Linksearch') || queryString('lifilter')) addOnloadHook(filterLiButton) function filterLiButton { mw.util.addPortletLink('p-cactions','javascript:filterLiForm','Filter','ca-rxfilter','Open interactive log entry regex filter thingy'); if(window.AutoLoadLogsFilter) filterLiForm; } function filterLiForm { var instructions = (rightsLogOnly) ? 'Regex filter the space-delimited list of rights.' : 'Regex filter the plain text representation of this list.' //generate the form document.getElementById('ca-rxfilter').style.display = 'none'; var frm = document.getElementsByTagName('form')[0]; var rf = document.createElement('form'); rf.setAttribute('action','javascript:void(0)'); rf.setAttribute('id','rfform'); var fs = document.createElement('fieldset'); var is = document.createElement('p'); is.appendChild(document.createTextNode(instructions)); fs.appendChild(is); var lg = document.createElement('legend'); lg.appendChild(document.createTextNode('Filter list (javascript)')); fs.appendChild(lg); if(rightsLogOnly) { var sel = document.createElement('select'); sel.setAttribute('id','rfselect'); var op1 = document.createElement('option'); op1.appendChild(document.createTextNode('added rights')); sel.appendChild(op1); var op2 = document.createElement('option'); op2.appendChild(document.createTextNode('removed rights')); sel.appendChild(op2); var op3 = document.createElement('option'); op3.appendChild(document.createTextNode('added OR removed')); sel.appendChild(op3); var op4 = document.createElement('option'); op4.appendChild(document.createTextNode('added/removed/static')); sel.appendChild(op4); fs.appendChild(sel); }   var lab1 = document.createElement('label'); lab1.appendChild(document.createTextNode(' Regex string: ')); lab1.setAttribute('for','rfinput1'); fs.appendChild(lab1); fs.appendChild(document.createTextNode(' ')); var inp1 = document.createElement('input'); inp1.setAttribute('id','rfinput1'); inp1.setAttribute('name','rfinput1'); inp1.setAttribute('type','text'); fs.appendChild(inp1); var chk1 = document.createElement('input'); chk1.setAttribute('id','rfinput2'); chk1.setAttribute('name','rfinput2'); chk1.setAttribute('type','checkbox'); fs.appendChild(chk1); var lab2 = document.createElement('label'); lab2.appendChild(document.createTextNode('Invert ')); lab2.setAttribute('for','rfinput2'); fs.appendChild(lab2); var sub1 = document.createElement('input'); sub1.setAttribute('type','button'); sub1.setAttribute('value','filter'); sub1.setAttribute('onclick','filterLi(false)'); fs.appendChild(sub1) fs.appendChild(document.createTextNode(' ')); var sub2 = document.createElement('input'); sub2.setAttribute('type','button'); sub2.setAttribute('value','hilight'); sub2.setAttribute('onclick','filterLi(true)'); fs.appendChild(sub2) rf.appendChild(fs); frm.parentNode.insertBefore(rf,frm); }

function filterLi(hilight) { //grab options from form if(rightsLogOnly) var type = document.getElementById('rfselect').selectedIndex; var invert = document.getElementById('rfinput2').checked; var srch = document.getElementById('rfinput1').value; var rx = new RegExp(srch,'ig');

//grab the list of all  in the content var lis = document.getElementById('bodyContent').getElementsByTagName('li');

//iterate var rightrx = /^.*?User\:.*? from (.*?) to (.*?) \u200E.*?$/i  //the regex used to grab the Special:Log/rights changes for(var i=0;i<lis.length;i++) { if(rightsLogOnly) { //Special:Log/rights var oldr = gettext(lis[i]).replace(rightrx,'$1').replace(/\, /g,' '); var newr = gettext(lis[i]).replace(rightrx,'$2').replace(/\, /g,' '); var oldrl = oldr.split(' '); var newrl = newr.split(' '); for (var j=0;j objects var look = gettext(lis[i]); }   lis[i].style.display = ''; lis[i].style.backgroundColor = ''; if ((look.search(rx)!=-1 && !invert) || (look.search(rx)==-1 && invert)) { if(hilight) lis[i].style.backgroundColor = '#ffff99'; } else { if(!hilight) lis[i].style.display = 'none'; } } }

function gettext(object) { if (object.nodeType == 3) return object.nodeValue; var txt = []; var i=0; while(object.childNodes[i]) { txt[txt.length] = gettext(object.childNodes[i]); i++; } return txt.join(''); }