Skript
#NoTrayIcon
[/autoit] [autoit][/autoit] [autoit]Global Const $GUI_ENABLE = 64
Global Const $GUI_DISABLE = 128
Global $oIE, $Form1, $btnStart, $btnPause, $inputWPM, $editText, $b = False, $nWPM, $aWords, $iWord = 0, $iTimer = -1
Global $sHTML = '<center style="font-family: Courier New;font-size: 24px"><span id="text">%%</span></center>'
$oIE = ObjCreate("Shell.Explorer.2")
If @error Then Exit MsgBox(16, "Error", "Sorry, but you need to have the 'Shell.Explorer.2' object installed to use this program.")
$Form1 = GUICreate("AutoIt Speed Reading Demo", 400, 320)
GUICtrlCreateObj($oIE, 20, 20, 360, 80)
GUISetFont(10, 1000, 0, "Courier New")
$btnStart = GUICtrlCreateButton("Start", 20, 120, 80, 20)
$btnPause = GUICtrlCreateButton("Pause", 110, 120, 80, 20)
GUICtrlSetState($btnPause, $GUI_DISABLE)
$inputWPM = GUICtrlCreateInput("", 200, 120, 180, 20)
GUICtrlSendMsg($inputWPM, 0x1501, 0, "Words / Minute")
$editText = GUICtrlCreateEdit("The quick brown fox jumps over the lazy dog.", 20, 150, 360, 130)
$labelInfo = GUICtrlCreateLabel("", 20, 290, 360, 20)
GUISetState(@SW_SHOW, $Form1)
$oIE.navigate("about:blank")
Sleep(10)
UpdateHTML("Hello World!")
Do
Switch GUIGetMsg()
Case -3
ExitLoop
Case $btnStart
If $b Then
_Stop()
Else
ParseText()
_Start()
$iWord = 0
GUICtrlSetData($btnStart, "Stop")
GUICtrlSetState($btnPause, $GUI_ENABLE)
$b = True
EndIf
Case $btnPause
If $b Then
AdlibUnRegister("DisplayNextWord")
GUICtrlSetData($btnPause, "Resume")
$b = False
Else
_Start()
GUICtrlSetData($btnPause, "Pause")
$b = True
EndIf
EndSwitch
Until False
AdlibUnRegister("DisplayNextWord")
$oIE = 0
Exit
Func _Start()
$nWPM = Number(GUICtrlRead($inputWPM))
If ($nWPM < 60) Then $nWPM = 250
AdlibRegister("DisplayNextWord", Floor(60000/$nWPM))
If ($iTimer < 0) Then $iTimer = TimerInit()
EndFunc
Func _Stop()
AdlibUnRegister("DisplayNextWord")
GUICtrlSetData($labelInfo, StringFormat("You just read %d word(s) in %s!", $iWord, _FormatSeconds(TimerDiff($iTimer)/1000)))
$iTimer = -1
GUICtrlSetState($btnPause, $GUI_DISABLE)
GUICtrlSetData($btnStart, "Start")
$b = False
EndFunc
Func ParseText()
Local $text = GUICtrlRead($editText), $i, $a, $b
Local $html = '\1<span style="color: #FF0000;">\2</span>\3'
$aWords = StringRegExp($text, '("?[\wÄäÖöÜüß]+[,.:;!?-]*"?)', 3)
For $i = 0 To UBound($aWords)-1
$a = StringRegExp($aWords[$i], "[A-Za-zÄäÖöÜüß]+", 3)
If (Not @error) Then
$a = $a[0]
If (StringLen($a) > 2) Then
$b = getORPIndex($a)
$aWords[$i] = StringReplace($aWords[$i], $a, StringRegExpReplace($a, '^(.{' & $b & '})(.)(.*)$', $html), 1, 1)
EndIf
EndIf
Next
EndFunc
Func getORPIndex($s)
Local $l = StringLen($s)
If ($l = 1) Then Return 0
If ($l = 2) Then Return 1
If ($l = 3) Then Return 1
Return Floor($l / 2) - 1
EndFunc
Func UpdateHTML($sContent)
$oIE.document.body.innerHTML = StringReplace($sHTML, "%%", $sContent)
EndFunc
Func DisplayNextWord()
UpdateHTML($aWords[$iWord])
$iWord += 1
If ($iWord >= UBound($aWords)) Then _Stop()
EndFunc
Func _FormatSeconds($n)
If ($n > 86400) Then
Return Round($n/86400, 2) & " day(s)"
EndIf
If ($n > 3600) Then
Return Round($n/3600, 2) & " hour(s)"
EndIf
If ($n > 60) Then
Return Round($n/60, 2) & " minute(s)"
EndIf
Return Round($n, 2) & " second(s)"
EndFunc