Advertisement
vizrtexample

BrowserCEF Parser

Oct 16th, 2020
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. dim _time as integer
  2. dim _duration as integer
  3. dim _runTimer as Boolean = false
  4. dim _fps as integer = 1 / System.CurrentRefreshRate
  5. dim _autoLoad as boolean = False
  6. dim _response as string = ""
  7. dim _browser as container = this.FirstChildContainer
  8. dim _js as string = GetParameterString("js")
  9. dim _jsFunction as string = "VizCallbackA"
  10.  
  11. sub OnInitParameters()
  12.     System.Map.UnregisterChangedCallback(_browser.VizId & " BROWSER STATUS")
  13.     System.Map.RegisterChangedCallback(_browser.VizId & " BROWSER STATUS")
  14.     RegisterParameterString("filename", "File Name", "", 80, 1000, "")
  15.     RegisterParameterBool("editor", "Javascript Editor", False)
  16.     RegisterParameterText("txt_js", "", 760, 250)
  17.     RegisterPushButton( "btn_save", " SAVE ", 2 )  
  18.     RegisterParameterBool("autoLoad", "Load Automatically", False)
  19.     RegisterParameterInt("autoLoadInterval", "Automatic load period", 10, 1, 6000)         
  20.     RegisterPushButton( "btn_load", " LOAD ", 1 )  
  21. end sub
  22.  
  23. sub OnInit()
  24.     SetData("")
  25.     System.Map[_browser.VizId & " BROWSER STATUS"] = ""
  26.     _duration = GetParameterInt("autoLoadInterval") * _fps
  27.     if GetParameterBool("autoLoad") then
  28.        startTimer(_duration)   
  29.     end if
  30. end sub
  31.  
  32. sub SetData(data as string)
  33.     this.FindSubContainer("Result").geometry.text = ""
  34.     this.FindSubContainer("Result").geometry.text = data
  35. end sub
  36.  
  37. sub OnParameterChanged(parameterName As String)
  38.     if parameterName = "txt_js" then
  39.        _js = GetParameterString("txt_js")
  40.        _js.Trim
  41.        _jsFunction.Trim
  42.     end if
  43.    
  44.     if parameterName = "filename" then
  45.         SetData("")
  46.        _browser.GetFunctionPluginInstance("BrowserCEF").SetParameterString("url", GetParameterString("filename"))
  47.     end if 
  48.            
  49.     if parameterName = "autoLoad" then
  50.         _autoLoad = GetParameterBool("autoLoad")
  51.     end if
  52.     if parameterName = "autoLoadInterval" then
  53.         _duration = GetParameterInt("autoLoadInterval") * _fps
  54.     end if     
  55. end sub
  56.  
  57. sub OnSharedMemoryVariableChanged(map As SharedMemory, mapKey As String)
  58.     SetData("")
  59.     if mapKey = _browser.VizId & " BROWSER STATUS" then
  60.        if CStr(System.Map[_browser.VizId & " BROWSER STATUS"]).Find("1 loadstate stopped") <> -1 then
  61.           _browser.GetFunctionPluginInstance("BrowserCEF").PushButton("execjavascript")
  62.        end if
  63.        if cstr(System.Map[_browser.VizId & " BROWSER STATUS"]).Find("javascript " & _jsFunction) <> -1 then
  64.           _response = CStr(System.Map[_browser.VizId & " BROWSER STATUS"])
  65.           _response.Substitute("0 javascript " & _jsFunction, "", true)
  66.           _response.Substitute("1 javascript " & _jsFunction, "", true)
  67.           _response.Trim
  68.           SetData(_response)
  69.        end if
  70.     end if
  71. end sub
  72.  
  73. sub OnGuiStatus()
  74.     select case GetParameterBool("editor")
  75.        case True
  76.           SendGuiParameterShow("txt_js", SHOW)
  77.           SendGuiParameterShow("btn_save", SHOW)
  78.           SendGuiParameterShow("autoLoadInterval", HIDE)
  79.           SendGuiParameterShow("autoLoad", HIDE)
  80.           SendGuiParameterShow("btn_load", HIDE)
  81.        case False
  82.           SendGuiParameterShow("txt_js", HIDE)
  83.           SendGuiParameterShow("btn_save", HIDE)
  84.           SendGuiParameterShow("autoLoadInterval", SHOW)
  85.           SendGuiParameterShow("autoLoad", SHOW)
  86.           SendGuiParameterShow("btn_load", SHOW)
  87.           if _autoLoad then
  88.              SendGuiParameterShow("autoLoadInterval", SHOW)
  89.              startTimer(_duration) 
  90.           else
  91.              SendGuiParameterShow("autoLoadInterval", HIDE)
  92.           end if   
  93.     end select
  94. end sub
  95.  
  96. sub OnExecAction(buttonId as Integer)
  97.     if buttonId == 1 then
  98.        _browser.GetFunctionPluginInstance("BrowserCEF").PushButton("reload")
  99.     end if
  100.     if buttonId == 2 then
  101.        _browser.GetFunctionPluginInstance("BrowserCEF").SetParameterString("javascript", _js)
  102.        _browser.GetFunctionPluginInstance("BrowserCEF").SetParameterString("javascriptfunction", _jsFunction)
  103.     end if 
  104. end sub
  105.  
  106. sub startTimer(duration as integer)
  107.     _time = 0
  108.     _duration = duration
  109.     _runTimer = true
  110. end sub
  111.  
  112. sub onTimerEnd()
  113.     _runTimer = false
  114.     _browser.GetFunctionPluginInstance("BrowserCEF").PushButton("reload")
  115.     if _autoLoad = true then
  116.        startTimer(_duration)   
  117.     end if
  118. end sub
  119.  
  120. sub OnExecPerField()
  121.     if _runTimer then
  122.         _time++
  123.         if _time = _duration then
  124.             onTimerEnd
  125.         end if
  126.     end if
  127. end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement