Forum Moderators: open

Message Too Old, No Replies

Highlight threads started by certain members

Follow your favourites, avoid your enemies

         

RonPK

4:32 pm on Jun 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I haven't seen this on namaste's list [webmasterworld.com] of suggestions to make WebmasterWorld even more useful, but personally I would have appreciated an option to somehow mark new threads started by favourite members. Things you really don't want to miss. Or threads started by people you'd rather ignore but whose name you had already forgotten...

Fortunately this board allows us to insert pieces of HTML, script and CSS into the template (Control Panel > System Preferences). So I wrote a bit of code that scans a page for certain member names and that enables some custom CSS. It works on the pages that list all topics in a forum.

In the field 'Custom Code Insert Top', enter this:

<script>var fl = new Array('Brett_tabke','jenstar');</script><style>tr.my {background: #ff0;} span.my {font-weight: bold;}</style>

The <script> block contains a comma-separated list of quoted member names. It is not case sensitive.
The <style> block contains custom style rules:
* tr.my is the table row with subject, started by, messages et cetera.
* span.my is a <span>-element containing the member name.

All that should be on one line. Also note that the field takes no more than 500 characters.

In the field 'Custom Code Insert Bottom', enter this script:

<script>var re=new RegExp(),d=document,ce,nt,sp;for(var i=0;i<fl.length;i++){sp=0;nt='';re.compile('('+fl[i]+')','gi');ce=d.getElementsByTagName('center')[4];
while((result=re.exec(ce.innerHTML))!=null){nt+=ce.innerHTML.substring(sp,result.index)+'<span class="my">'+result[0]+'<\/span>';sp=re.lastIndex;}ce.innerHTML=nt+ce.innerHTML.substring(sp);}var as=d.getElementsByTagName('span');for(var i=0;i<as.length;i++){as[i].parentNode.parentNode.parentNode.className='my';}</script>

You don't need to edit anything in that script. Just make sure it all goes on one line. (I had to insert a line break before 'while' in order not to break this page's layout.)

The script is far from perfect: if someone would mention Brett_Tabke in a posting's subject or description, that would get highlighted too. Suggestions for a solution and for other improvements are welcome!

Tested and seen working in IE 6 (Win), Opera 8 (Win/Mac) and Firefox 1.0.4 (Win/Mac). Doesn't work in Safari...

mattglet

5:42 pm on Jun 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Brilliant.

Brett_Tabke

6:02 pm on Jun 22, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



There is a limit to doing this - 256 chars.

Best bet is to put stuff like this in an external iframe on your own site.

RonPK

7:58 am on Jun 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The value of the custom code fields' maxlength attribute is 500, and I had no problems with strings longer than 256 chars.

You can indeed put the script on your own server / site, and call it with <script src="http://www.example.com/myscript.js"></script>. It won't work in an iframe, because of cross domain scripting issues.
Putting the script on your own server may be handy if you're already using the custom code fields, e.g. for a custom site search box.