User:Sudopeople/common.js

function isolateUser(query){ var resetResults = false; if (query === ''){ resetResults = true; }	console.log(resetResults);

var ul = document.getElementById('pagehistory'); var lis = ul.getElementsByTagName('li'); var userCount = 0;

//console.log(ul, lis);

for (var i = 0; i < lis.length; i++) { var li = lis[i]; if (li.getElementsByClassName('history-user').length < 1) {//make sure li has info we need continue; }		var liUserName = li.getElementsByClassName('history-user')[0].getElementsByTagName('a')[0].innerHTML; //console.log(liUserName, query); if (resetResults || liUserName == query) { li.style.display = ''; userCount++; } else { li.style.display = 'none'; }	}	if (document.getElementById('descriptionLi') === null) { var descriptionLi = document.createElement ( 'li' ); descriptionLi.id = 'descriptionLi'; descriptionLi.innerHTML = "No edits by "+query+" found in this result set. Try adding more results (eg. 500), or looking farther back."; ul.appendChild( descriptionLi ); }	if (userCount < 1) { document.getElementById('descriptionLi').style.display = ''; } else { document.getElementById('descriptionLi').style.display = 'none'; } }

var title = document.createElement( 'span' ); title.setAttribute ( 'id', '' ); title.innerHTML = 'Filter User: '; var box = document.createElement( 'input' ); box.setAttribute ( 'id', 'userhist-isolate' ); box.setAttribute ( 'type', 'text' ); //box.setAttribute ( 'value', user ); var button = document.createElement( 'input' ); button.setAttribute ( 'type', 'submit' ); button.setAttribute ( 'value', 'Go' ); button.setAttribute ( 'style', 'margin-left: 4px;' ); var resetButton = document.createElement( 'input' ); resetButton.setAttribute ( 'type', 'button' ); resetButton.setAttribute ( 'value', 'Reset' ); resetButton.setAttribute ( 'style', 'margin-left: 4px;' ); var form = document.createElement ( 'form' ); form.setAttribute ( 'style','border-bottom: 1px solid #2f6fab; margin-bottom: 10px; padding: 0 15px 15px;' ); form.appendChild ( title ); form.appendChild ( box ); form.appendChild ( button ); form.appendChild ( resetButton );

if ( resetButton.addEventListener ) { resetButton.addEventListener( 'click', function (evt) {		evt.preventDefault;		box.value = '';		isolateUser(box.value);	}, false ); } else { resetButton.attachEvent( 'onclick', function (evt) {		evt.preventDefault;		box.value = '';		isolateUser(box.value);	 } ); }

if ( form.addEventListener ) { form.addEventListener( 'submit', function (evt) {		evt.preventDefault;		isolateUser(box.value);	}, false ); } else { form.attachEvent( 'onsubmit', function (evt) {		evt.preventDefault;		isolateUser(box.value);	 } ); } var section = document.getElementById( 'histlegend' ); //console.log(section, section.firstChild); section.parentNode.insertBefore( form, section );