Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

fireindy

fireindy Avatar

**
Official Member

114


May 2007
Im working on a code for my forum that puts the mini-profile info above posts. But it only does it for the last post. I tried while() loops, but where I put them, the script continues forever and freezes. Heres what I have:

<script>
/*Post Mod */
function make_posts(){
var td = document.getElementsByTagName("td");
var theTD = document.createElement("TD");
var theTR = document.createElement("TR");
theTD.width = '100%';
theTD.height = '50'
theTD.colSpan='2'
theTD.className = 'windowbg'
for(s=0;s<td.length;s++){
if(td.width=="20%" && td.innerHTML.match(/(Posts:|Guest)/i)){
theTD.innerHTML = td.innerHTML
theTR.appendChild(theTD);
td.style.display = 'none'
}
}
for(i=0;i<td.length;i++){
if(td.width=="5%"){
td.style.display = 'none';
td.appendChild(theTR);
}
}
for(m=0;m<td.length;m++){
if(td[m].innerHTML.match(/Author/i) && td[m].width =='20%'){
td[m].style.display = 'none';
}
}
}
if(location.href.match(/thread/i)){
make_posts();
}
</script>


Just point me in the way to make it move for every post.



(¯`•DregondRahl•._)

(¯`•DregondRahl•._) Avatar
Remanifesting-Eternal

***
Dedicated Member

239


September 2006
there are several methods of approaching it, but this idea really came from Chris:


<script>

/*Post Mod */

function make_posts(){

var td = document.getElementsByTagName("td");

for(i = 0; i <td.length; i ++){

if(td.width == "20%" && td.innerHTML.match(/(<b>Poll<\/b><\/font>|Author)/i)){
td.style.display = "none";

} else if(td.width == "20%" && td.innerHTML.match(/(Posts:|Guest)/i)){
td.parentNode.parentNode.insertRow(td.parentNode.rowIndex).appendChild(td);
}
}
}

if(location.href.match(/thread/i)){
make_posts();
}

</script>



you had the right idea, but you didn't consider that each post needs a new line when you were creating elements and a few other thing, the snippet above is actually a faster approach to moving the miniprofile on top, especially because your not creating any new elements other than the insertRow() which adds a TR for each MP, and plus the row index so it goes to each one.

Bla bla Yadda yadda, the obvious advantages is the speed, and you don't need to set the mp's class name and other attributes. Haven't tested it really, just scribbled it up but i remmebr testing it on FF yesterday, so tell me if it workies.


Last Edit: Jul 20, 2007 22:00:34 GMT by (¯`•DregondRahl•._)




fireindy

fireindy Avatar

**
Official Member

114


May 2007
It works Dregond, thanks. Its always the little things that mess me up :) Thanks for the help.


newBookmarkLockedFalling