You are viewing our Forum Archives. To view or take place in current topics click here.

Get timestamps in your shoutbox NOW!Posted:

tortuga
  • Wizard
Status: Offline
Joined: Dec 25, 20098 Year Member
Posts: 2,312
Reputation Power: 530
Thanks to our constant complaining, telli has finally decided to consider adding timestamps to the shoutbox.

You can check for yourself by inspecting the HTML for each shout. You'll notice there is a new child inside of the shout div whose contents are a readable timestamp!

[ Register or Signin to view external links. ]

This change happened only two hours ago from now! Don't ask me how I know this!

For now - the timestamps are hidden, as indicated by that ui-helper-hidden class. By removing them, we'll have those timestamps we've been wanting so bad!

The following line does that:


$( '.shout-stamp' ).removeClass( 'ui-helper-hidden' )


This uses jQuery to select every HTML element that has the shout-stamp class and removes from those elements the offending class described above. However, this will only do it once. We need a way to execute the above line of code several times. We can either enclose the above line in a function and stick that into a setInterval, but that'll be unnecessary work.

I've chosen to use a [ Register or Signin to view external links. ] to observe the DOM for changes to the shoutbox. This is smoother than the setInterval-method because we can actually synchronize the class removal with shout updates from our side, whereas there is no way to synchronize the aforementioned interval with the GET request the shoutbox issues to get new shouts.

The code is then as follows (expand this one) -


$( '.shout-stamp' ).removeClass( 'ui-helper-hidden' )

let observer = new MutationObserver( mutations =>
    mutations.forEach( mutation => {
        if ( mutation.addedNodes.length == 1) {
            $( mutation.addedNodes[ 0 ] ).children( '.shout-stamp' ).removeClass( 'ui-helper-hidden' )
        }
    })
)

observer.observe( $( '#chatwindow' )[ 0 ], { childList: true } )

The Following 2 Users Say Thank You to tortuga For This Useful Post:

Dusky (05-05-2017), Xbox (04-05-2017)
#2. Posted:
Status: Offline
Joined: Feb 27, 20117 Year Member
Posts: 26,453
Reputation Power: 3568
I don't know what the **** I just read.

But if sounded pretty tech savy.

Thanks for the share.

#3. Posted:
Saki
  • PC Master Race
Status: Offline
Joined: Apr 09, 20117 Year Member
Posts: 4,534
Reputation Power: 3294
Motto: Fanatical like a demon
I'm from the fuutureee

[ Register or Signin to view external links. ]

In all seriousness, he added this earlier today, looks like more SB goodies for us
#4. Posted:
speed
  • 2000 Thanks
Status: Offline
Joined: Jun 11, 20099 Year Member
Posts: 9,897
Reputation Power: 3150
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
In reference to your code, don't overcomplicate things that have a simple solution.

$('.shout-stamp').livequery(function() {
    $(this).removeClass('ui-helper-hidden');
});
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.