Boas-vindas ao Power Pixel

Junte-se a comunidade! Crie o seu próprio conteúdo, e faça amizades.EntrarCriar uma conta

' Akιo ' Akιo  • Seg 10 Fev 2014 - 21:29

Avatar no Chatbox - simplificado Empty Avatar no Chatbox - simplificado Seg 10 Fev 2014 - 21:29

Qual é minha questão:
Olá!
Gostaria de pedir o código simplificado desse JavaScript, para que tenha apenas a função de adicionar o avatar nas mensagens do Chatbox.

Código:
/*
* Avatar in /chatbox - Fast and Rá!!!
* Version: 1.11.2013 - Kheops
* Made and Optimizations by JScript - 2013/11/01
* View more in: http://ajuda.forumeiros.com
* Copyright (c) 2013 JScript <jscriptbrasil at live dot com>
* This work is free. You can redistribute it and/or modify it
* under the terms of the WTFPL, Version 2
*/
$(document).ready(function(){
  var sHtml = '<iframe onload="setOptions()" src="/chatbox/index.forum" id="frame_chatbox" scrolling="no" width="100%" height="100%" type="text/html" style="border: 0px;" />';
  $('#frame_chatbox').replaceWith(sHtml);
});

var old = '',
  oChat= null,
  connected = 1,
  chatbox_updated = 0,
  chatbox_last_update = 1,
  template_color = '#333333',
  chatbox_messages = 'null',
  chatbox_messages_old = '',
  number_of_refresh = 0,
  refresh_interval = 0,
  ncheckData = 0;

function setOptions() {
  oChat = $('#frame_chatbox').contents();
  oChat.find('#chatbox_footer form').attr('onsubmit', "parent.submitmsg2('');parent.refresh_chatbox2('');return false;");
  oChat.find('#chatbox_main_options li:eq(0) a').attr('onclick', "parent.ajax_refresh_chatbox2('', 1);");
  oChat.find('#chatbox_main_options li:eq(3)').attr('onclick', "parent.refresh_chatbox2('');");
  oChat.find('#chatbox_main_options li:eq(4) a').attr('onclick', "parent.CB_disconnect2();");

  connected = document.getElementById('frame_chatbox').contentWindow['connected'];
  chatbox_updated = document.getElementById('frame_chatbox').contentWindow['chatbox_updated'];
  chatbox_last_update = document.getElementById('frame_chatbox').contentWindow['chatbox_last_update'];
  number_of_refresh = document.getElementById('frame_chatbox').contentWindow['number_of_refresh'];
  //refresh_interval = document.getElementById('frame_chatbox').contentWindow['refresh_interval'];

  ncheckData = setInterval("checkData()", 0);
}
function checkData() {
  if (oChat.find('#chatbox span.user').length) {
      clearInterval(ncheckData);
      try {
          connected = document.getElementById('frame_chatbox').contentWindow['connected'];
          document.getElementById('frame_chatbox').contentWindow.clearInterval(document.getElementById('frame_chatbox').contentWindow['refresh_interval']);
          chatAvatar();
          refresh_interval = setInterval("refresh_chatbox2('')", 5000);
          oChat[0].getElementById('chatbox').scrollTop = 999999;
      } catch (err) {}
  }
}
function chatAvatar() {
  var target = oChat.find('#chatbox span.user a'), chk = {};
  target.each(function(index) {
      var oThis = $(this);
      var USER_URL = oThis.attr('href');

      if (!chk[USER_URL]) {
          chk[USER_URL] = true;       
          //if ( !oThis.parent().find('.KheopsUserPhoto.KheopsUserPhoto_icon').length ) {
          /* Gets the avatar saved in local storage */
          var oStor = sessionStorage.getItem('chat' + USER_URL);
     
          if (oStor !== null) {
              oChat.find("#chatbox span.user a[href='" + USER_URL + "']").parent().prepend('<img alt="" class="KheopsUserPhoto KheopsUserPhoto_icon" src="' + oStor + '">');
              [Tens de ter uma conta e sessão iniciada para poderes visualizar este link] alt="" class="KheopsUserPhoto KheopsUserPhoto_icon" src="' + oStor + '">');
          } else {
              [Tens de ter uma conta e sessão iniciada para poderes visualizar este link]
              $.get(USER_URL, function (data) {
                  var AVATAR = $('#profile-advanced-right img', data).attr('src');
                  if (!AVATAR) AVATAR = $('#profile_tabs p img', data).attr('src');

                  oChat.find("#chatbox span.user a[href='" + USER_URL + "']").parent().prepend('<img alt="" class="KheopsUserPhoto KheopsUserPhoto_icon" src="' + AVATAR + '">');
                  /* Saves the member avatar in local storage */
                  sessionStorage.setItem('chat' + USER_URL, AVATAR);
              });
              [Tens de ter uma conta e sessão iniciada para poderes visualizar este link]
          }
          //}
      }
  });
  if (oChat.find("#punbb_jscript").length) {
      $('#punbb_jscript').attr('href', '').text('').show();
  } else {
      oChat.find('#chatbox_main_options').prepend('<li><a id="punbb_jscript" title="JScript at live dot com" href="" target="_top" style="float: right; margin-left: 0px;"></a></li>');
  }
}
function CB_disconnect2() {
if (connected) {
      document.getElementById('frame_chatbox').contentWindow.ajax_connect('', 'disconnect');
clearInterval(refresh_interval);
      clearInterval(ncheckData);
      connected = 0;
} else {
      document.getElementById('frame_chatbox').contentWindow.ajax_connect('', 'connect');
      clearInterval(refresh_interval);
      document.getElementById('frame_chatbox').contentWindow.clearInterval(document.getElementById('frame_chatbox').contentWindow['refresh_interval']);
      connected = 1;
      number_of_refresh = 0;
      if (!ncheckData) ncheckData = setInterval("checkData()", 10);
/*try {
          chatAvatar();
refresh_interval = setInterval("refresh_chatbox2('')", 5000);
} catch (err) {}*/
}
}
function submitmsg2(params) {
oChat[0].post.sent.value = oChat[0].post.message.value;
oChat[0].post.message.value = '';
oChat[0].post.message.focus();
ajax_submit_chatbox2(params);
return false
}
function refresh_chatbox2(params) {
if (params == '' || params == undefined) {
params = '?achives=0'
}
if (oChat[0].getElementById('refresh_auto').checked == true) {
ajax_refresh_chatbox2(params)
}
  $.post('/chatbox/chatbox_actions.forum', 'mode=send&sent=');
}
function ajax_refresh_chatbox2(params, force) {
if (params == '' || params == undefined) {
params = '?achives=0'
}
if (window.XMLHttpRequest) {
var http_request = new XMLHttpRequest()
} else if (window.ActiveXObject) {
var http_request = new ActiveXObject("Microsoft.XMLHTTP")
}
http_request.onreadystatechange = function () {
if (http_request.readyState == 4 && http_request.status == 200) {
var parsed_text = http_request.responseText;
eval(parsed_text);
if (chatbox_last_update > chatbox_updated || force) {
if (oChat[0].getElementById('chatbox').innerHTML != null) {
if (chatbox_messages_old != chatbox_messages) {
oChat[0].getElementById('chatbox').innerHTML = chatbox_messages;
chatbox_messages_old = chatbox_messages;
                      chatAvatar();
oChat[0].getElementById('chatbox').scrollTop = oChat[0].getElementById('chatbox').scrollHeight + oChat[0].getElementById('chatbox').offsetHeight;
oChat[0].getElementById('chatbox').scrollTop = 999999;
}
}
if (oChat[0].getElementById('chatbox_members').innerHTML != null) oChat[0].getElementById('chatbox_members').innerHTML = chatbox_memberlist;
chatbox_updated = chatbox_last_update
}
}
};
http_request.open('GET', '/chatbox/chatbox_actions.forum' + params + '&mode=refresh', true);
http_request.send(null)
}
function ajax_submit_chatbox2(params) {
number_of_refresh = 0;
var msg_sent = oChat[0].post.sent.value;
if (params == '' || params == undefined) {
params = '?achives=0'
}
var data = '&mode=send';
data += '&sent=' + encodeURIComponent(msg_sent);
data += '&sbold=' + oChat[0].post.sbold.value;
data += '&sitalic=' + oChat[0].post.sitalic.value;
data += '&sunderline=' + oChat[0].post.sunderline.value;
data += '&sstrike=' + oChat[0].post.sstrike.value;
data += '&scolor=' + oChat[0].post.scolor.value;
if ((msg_sent.indexOf('/away') == 0) || (msg_sent.indexOf('/abs') == 0)) {
oChat[0].getElementById('refresh_auto').checked = false
}
if (oChat[0].post.sent.value == '/banlist') {
window.open('/chatbox/chatbox_banlist.forum' + params, 'banlist', 'toolbar=no,menubar=no,personalbar=no,width=450,height=300,scrollbars=yes,resizable=yes');
return false
}
if (window.XMLHttpRequest) {
var http_request = new XMLHttpRequest()
} else if (window.ActiveXObject) {
var http_request = new ActiveXObject("Microsoft.XMLHTTP")
}
http_request.onreadystatechange = function () {
if (http_request.readyState == 4 && http_request.status == 200) {
var parsed_text = http_request.responseText;
eval(parsed_text);
if (chatbox_last_update > chatbox_updated) {
oChat[0].getElementById('chatbox').innerHTML = chatbox_messages;
oChat[0].getElementById('chatbox_members').innerHTML = chatbox_memberlist;
chatbox_updated = chatbox_last_update;
              chatAvatar();
oChat[0].getElementById('chatbox').scrollTop = 999999;
}
}
};
http_request.open('POST', '/chatbox/chatbox_actions.forum' + params, true);
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
http_request.send((data))
}

Gostaria que os adicionais como a /banlist, o bloqueio da /exit, e todos outros códigos que não seja o Avatar, sejam excluídos.
Obrigado Wink

Endereço do meu fórum:
[Tens de ter uma conta e sessão iniciada para poderes visualizar este link]

Versão:
Phpbb3

Target Target  • Seg 10 Fev 2014 - 21:38

Avatar no Chatbox - simplificado Empty Re: Avatar no Chatbox - simplificado Seg 10 Fev 2014 - 21:38

Olá,
Amigo este já é um código simplificado, é um jQuery Wink
Não dá para simplificar mais ele. Ele já está na sua forma mais simplificada possível!

Até +! Smile

' Akιo ' Akιo  • Seg 10 Fev 2014 - 22:32

Avatar no Chatbox - simplificado Empty Re: Avatar no Chatbox - simplificado Seg 10 Fev 2014 - 22:32

Mas possui vários efeitos adicionais que não desejo.

Não gostaria que 'simplificasse', mas sim, remover esses efeitos desnecessários.

Gostaria apenas do código para adicionar o avatar no Chatbox nativo. Nada mais.

Target Target  • Seg 10 Fev 2014 - 22:43

Avatar no Chatbox - simplificado Empty Re: Avatar no Chatbox - simplificado Seg 10 Fev 2014 - 22:43

Olá amigo,
Quais seriam tais efeitos?
Está ciente que alguns efeitos podem ser causado pelo teu CSS!?

Até +! Wink

' Akιo ' Akιo  • Seg 10 Fev 2014 - 22:57

Avatar no Chatbox - simplificado Empty Re: Avatar no Chatbox - simplificado Seg 10 Fev 2014 - 22:57

Eu sei sim;

Tais efeitos seriam, por exemplo,  a criação de uma /banlist, a proibição do /exit, etc.

Target Target  • Seg 10 Fev 2014 - 23:06

Avatar no Chatbox - simplificado Empty Re: Avatar no Chatbox - simplificado Seg 10 Fev 2014 - 23:06

Tudo bem, estarei analisando o código e editarei ao seu gosto.
Diga-me quais os efeitos que devem sair?!

' Akιo ' Akιo  • Seg 10 Fev 2014 - 23:13

Avatar no Chatbox - simplificado Empty Re: Avatar no Chatbox - simplificado Seg 10 Fev 2014 - 23:13

Se encontrar algum além desses que citei, pode tirar.
Realmente, quero apenas o código do avatar.

Latysh Latysh  • Seg 10 Fev 2014 - 23:23

Avatar no Chatbox - simplificado Empty Re: Avatar no Chatbox - simplificado Seg 10 Fev 2014 - 23:23

Tente este código (feito por [F]lames):
Código:
$(document).ready(function(){
   $('#frame_chatbox').replaceWith('<iframe src="/chatbox" id="frame_chatbox" scrolling="yes" width="100%" height="100%" type="text/html" style="border: 0px;" />');
});
$(document).ready(function(){
   $('#frame_chatbox').mouseenter(function() {
      $('#frame_chatbox').contents().find('#chatbox p .user-msg').each(function() {
         $('#frame_chatbox').attr('id','framejqs');
         $(this).prepend('<div id="chat-avat" style="position: relative; left: -38px; top: 5px; margin-bottom: -26px;"><img src="http://i.imgur.com/BMdww.gif" style="width: 35px;"></div>').css('background','none');
         var profileUserURL=$(this).find('.user').find('a[href^="/u"]').attr('href');
         $(this).find('#chat-avat').load(profileUserURL+' #profile-advanced-right .module:first img:first');
      });
   });
});

' Akιo ' Akιo  • Seg 10 Fev 2014 - 23:26

Avatar no Chatbox - simplificado Empty Re: Avatar no Chatbox - simplificado Seg 10 Fev 2014 - 23:26

Não é o que eu pedi; quero o avatar do autor da mensagem, como no código que mandei.

' Akιo ' Akιo  • Qua 12 Fev 2014 - 14:08

Target Target  • Qua 12 Fev 2014 - 14:24

Avatar no Chatbox - simplificado Empty Re: Avatar no Chatbox - simplificado Qua 12 Fev 2014 - 14:24

Olá,
Tente este código:

Código:

/*
* Avatar in /chatbox - Fast and Rá!!!
* Version: 1.11.2013 - Kheops
* Made and Optimizations by JScript - 2013/11/01
* View more in: http://ajuda.forumeiros.com
* Copyright (c) 2013 JScript <jscriptbrasil at live dot com>
* This work is free. You can redistribute it and/or modify it
* under the terms of the WTFPL, Version 2
*/
$(document).ready(function(){
  var sHtml = '<iframe onload="setOptions()" src="/chatbox/index.forum" id="frame_chatbox" scrolling="no" width="100%" height="100%" type="text/html" style="border: 0px;" />';
  $('#frame_chatbox').replaceWith(sHtml);
});

var old = '',
  oChat= null,
  connected = 1,
  chatbox_updated = 0,
  chatbox_last_update = 1,
  template_color = '#333333',
  chatbox_messages = 'null',
  chatbox_messages_old = '',
  number_of_refresh = 0,
  refresh_interval = 0,
  ncheckData = 0;

function setOptions() {
  oChat = $('#frame_chatbox').contents();
  oChat.find('#chatbox_footer form').attr('onsubmit', "parent.submitmsg2('');parent.refresh_chatbox2('');return false;");
  oChat.find('#chatbox_main_options li:eq(0) a').attr('onclick', "parent.ajax_refresh_chatbox2('', 1);");
  oChat.find('#chatbox_main_options li:eq(3)').attr('onclick', "parent.refresh_chatbox2('');");
  oChat.find('#chatbox_main_options li:eq(4) a').attr('onclick', "parent.CB_disconnect2();");

  connected = document.getElementById('frame_chatbox').contentWindow['connected'];
  chatbox_updated = document.getElementById('frame_chatbox').contentWindow['chatbox_updated'];
  chatbox_last_update = document.getElementById('frame_chatbox').contentWindow['chatbox_last_update'];
  number_of_refresh = document.getElementById('frame_chatbox').contentWindow['number_of_refresh'];
  //refresh_interval = document.getElementById('frame_chatbox').contentWindow['refresh_interval'];

  ncheckData = setInterval("checkData()", 0);
}
function checkData() {
  if (oChat.find('#chatbox span.user').length) {
      clearInterval(ncheckData);
      try {
          connected = document.getElementById('frame_chatbox').contentWindow['connected'];
          document.getElementById('frame_chatbox').contentWindow.clearInterval(document.getElementById('frame_chatbox').contentWindow['refresh_interval']);
          chatAvatar();
          refresh_interval = setInterval("refresh_chatbox2('')", 5000);
          oChat[0].getElementById('chatbox').scrollTop = 999999;
      } catch (err) {}
  }
}
function chatAvatar() {
  var target = oChat.find('#chatbox span.user a'), chk = {};
  target.each(function(index) {
      var oThis = $(this);
      var USER_URL = oThis.attr('href');

      if (!chk[USER_URL]) {
          chk[USER_URL] = true;       
          //if ( !oThis.parent().find('.KheopsUserPhoto.KheopsUserPhoto_icon').length ) {
          /* Gets the avatar saved in local storage */
          var oStor = sessionStorage.getItem('chat' + USER_URL);
     
          if (oStor !== null) {
              oChat.find("#chatbox span.user a[href='" + USER_URL + "']").parent().prepend('<img alt="" class="KheopsUserPhoto KheopsUserPhoto_icon" src="' + oStor + '">');
              http://oThis.parent().prepend('<img alt="" class="KheopsUserPhoto KheopsUserPhoto_icon" src="' + oStor + '">');
          } else {
              http://jQuery.ajaxSetup({async:false});
              $.get(USER_URL, function (data) {
                  var AVATAR = $('#profile-advanced-right img', data).attr('src');
                  if (!AVATAR) AVATAR = $('#profile_tabs p img', data).attr('src');

                  oChat.find("#chatbox span.user a[href='" + USER_URL + "']").parent().prepend('<img alt="" class="KheopsUserPhoto KheopsUserPhoto_icon" src="' + AVATAR + '">');
                  /* Saves the member avatar in local storage */
                  sessionStorage.setItem('chat' + USER_URL, AVATAR);
              });
              http://jQuery.ajaxSetup({async:true});
          }
          //}
      }
  });

function CB_disconnect2() {
if (connected) {
      document.getElementById('frame_chatbox').contentWindow.ajax_connect('', 'disconnect');
clearInterval(refresh_interval);
      clearInterval(ncheckData);
      connected = 0;
} else {
      document.getElementById('frame_chatbox').contentWindow.ajax_connect('', 'connect');
      clearInterval(refresh_interval);
      document.getElementById('frame_chatbox').contentWindow.clearInterval(document.getElementById('frame_chatbox').contentWindow['refresh_interval']);
      connected = 1;
      number_of_refresh = 0;
      if (!ncheckData) ncheckData = setInterval("checkData()", 10);
/*try {
          chatAvatar();
refresh_interval = setInterval("refresh_chatbox2('')", 5000);
} catch (err) {}*/
}
}
if (chatbox_messages_old != chatbox_messages) {
oChat[0].getElementById('chatbox').innerHTML = chatbox_messages;
chatbox_messages_old = chatbox_messages;
                      chatAvatar();
oChat[0].getElementById('chatbox').scrollTop = oChat[0].getElementById('chatbox').scrollHeight + oChat[0].getElementById('chatbox').offsetHeight;
oChat[0].getElementById('chatbox').scrollTop = 999999;
}
}
if (oChat[0].getElementById('chatbox_members').innerHTML != null) oChat[0].getElementById('chatbox_members').innerHTML = chatbox_memberlist;
chatbox_updated = chatbox_last_update
}
}
};
}
function ajax_submit_chatbox2(params) {
number_of_refresh = 0;
var msg_sent = oChat[0].post.sent.value;
if (window.XMLHttpRequest) {
var http_request = new XMLHttpRequest()
} else if (window.ActiveXObject) {
var http_request = new ActiveXObject("Microsoft.XMLHTTP")
}
http_request.onreadystatechange = function () {
if (http_request.readyState == 4 && http_request.status == 200) {
var parsed_text = http_request.responseText;
eval(parsed_text);
if (chatbox_last_update > chatbox_updated) {
oChat[0].getElementById('chatbox').innerHTML = chatbox_messages;
oChat[0].getElementById('chatbox_members').innerHTML = chatbox_memberlist;
chatbox_updated = chatbox_last_update;
              chatAvatar();
oChat[0].getElementById('chatbox').scrollTop = 999999;
}
}
};

Até +! Wink

Conteúdo patrocinado  • 

Avatar no Chatbox - simplificado Empty Re: Avatar no Chatbox - simplificado

Permissões neste sub-fórum
Não podes responder a tópicos