http://www.perlmonks.org?node_id=581764


in reply to Node ids by node titles

Good idea, it'd be nice to have the node id easily accessible for each reply.

Put this snippet in your free nodelet - it'll add "#node_id" after the reply title (ie #581764 for this node).

<script language="javascript"><!-- function add_node_ids() { var trs = document.getElementsByTagName('tr'); var i; for ( i = 0; i < trs.length; i++ ) { if ( trs[i].className == 'reply' ){ var anch = trs[i].getElementsByTagName( 'a' ); var id = anch[0].href.match( /\d+$/ ); var txt = document.createTextNode( " #" + id ); //or for [id://nnnnnn] style, //var txt = document.createTextNode( " [id://" + id + "]" ); anch[0].parentNode.insertBefore( txt, anch[0].nextSibling +); } } } add_node_ids(); </script><!-- end add_node_ids -->

Update: Tested on Firefox 1.507 & IE 6
Update 2: Only showed ids for new replies. Fixed to show id's for all replies. Added [id://nnnnnn].

Replies are listed 'Best First'.
Free Nodelet Hack: Node IDs by node titles
by jdporter (Paladin) on May 01, 2007 at 16:25 UTC

    Due to a recent patch, the above code no longer works.
    The following illustrates the necessary fix, which I've flagged with XXX:

    function add_node_ids() { var trs = document.getElementsByTagName('tr'); var i; for ( i = 0; i < trs.length; i++ ) { if ( trs[i].className == 'reply' ){ var anch = trs[i].getElementsByTagName( 'a' ); var id = anch[0].name; // XXX var ntre = document.createElement('input'); ntre.type = 'text'; ntre.name = 'see_Free_Nodelet_Settings'; ntre.value = "[id://" + id + "]"; anch[0].parentNode.insertBefore( ntre, anch[0].nextSibling.nextS +ibling ); } } }
    A word spoken in Mind will reach its own level, in the objective world, by its own weight