Javascript that replaces

Asked

Viewed 58 times

2

I have a Javascript code that was supposed to replace the one marked below: inserir a descrição da imagem aqui

The platform of this chatbox is FORUMEIROS and the code I’m using is as follows::

   $(window).load(function() {
      var chatbox_script = function() {
        var overrided = Chatbox.prototype.refresh;
        Chatbox.prototype.refresh = function(data) {
          overrided.call(this, data);
          $('.chatbox-username').each(function(){
            this.previousSibling&&$.trim(this.previousSibling.nodeValue)=="@"&&$(this.previousSibling).replaceWith('<img src="http://i.imgur.com/zICIAne.png" /> ')
          })
        };
      };
      var s=document.createElement('script');s.text="("+chatbox_script.toString()+")();";$('object[data^="/chatbox/index.forum"],iframe[src^="/chatbox/index.forum"]').each(function(){try{$(this.contentDocument||this.contentWindow.document).find("#chatbox").closest("html").find("head").first().each(function(){this.appendChild(s.cloneNode(true))})}catch(a){}})
    });

Does the code have some error?

  • that @ was to be replaced by an image ? give a better indentation in this javascript code please.

  • Open the Chrome browser console, in the "console" tab put a 'console.log($. Trim(this.previousSibling.nodeValue))dentro desse$('.chatbox-username'). each(Function(){ ... })` and see what it returns. From what I’m seeing this code comes an Minify.

  • Did not return anything. Yes, you are supposed to replace @ with the image in the source. > http://i.imgur.com/zICIAne.png

1 answer

1


Dude, try it this way, I’m kind of an amateur but maybe it’ll help:

$(window).load(function() {
  var chatbox_script = function() {
    var overrided = Chatbox.prototype.refresh;
    Chatbox.prototype.refresh = function(data) {
      overrided.call(this, data);
      $('.chatbox-username').each(function(){
        this.previousSibling&&$.trim(this.previousSibling.nodeValue)=='<img src="http://i.imgur.com/zICIAne.png" />'&&$(this.previousSibling).replaceWith("@")
      })
    };
  };
  var s=document.createElement('script');s.text="("+chatbox_script.toString()+")();";$('object[data^="/chatbox/index.forum"],iframe[src^="/chatbox/index.forum"]').each(function(){try{$(this.contentDocument||this.contentWindow.document).find("#chatbox").closest("html").find("head").first().each(function(){this.appendChild(s.cloneNode(true))})}catch(a){}})
});
  • @Fábio Ferreira worked well, man?

  • I did. I forgot to say. I’m sorry ^^

Browser other questions tagged

You are not signed in. Login or sign up in order to post.