You are viewing our Forum Archives. To view or take place in current topics click here.
Get timestamps in your shoutbox NOW!
Posted:

Get timestamps in your shoutbox NOW!Posted:

tortuga
  • Blind Luck
Status: Offline
Joined: Dec 25, 200914Year Member
Posts: 2,314
Reputation Power: 1686
Status: Offline
Joined: Dec 25, 200914Year Member
Posts: 2,314
Reputation Power: 1686
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 thanked tortuga for this useful post:

Dusknoir (05-05-2017), Xbox (04-05-2017)
#2. Posted:
Status: Offline
Joined: Feb 27, 201113Year Member
Posts: 31,557
Reputation Power: 15112
Status: Offline
Joined: Feb 27, 201113Year Member
Posts: 31,557
Reputation Power: 15112
I don't know what the **** I just read.

But if sounded pretty tech savy.

Thanks for the share.

#3. Posted:
Saki
  • Retired Staff
Status: Offline
Joined: Apr 09, 201113Year Member
Posts: 4,993
Reputation Power: 14214
Motto: Wow crazy USA hamburger yes
Motto: Wow crazy USA hamburger yes
Status: Offline
Joined: Apr 09, 201113Year Member
Posts: 4,993
Reputation Power: 14214
Motto: Wow crazy USA hamburger yes
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
  • Summer 2021
Status: Offline
Joined: Jun 11, 200914Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200914Year Member
Posts: 9,897
Reputation Power: 3160
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.