User:Splarka/wbfilter.js

/* Watchlist line filter script, version [0.0.2] Originally from http://en.wikipedia.org/wiki/User:Splarka/wbfilter.js

Triggers on watchlists, lets you filter by byte change.

if(wgCanonicalSpecialPageName == 'Watchlist') addOnloadHook(watchlistByteFilter) function watchlistByteFilter { var obj = document.getElementById('contentSub') || document.getElementById('topbar') if(!obj) return; var wbf = document.createElement('div'); wbf.setAttribute('id','wbffrm'); wbf.style.color = 'black'; var fs = document.createElement('fieldset'); var lg = document.createElement('legend'); lg.appendChild(document.createTextNode('Byte change threshold filter')); fs.appendChild(lg); var lab1 = document.createElement('label'); lab1.appendChild(document.createTextNode('Byte threshold ')); lab1.setAttribute('for','wbfinput1'); fs.appendChild(lab1); var inp1 = document.createElement('input'); inp1.setAttribute('id','wbfinput1'); inp1.setAttribute('name','wbfinput1'); inp1.setAttribute('type','text'); fs.appendChild(inp1); var inp2 = document.createElement('input'); inp2.setAttribute('id','wbfinput2'); inp2.setAttribute('name','wbfinput2'); inp2.setAttribute('type','checkbox'); fs.appendChild(inp2); var lab2 = document.createElement('label'); lab2.style.fontSize = '200%' lab2.appendChild(document.createTextNode(String.fromCharCode(177) + ' ')); lab2.setAttribute('for','wbfinput2'); fs.appendChild(lab2); var sub1 = document.createElement('input'); sub1.setAttribute('type','button'); sub1.setAttribute('value','greater than'); addClickHandler(sub1,function { filterWbf(true) }); sub1.setAttribute('onclick',''); fs.appendChild(sub1) fs.appendChild(document.createTextNode(' ')); var sub2 = document.createElement('input'); sub2.setAttribute('type','button'); sub2.setAttribute('value','less than'); addClickHandler(sub2,function { filterWbf(false) }); fs.appendChild(sub2) wbf.appendChild(fs); obj.appendChild(wbf); }

function filterWbf(greater) { var plusminus = document.getElementById('wbfinput2').checked; var bt = parseInt(document.getElementById('wbfinput1').value); var docobj = document.getElementById('bodyContent') || document.getElementById('content') || document.body var pos = getElementsByClassName(docobj,'*','mw-plusminus-pos'); var neg = getElementsByClassName(docobj,'*','mw-plusminus-neg'); var nul = getElementsByClassName(docobj,'*','mw-plusminus-null'); var posneg = pos.concat(neg).concat(nul);

for(var i=0;i 0) { spans = pos.concat(nul); } else if(bt < 0) { spans = neg.concat(nul); } else { alert('bad input'); return; } for(var i=0;i Math.abs(bt) && greater) || (Math.abs(val) < Math.abs(bt) && !greater)) { spans[i].parentNode.style.backgroundColor = '#ffff99'; } } }

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(''); }