Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8063099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:54:28+00:00 2026-06-05T10:54:28+00:00

What this is all about I am currently working on a script for emoticons

  • 0

What this is all about

I am currently working on a script for emoticons on the Campfire Chat Service since they don’t have an emoticon feature. Right now it is running the emoticon really slowly since it uses a setInterval that is suppose to check ever 200 milliseconds if there is a new message in the chat. I do this by making two variables “a” and “b” with var a,b;. So then in the first setInterval I time it with 150 millisecond. Inside of this I just give the variable “a” the value of the HTML of the chat. Then in the second setInterval (200) I give the variable “b” the value of the HTML too but this is a different timing so now I check the HTML in an if statement and if it is different I run the function to change the Symbol to an emoticon. I did it this was to improve performance. Before it would check for emoticons even though no one in the Campfire Chat actually wrote something so there is no need to check for emoticons.

This is the complete function:

var a, b;
setInterval(function() {
    a = $('#chat').html();
    console.warn("Chat HTML has been Scanned");
}, 150);
var t = "0";
setInterval(function() {
    b = $('#chat').html();
    console.warn("Chat got scanned for Change in html.");
    if (emoOn == true) {
        if (t === $('#num12345').text()) {
            $(".participants").after('<div id="emote"><h3><span class="room_actions"><a href="javascript:void(0)" class="on" style="font-weight:bold;">On</a> | <a href="javascript:void(0)" class="off" style="cursor:pointer;">Off</a></span>Emoticons</h3></div>');
            $('#num12345').text("111")
        }
        if (a !== b) {
            turnOn();
            console.log("CHANGE")
        } else {
            turnOn("off");
        }
    }
}, 200)​;

The problem

As you can see in the above code I run 3 consoles. In the consoles I expect the “Chat HTML has been Scanned” warning to come for and then the “Chat got scanned for Change in html.” in that order for the whole time. But instead the “Chat HTML has been Scanned” warning shoes up twice it just doesn’t work like I image it to work.

And when a new message shows its suppose to log “Change” but most of the time it doesn’t and I think it is the problem of the setIntervals. It seems like they aren’t timing right. But I really don’t wanna say that JavaScript is causing this issue but I don’t know what else it could be. Also I’m using Chrome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:54:31+00:00Added an answer on June 5, 2026 at 10:54 am

    setInterval is asynchronous, so when your first call is waiting, the javascript interpreter moves on to it’s next job (in this case setting t to “0” and then your second setInterval call).

    Edit: I think the problem is that you’re defining your setInterval calls at the same time, yet the precision of javascript timers is not that great (see here: http://ejohn.org/blog/accuracy-of-javascript-time/).

    You could call the second setInterval after a setTimeout to give yourself a bit of a buffer:

    var a, b;
    setInterval(function() {
        a = $('#chat').html();
        console.warn("Chat HTML has been Scanned");
        var t = "0";
    }, 2000);
    setTimeout(function(){
        setInterval(function() {
            b = $('#chat').html();
            console.warn("Chat got scanned for Change in html.");
            if (emoOn == true) {
                if (t === $('#num12345').text()) {
                    $(".participants").after('<div id="emote"><h3><span class="room_actions"><a href="javascript:void(0)" class="on" style="font-weight:bold;">On</a> | <a href="javascript:void(0)" class="off" style="cursor:pointer;">Off</a></span>Emoticons</h3></div>');
                    $('#num12345').text("111")
                }
                if (a !== b) {
                    turnOn();
                    console.log("CHANGE")
                } else {
                    turnOn("off");
                }
            }
        }, 2000)​;
    
    }, 500);
    

    This will set up the second call to setInterval half a second after the first, you could get away with a lot less than that though (anything over 30ms should be enough).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been reading all over the web about this and still can't understand
I am currently working with a script that has lists that looks like this:
I keep hearing about DLL hell - what is this all about?
In my iPad App, I am using AQGridView. This app is all about matching
first of all this is my third question about web services here and i
Well, first of all sorry about this question it must be pretty straight forward
Before you all get pissy about me posting this question again, let me explain
I've a question about weka as this person: Hi all: I felt really strange
The compiler complains about this, after I activated all kind of warnings: For MyApp_Prefix.pch
(This is a question about a vague problem. I try to present all relevant

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.