http://www.perlmonks.org?node_id=309074
Category: CB Clients
Author/Contact Info jZed -- Jeff Zucker <jeff@vpservices.com>
Description:

One of the best features of Perl Monks is that it is easy to link to almost anything. The ability to insert links into Chatterbox conversation gives us the ability to turn entire webpages into parts of speech. But the standard setup makes it so that we can't see the conversation and the thing the conversation is refering to on the same page (well, yes the CB is there, but if you scroll to see the CB, you lose the page and vice-versa, and the CB isn't dynamically refreshed). With a dynamically refreshed, non-scrolling CB, we need to switch back and forth between windows or tabs to see pad://fooBar and the CB discussion of it.

The quick and dirty hack below puts something similar to the FullPage Chat into a frame on the same page as a page-viewing frame and makes the links in the CB go to the page-viewing frame so that both the chat and the page are visible in a single window/tab. I accomplish this with CGI and LWP but it could be accomplished with no programming if the base target for the showchatmessages node was either user definable or was named something other than _new. For example, if the base target was named pm_page_display, then my framed CB can be created with just a local frameset and no need for CGI or LWP.

This could probably also be accomplished with the excellent framechat, but I'm looking for something simpler and this is more of a proof of concept than a full script, the code is lame - I don't parse the HTML, much less XML.

One use of this is generalizable for other Everything installations - you can give a guided tour of a website. You chat with your client in the CB box, presenting links to pages on the site, the client views the link in one frame and chats with you about it in another. Similarly, if a teacher is doing a class, they can put up a diagram or page for discussion and then talk with students about it in the CB without dividing the attention or requiring multiple, possibly confusing windows. It would even be simple for the teacher to create a self-refreshing page, have all the students go there and then as the teacher changed the page, the page would change for all students.

Installation : requires a perl, LWP::Simple, a local webserver. Just drop the code in a CGI directory; chmod it and change the shebang line if needed.

#!perl -Tw
$|=1;
use strict;
use LWP::Simple;
use CGI();
use CGI::Carp qw(fatalsToBrowser);
my $q   = new CGI;
my $cgi = $q->url;
my $pm  = 'http://www.perlmonks.org';
my $op  = $q->param('op') || 'frameset';
my %v;
($v{frameset},$v{talk_button}) = split "\n\n", join '', <DATA>;
my $source = $v{$op};
if ($op eq 'chat' ) {
    my $btag =  qq[ <body text    =" #007F00"
                          bgcolor =" #000000"
                          link    =" #00C600"
                          vlink   =" #00A000"
                    >
                 ];
    $source = &get("$pm/index.pl?displaytype=raw&node=showchatmessages
+") || '';
    $source =~ s/target="_new"/target="pm_page_view"/;
    $source =~ s~\s*</head>~<base href="$pm">\n</head>\n$btag~;
}
$source =~ s/\$pm/$pm/g;
$source =~ s/\$cgi/$cgi/g;
print $q->header(), $source;

__DATA__
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
  <title>Zedulator</title>
  <base href="$pm">
</head>
<frameset rows="50%,50%">
  <frame name="pm_page_view" src="/index.pl?node=Newest%20Nodes">
  <frameset cols="80%,20%">
    <frameset rows="0,28,*" border="0">
      <frame name="hiddenFrame" src="" />
      <frame src="$cgi?op=talk_button"
             marginwidth="2" marginheight="2" scrolling="no"/>
      <frame src="$cgi?op=chat" />
    </frameset>
    <frameset rows="60,*">
      <frame src="/index.pl?displaytype=raw&type=superdoc&node=private
+messages" />
            <frame src="/index.pl?displaytype=raw&node=showotherusers"
+ />
        </frameset>
    </frameset>
    <noframes>
      <p>No Frames?  <a href="/index.pl?displaytype=raw&node=showchatm
+essages">
      Chat Here</a></p>
    </noframes>
</frameset>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<head>
<base href="$pm">
<base target="hiddenFrame">
<script language="javascript">
function do_submit(){
    document.f1.submit();
    document.f1.message.value='';
}
</script>
</head>
<body bgcolor="black">
<form id="f1" name="f1" method="post" action="/index.pl" enctype="appl
+ication/x-www-form-urlencoded">
<input type="hidden" name="displaytype" value="raw"><input type="hidde
+n" name="node_id" value="3193"><input type="hidden" name="op" value="
+message">
<input type="text" name="message"  size=40 maxlength=240 onMouseDown="
+javascript:document.f1.message.value=''" /> <input type="button" valu
+e="talk" onClick="do_submit()"></form>