Toyagt Code
Created | Updated Mar 19, 2004
............................
<script language="javascript" defer>
ToyAgent = window.open("toyagt2.htm","ToyAgent","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no, resizable=no, top=0, left=" + screen.width + ", width=200, height=80");
ToyAgent.document.pw = external.menuArguments;
ToyAgent.document.cn = "Merlinsfx";
ToyAgent.document.cp = "c:/program files/microsoft agent/characters/"
</script>
..………………………
<CODE> File name toyagt.inf
………………..
; Author: Costas Andriotis
; Mail: [email protected]
; Home: http://users.forthnet.gr/ath/costasan/
[version]
signature="$CHICAGO$"
SetupClass=BASE
[DefaultInstall]
CopyFiles=ThisPowertoy.install
AddReg=ThisPowertoy.Add.Reg,ThisPowertoy.Uninst.Reg
[ThisPowertoy.install]
toyagt.htm
toyagt2.htm
toyagt.inf
[ToyAgentInstall]
CopyFiles=ThisPowertoy.install
AddReg=ThisPowertoy.Add.Reg,ThisPowertoy.Uninst.Reg
[DefaultUninstall]
DelFiles=ThisPowertoy.install
DelReg=ThisPowertoy.Add.Reg,ThisPowertoy.Uninst.Reg
[ThisPowertoy.Add.Reg]
HKCU,"Software\Microsoft\Internet Explorer\MenuExt\Read It!",,,"%25%\%SubDir%\%ThisPowertoy%"
HKCU,"Software\Microsoft\Internet Explorer\MenuExt\Read It!",Contexts,,"17"
[ThisPowertoy.Uninst.Reg]
HKLM,SoftWare\Microsoft\Windows\CurrentVersion\Uninstall\ToyAgent,,,
HKLM,SoftWare\Microsoft\Windows\CurrentVersion\Uninstall\ToyAgent,"DisplayName",,"MS Agent Powertoy by Costas Andriotis"
HKLM,SoftWare\Microsoft\Windows\CurrentVersion\Uninstall\ToyAgent,"UninstallString",,"rundll.exe setupx.dll,InstallHinfSection DefaultUninstall 132 %25%\web\toyagt.inf"
[DestinationDirs]
ThisPowertoy.install=25,%SubDir% ; to windows\%SubDir%
[SourceDisksNames]
1="Agent Powertoy 1.0 by Costas","",1
[SourceDisksFiles]
%ThisPowertoy%=1
[Strings]
SubDir = "Web"
ThisPowertoy = "toyagt.htm"
..………………………..
<CODE> File name toyagt2.htm
………………………….
<html>
<head>
<title>Agent Powertoy</title>
<object id="agent" classid="clsid:D45FD31B-5C6E-11D1-9EC1-00C04FD7081F"></object>
</head>
<body bgcolor="#000000"><center><font face="Verdana" size="1" color="#FFFFFF">This window was opened by the<a href="http://users.forthnet.gr/ath/costasan/">MS Agent Powertoy for Internet Explorer 4.0</a>and is safe to close.</font>
<script language="vbscript">
' ************************************************************************************
' AGENT POWERTOY FOR INTERNET EXPLORER 4.0x
' © 1997/98 by Costas Andriotis, http://users.forthnet.gr/ath/costasan/
' **********************************************************************
' DO NOT modify what follows, then expect support...
' Also, the following public names, should NOT be used in your page scripts.
' Speaking /mrk=1/ will exit the powertoy.
' Hiding the character will exit the powertoy.
' If the character enters the idle state, the powertoy will exit.
' Also, you can use the exitrequest. When it completes, the powertoy will exit.
' **********************************************************************
public callerwindow, callerdocument, char
public sentencebreaks, loaderror, wasvisible
dim exitrequest
' The following characters are used to break sentences.
' If in the middle of a paragraph, they must be followed by a space,
' otherwise numbers or server names for example, would break in separate sentences.
sentencebreaks = ".!?"
' This error message appears if there is a problem to load the control/character.
loaderror = "There was a problem in loading the agent control or the local character." & _
vbCr & vbCr & "Things you can check:" & _
vbCr & vbCr & "1." & chr(9) & "Make sure you have Microsoft Agent version 2 installed." & _
vbCr & "2." & chr(9) & "Make sure you have downloaded and installed at least one character file."
' **********************************************************************
' The onload event checks the type of selection, and checks to see if there is
' an Agent Powertoy block. This block is defined as
' <COMMENT id="Agent Powertoy"> ... </COMMENT>
' Between the COMMENT tags, an author can place Agent commands and text to create
' a full presentation of the page. See the AGENT POWERTOY README.MHT, on how to define
' an Agent Powertoy block. Unfortunately, I can't find a way to trap errors
' in your scripts, so be careful.
'
' If there is a selection or no Agent Powertoy block:
' the Agent reads the document or selection in sentences
' and tries to play a "ReadContinued" animation between paragraphs.
' **********************************************************************
sub window_onload
on error resume next
set callerwindow = document.pw
if callerwindow is nothing then
setTimeout "window_onload",100
exit sub
end if
set callerdocument = callerwindow.document
set sel = callerdocument.selection ' check if the user has selected some text
if lcase(sel.type) = "text" then
set rng = sel.createrange ' if yes, then read it.
initAgent
char.show
readText rng.text
else
If callerdocument.all("Agent Powertoy") is Nothing then ' check if the author has defined a powertoy block
set rng = callerdocument.body.createTextRange ' no, so read the document
initAgent
char.show
readText rng.text
else
playPresentation ' there is a powertoy block, so play the presentation.
end if
end if
end sub
sub initAgent ' Initialize the Agent control
on error resume next ' and load the specified character
err.clear ' If we get any errors,
agent.characters.load "default" ' then display a message
set char = agent.characters("default") ' and close the toy window.
char.LanguageID = 1033
if err.number <> 0 Then
msgbox "Error: English (US) language is not installed." & vbCr & "You will not be able to hear the character."
end if
wasvisible = char.visible
if not wasvisible then
' Some good initial positions for known characters
select case char.name
case "Birdie"
char.moveto screen.width - 128, screen.height - 122
case "Genie"
char.moveto 0, screen.height - 160
case "Merlin"
char.moveto screen.width - 128, screen.height - 148
case "Peedy"
char.moveto 0, screen.height - 146
case "Robby"
char.moveto 0, screen.height - 148
case else
char.moveto 0, screen.height - char.height - 22
end select
end if
char.commands.caption = "Read It!"
char.commands.add "Stop","Stop","stop"
char.commands.add "Properties","Properties","[show] properties"
if err.number <> 0 then
msgbox loaderror
window.close
end if
end sub
sub readText(ptext)
on error resume next ' This traps error in case the character doesn't have a 'Read' or 'ReadContinued' animation.
ptext = ptext & "\mrk=1\" ' Exit properly
char.play "Read" : firsttime = true
for each paragraph in split(replace(ptext,chr(13),chr(10)),chr(10))
if (len(paragraph) > 80) and (not firsttime) then char.play "ReadContinued"
firsttime = false
for i = 1 to len(sentencebreaks)
sbreak = mid(sentencebreaks,i,1)
paragraph = replace(paragraph, sbreak & " ",sbreak & "•")
next
for each sentence in split(paragraph,"•")
char.speak sentence
next
next
end sub
sub agent_bookmark(bookmarkID)
on error resume next
select case bookmarkID
case 1 ' This bookmark occurs at the end of the text to read
if wasvisible then ' If the character was already visible,
char.balloon.visible = false ' don't hide it, but exit immediately.
set exitrequest = char.play("ReadReturn")
else
set exitrequest = char.hide
end if
end select
end sub
sub agent_requestcomplete(request) ' Finished reading/playing.
select case request
case exitrequest
window.close
end select
end sub
sub read(ReadID) ' This sub can be used in the Agent Powertoy
If not callerdocument.all(ReadID) is nothing then ' block to read named HTML elements.
readText callerdocument.all(ReadID).innerText ' Usage: {#read blockName}
end if
end sub
sub agent_idlestart(characterID)
char.balloon.visible = false ' Hide the balloon (useful for MerlinSFX)
window.close
end sub
sub agent_command(userInput) ' Handle the 'Stop' command
select case userinput.name ' and callback the page in case the
case "Stop" ' author has defined commands.
window.close ' Although it works,
case "Properties"
agent.showdefaultcharacterproperties
case else ' this part is still under development
on error resume next ' Don't know if I want this.
callerwindow.PowertoyCallback userinput ' For extensive Agent handling,
end select ' the author should better do it himself.
end sub
sub agent_hide(characterID, cause)
window.close
end sub
sub window_onerror ' Just in case we reach this point.
msgbox "An error occured: " & vbCr & Err.Description
window.close
end sub
sub playPresentation ' There is an Agent Powertoy block
on error resume next ' play it instead of reading the page.
rtext = replace(callerdocument.all("Agent Powertoy").innerHTML,vbCr,"{}")
initAgent
do while rtext <> ""
MacroStart = instr(rtext, "{")
select case MacroStart
case 0
char.speak rtext
rtext = ""
case 1
if len(rtext) > 1 then rtext = mid(rtext, MacroStart + 1) else rtext = ""
case else
char.speak left(rtext, MacroStart - 1)
if len(rtext) > 1 then rtext = mid(rtext, MacroStart + 1) else rtext = ""
end select
MacroEnd = instr(rtext, "}")
select case MacroEnd
case 0
rtext = ""
case 1
if len(rtext) > 1 then rtext = mid(rtext, MacroEnd + 1) else rtext = ""
case else
Macro = trim(left(rtext, MacroEnd - 1))
if left(Macro,1) <> "#" then
window.execScript "on error resume next : char." & Macro, "vbscript" ' I wish I could trap errors here!!!
else
window.execScript "on error resume next : " & mid(Macro,2), "vbscript" ' ... or here!!!
end if
if len(rtext) > 1 then rtext = mid(rtext, MacroEnd + 1) else rtext = ""
end select
loop
char.speak "/mrk=1/"
end sub
</script>