Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dim _time as integer
- dim _duration as integer
- dim _runTimer as Boolean = false
- dim _fps as integer = 1 / System.CurrentRefreshRate
- dim _autoLoad as boolean = False
- dim _response as string = ""
- dim _browser as container = this.FirstChildContainer
- dim _js as string = GetParameterString("js")
- dim _jsFunction as string = "VizCallbackA"
- sub OnInitParameters()
- System.Map.UnregisterChangedCallback(_browser.VizId & " BROWSER STATUS")
- System.Map.RegisterChangedCallback(_browser.VizId & " BROWSER STATUS")
- RegisterParameterString("filename", "File Name", "", 80, 1000, "")
- RegisterParameterBool("editor", "Javascript Editor", False)
- RegisterParameterText("txt_js", "", 760, 250)
- RegisterPushButton( "btn_save", " SAVE ", 2 )
- RegisterParameterBool("autoLoad", "Load Automatically", False)
- RegisterParameterInt("autoLoadInterval", "Automatic load period", 10, 1, 6000)
- RegisterPushButton( "btn_load", " LOAD ", 1 )
- end sub
- sub OnInit()
- SetData("")
- System.Map[_browser.VizId & " BROWSER STATUS"] = ""
- _duration = GetParameterInt("autoLoadInterval") * _fps
- if GetParameterBool("autoLoad") then
- startTimer(_duration)
- end if
- end sub
- sub SetData(data as string)
- this.FindSubContainer("Result").geometry.text = ""
- this.FindSubContainer("Result").geometry.text = data
- end sub
- sub OnParameterChanged(parameterName As String)
- if parameterName = "txt_js" then
- _js = GetParameterString("txt_js")
- _js.Trim
- _jsFunction.Trim
- end if
- if parameterName = "filename" then
- SetData("")
- _browser.GetFunctionPluginInstance("BrowserCEF").SetParameterString("url", GetParameterString("filename"))
- end if
- if parameterName = "autoLoad" then
- _autoLoad = GetParameterBool("autoLoad")
- end if
- if parameterName = "autoLoadInterval" then
- _duration = GetParameterInt("autoLoadInterval") * _fps
- end if
- end sub
- sub OnSharedMemoryVariableChanged(map As SharedMemory, mapKey As String)
- SetData("")
- if mapKey = _browser.VizId & " BROWSER STATUS" then
- if CStr(System.Map[_browser.VizId & " BROWSER STATUS"]).Find("1 loadstate stopped") <> -1 then
- _browser.GetFunctionPluginInstance("BrowserCEF").PushButton("execjavascript")
- end if
- if cstr(System.Map[_browser.VizId & " BROWSER STATUS"]).Find("javascript " & _jsFunction) <> -1 then
- _response = CStr(System.Map[_browser.VizId & " BROWSER STATUS"])
- _response.Substitute("0 javascript " & _jsFunction, "", true)
- _response.Substitute("1 javascript " & _jsFunction, "", true)
- _response.Trim
- SetData(_response)
- end if
- end if
- end sub
- sub OnGuiStatus()
- select case GetParameterBool("editor")
- case True
- SendGuiParameterShow("txt_js", SHOW)
- SendGuiParameterShow("btn_save", SHOW)
- SendGuiParameterShow("autoLoadInterval", HIDE)
- SendGuiParameterShow("autoLoad", HIDE)
- SendGuiParameterShow("btn_load", HIDE)
- case False
- SendGuiParameterShow("txt_js", HIDE)
- SendGuiParameterShow("btn_save", HIDE)
- SendGuiParameterShow("autoLoadInterval", SHOW)
- SendGuiParameterShow("autoLoad", SHOW)
- SendGuiParameterShow("btn_load", SHOW)
- if _autoLoad then
- SendGuiParameterShow("autoLoadInterval", SHOW)
- startTimer(_duration)
- else
- SendGuiParameterShow("autoLoadInterval", HIDE)
- end if
- end select
- end sub
- sub OnExecAction(buttonId as Integer)
- if buttonId == 1 then
- _browser.GetFunctionPluginInstance("BrowserCEF").PushButton("reload")
- end if
- if buttonId == 2 then
- _browser.GetFunctionPluginInstance("BrowserCEF").SetParameterString("javascript", _js)
- _browser.GetFunctionPluginInstance("BrowserCEF").SetParameterString("javascriptfunction", _jsFunction)
- end if
- end sub
- sub startTimer(duration as integer)
- _time = 0
- _duration = duration
- _runTimer = true
- end sub
- sub onTimerEnd()
- _runTimer = false
- _browser.GetFunctionPluginInstance("BrowserCEF").PushButton("reload")
- if _autoLoad = true then
- startTimer(_duration)
- end if
- end sub
- sub OnExecPerField()
- if _runTimer then
- _time++
- if _time = _duration then
- onTimerEnd
- end if
- end if
- end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement