The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

useing js in chat

View previous topic View next topic Go down

Solved useing js in chat

Post by _Twisted_Mods_ on November 5th 2014, 11:36 pm

ok what im trying to do edit my name in js in the chat box but it only works for my name out of the chat box

here is a working example

Code:
$(function() {
   var x;
   setInterval(function() {
         if(x == 0) {
            $('a[href*="/u71"]').find('strong').css('color', 'black');
            x = 1;
         } else  {
            if(x = 1) {
               $('a[href*="/u71"]').find('strong').css('color', 'white');
               x = 0;
            }
         }
   }, 500);
});

_Twisted_Mods_
Helper
Helper

Male Posts : 2032
Reputation : 302
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: useing js in chat

Post by Ange Tuteur on November 6th 2014, 5:21 am

Hello _twisted_mods_,

As the chatbox is on a different page and doesn't refer to the scripts installed on your forum, you'll have to access its frame. I have an example that you can use with the default chatbox :

Administration Panel > Modules > JavaScript codes management > Create a new script

Title : Your choice
Placement : In the homepage
Code:
$(function() {
 var fa_chat = document.getElementById('frame_chatbox'), frame; // get the chat frame, and define frame
 
 // wait until the frame is fully loaded before executing your code
 fa_chat.onload = function() {
 
  // determine how to access the frame ( depends what the browser supports )
  if (fa_chat.contentDocument) frame = fa_chat.contentDocument;
  else if (fa_chat.contentWindow) frame = fa_chat.contentWindow.document;
 
  // use an interval to apply the changes, as the content is refreshed on new messages
  window.setInterval(function() {
 
  // example : change the content of a link
  var a = frame.getElementsByTagName('A');
  for (i=0; i<a.length; i++) {
 
  // use a regular expression to check if \u1 is true for the href attribute
  // and make some changes to its style if it's true
  if (/\/u1/.test(a[i].href)) a[i].style.textShadow = '0 0 6px #85D';
  }
  },1);
 }
});

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: useing js in chat

Post by _Twisted_Mods_ on November 7th 2014, 3:43 am

how would i do this with the code that i gave u as an example i have tried last few das on my own but couldn't figure it out

_Twisted_Mods_
Helper
Helper

Male Posts : 2032
Reputation : 302
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: useing js in chat

Post by Ange Tuteur on November 7th 2014, 5:41 am

Here you are Smile

Code:
$(function() {
 var fa_chat = document.getElementById('frame_chatbox'), frame;
 
 fa_chat.onload = function() {
  if (fa_chat.contentDocument) frame = fa_chat.contentDocument;
  else if (fa_chat.contentWindow) frame = fa_chat.contentWindow.document;
 
  // kill the interval if archives are enabled
  var a = frame.getElementsByTagName('A');
  for (i=0; i<a.length; i++) if (/archives/.test(a[i].href)) a[i].onclick = function() { window.clearInterval(_chat_refresh) };

  // execute flashName() inside the interval below
  _chat_refresh = window.setInterval(function() {
  flashName(1, 'red', 'black');
  flashName(2, 'blue', 'green');
  },500);
 
  // argument explanation
  // uid : the ID of the user
  // c1 : the first color value
  // c2 : the second color value
  function flashName(uid, c1, c2) {
  var a = frame.getElementsByTagName('A'), reg = new RegExp('/u'+uid);
  for (i=0; i<a.length; i++) {
  if (reg.test(a[i].href) && a[i].getElementsByTagName('SPAN').length) {
  var b = a[i].getElementsByTagName('SPAN');
  for (c=0; c<b.length; c++) switchColor(b[c]);
  }
  else if (reg.test(a[i].href)) switchColor(a[i]);
  }
  function switchColor(o) { if (o.style.color != c1) o.style.color = c1; else o.style.color = c2; }
  }
 }
});

I added the code for switching the color inside a function, so you can call it by writing : flashName();

There are three arguments that you have to pass along. They're explained in comments above the function, and I left examples in the interval for you. ^^

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: useing js in chat

Post by _Twisted_Mods_ on November 7th 2014, 6:43 am

awsome ty

now to figure it out for awc and im n there but i dont think this will work in that chat think i have to use some of there code idk

_Twisted_Mods_
Helper
Helper

Male Posts : 2032
Reputation : 302
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: useing js in chat

Post by Ange Tuteur on November 7th 2014, 6:55 am

You're welcome.

If the iframe uses an ID, change the id here :
Code:
document.getElementById('frame_chatbox')

otherwise you can run a loop to find its source attribute and set a variable :
Code:
var f = document.getElementsByTagName('IFRAME'), fa_chat, frame;
for (i=0; i<f.length; i++) if (/chatbox/.test(f[i].src)) fa_chat = f[i];

You'd just replace the variables at the start of the script with what I have above. That's if it uses an iframe.

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: useing js in chat

Post by _Twisted_Mods_ on November 7th 2014, 10:18 am

it has a iframe but no id or class id whole thing is weird u have to use totally dif javascript for it


this is iframe
Code:
<iframe frameborder="0" onload="avacweb_chat.init()" seamless="seamless" src="/chatbox?archives=0" name="avacweb_chat_frame" style="visibility: visible;">

this what javascript looks like just to change the @ symol before the users name



Code:
avacweb_chat_config.message_hook.push(function(row,username,user_id,user){user.innerHTML=user.innerHTML.replace(/@(?=\W)/,'Mod:');//perform@replacement});avacweb_chat_config.user_hook.push(function(row,username,user_id){varu=row.getElementsByTagName('a')[0];if(u)u.innerHTML=u.innerHTML.replace(/@(?=\W)/,'Mod:');//perform@replacement});

_Twisted_Mods_
Helper
Helper

Male Posts : 2032
Reputation : 302
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: useing js in chat

Post by _Twisted_Mods_ on November 18th 2014, 9:18 am

ok ange 1 last question and u can close this .. how would i change the login/logout msg

"Admin joined the chat on Tue 18 Nov 2014 - 4:51"

to say what ever i want it to say

example when someone enters the room it will say


"Admin has chosen to partake in our conversation"

instead of

"Admin joined the chat on Tue 18 Nov 2014 - 4:51"

_Twisted_Mods_
Helper
Helper

Male Posts : 2032
Reputation : 302
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: useing js in chat

Post by Ange Tuteur on November 18th 2014, 12:15 pm

Something like this should work :

Create a new script, and make sure the placement is in the homepage.
Code:
$(function() {
 var connect_text = 'has joined the chat',
  disconnect_text = 'has left the chat',
  fa_chat = document.getElementById('frame_chatbox'), frame;
 if (!fa_chat) return;
 
 fa_chat.onload = function() {
  if (fa_chat.contentDocument) frame = fa_chat.contentDocument;
  else if (fa_chat.contentWindow) frame = fa_chat.contentWindow.document;
 
  // kill the interval if archives are enabled
  var a = frame.getElementsByTagName('A'),i;
  for (i=0; i<a.length; i++) if (/archives/.test(a[i].href)) a[i].onclick = function() { window.clearInterval(_chat_refresh) };

  // execute code in an interval
  _chat_refresh = window.setInterval(function() {
  var logs = frame.getElementsByTagName('SPAN'),i;
  for (i=0; i<logs.length; i++) {
  if (!/customLog/.test(logs[i].className)) {
  if (/green/.test(logs[i].style.color)) {
  logs[i].className += ' customLog';
  logs[i].firstChild.innerHTML = logs[i].firstChild.innerHTML.replace(/(.*?) joined.*?\d+:\d+/,'$1 ') + connect_text;
  }
  if (/red/.test(logs[i].style.color)) {
  logs[i].className += ' customLog';
  logs[i].firstChild.innerHTML = logs[i].firstChild.innerHTML.replace(/(.*?) has.*?\d+:\d+/,'$1 ') + disconnect_text;
  }
  }
  }
  },1);
 }
});
Although the regexes might not work for other languages.

You can edit the log text by editing these variables :
Code:
var connect_text = 'has joined the chat',
  disconnect_text = 'has left the chat',

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: useing js in chat

Post by _Twisted_Mods_ on November 19th 2014, 12:21 am

works awsome but still shows am|pm before the msg


Username pmhas joined the chat

_Twisted_Mods_
Helper
Helper

Male Posts : 2032
Reputation : 302
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: useing js in chat

Post by Ange Tuteur on November 19th 2014, 12:30 am

Is the AM/PM in the date time ?

You might need to add it somewhere in the regular expressions :

login regex :
Code:
/(.*?) joined.*?\d+:\d+/

logout regex :
Code:
/(.*?) has.*?\d+:\d+/

This should work to identify am/pm : (am|pm)

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: useing js in chat

Post by _Twisted_Mods_ on November 19th 2014, 2:03 am

got it

/(.*?) has.*?\d+:\d+ (am|pm)/

i was doing it

/(.*?) has.*?\d+:\d+ am|pm/


ty ange solved

_Twisted_Mods_
Helper
Helper

Male Posts : 2032
Reputation : 302
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: useing js in chat

Post by Ange Tuteur on November 19th 2014, 2:19 am

You're welcome ^^

If you have any problems you can also do a case insensitive search by adding 'i' to the regex :
/(.*?) has.*?\d+:\d+ (am|pm)/i

Topic archived

Have a great day

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum