ScriptRunner = {} ScriptRunner.default_scriptdir = app.dir..'Scripts\\' function ScriptRunner:reset() debug.print('Reseting Script Runner...') Runik.Options.ModuleName = 'Sandcat' Runik.Options.RedirectIO = true Runik.Options.UseGlobals = false end function ScriptRunner:start() local initscript = [[ require "Runik" Runik.Options.ModuleName = 'Sandcat' Runik.Options.RedirectIO = true Runik.Options.UseGlobals = true ]] browser.addlua('task.init',initscript) end function ScriptRunner:javascript_browser(script) local ui = self.ui tab:runjs(script,tab.url,ui.startline.value) end function ScriptRunner:canrunext(ext) local r = true if ext == 'py' then if hassoftware('Python') == false then r = false app.showmessage('Python not installed!') end end return r end function ScriptRunner:showvariables() local vars = [[ tabURL = contains the tab URL
tabSource = contains the tab source
tabRcvdHeaders = contains all the received HTTP headers
tabSentHeaders = contains all the sent HTTP headers ]] app.showmessagex(vars) end function ScriptRunner:runscript(ext,script) if self:canrunext(ext) then require "Runik" self:reset() local tabURL = tab.url local tabSource = tab.source local tabRcvdHeaders = tab.rcvdheaders local tabSentHeaders = tab.sentheaders debug.print('Executing...') tab.status = 'Executing script...' if ext == 'js' then self:javascript_browser(script) end if ext == 'jsc' then Runik.Run.jscript(script) end if ext == 'lua' then assert(loadstring(script))() end if ext == 'pas' then Runik.Run.pascalscript(script) end if ext == 'pasrem' then Runik.Run.pascalprog(script) end if ext == 'pl' then Runik.Run.perl(script) end if ext == 'php' then Runik.Run.php(script) end if ext == 'py' then Runik.Run.python(script) end if ext == 'rb' then Runik.Run.ruby(script) end if ext == 'vbs' then Runik.Run.vbscript(script) end if ext == 'tis' then browser.navbar:eval(script) end tab.status = 'Done.' end end function ScriptRunner:runscriptfile(file) local script = scop.file.getcontents(file) local ext = string.lower(scop.file.getext(file)) ext = stringop.after(ext,'.') self:runscript(ext,script) end function ScriptRunner:execute(ext) local ui = self.ui if ui.buttonclearlog.value == true then tab:clearlog() end self:runscript(ext,ui.codeedit.value) end function ScriptRunner:openscript_inp() local ui = self.ui local f = ui.scriptfile.value if scop.file.exists(f) then local s = scop.file.getcontents(f) ui.codeedit.value = s end if f == '' then ui.codeedit.value = '' end end function ScriptRunner:savescript() local ui = self.ui local f = ui.scriptfile.value local ext = ui.lablangext.value local sl = scl.stringlist:new() sl.text = ui.codeedit.value if scop.file.exists(f) then sl:savetofile(f) ui.scriptfile.value = f else f = app.savefile('All files (*.*)|*.*',ext,'Untitled.'..ext) if f ~= '' then sl:savetofile(f) ui.scriptfile.value = f end end sl:release() end function ScriptRunner:openscript() local ui = self.ui ui.buttonrun.enabled = true local f = ui.scriptlist.value local file = self.default_scriptdir..f local fcontents = '' if scop.file.exists(file) then fcontents = scop.file.getcontents(file) ui.scriptfile.value = file end ui.codeedit.value = fcontents end function ScriptRunner:get_scriptlist(ext) local p = scl.listparser:new() local flist = scl.stringlist:new() local l = scop.dir.getfilelist(self.default_scriptdir..'*.'..ext) p:load(l) while p:parsing() do flist:add('') end local result = flist.text flist:release() p:release() return result end function ScriptRunner:loadscript(package,script) local ui = self.ui ui.codeedit.value = browser.getpackfile(package,script) ui.scriptfile.value = 'pak:'..script end function ScriptRunner:loadhelpscript(script) self:loadscript(Syhunt.filename,'Scripts/scriptrunner/'..script) end function ScriptRunner:vieweditor_lua() self:vieweditor('Lua','lua','Lua Script') end function ScriptRunner:vieweditor_js() self:vieweditor('JavaScript','js','JavaScript') end function ScriptRunner:vieweditor(lang_name,lang_ext,lang_desc) local html = Syhunt:getfile('Scripts/ScriptRunner.html') local helpitems = Syhunt:getfile('Scripts/scriptrunner/Menu_'..lang_name..'.html') if lang_ext ~= 'js' and lang_ext ~= 'lua' and lang_ext ~= 'tis' then helpitems = helpitems.."
  • Available Variables
  • " end local extraoptions = Syhunt:getfile('Scripts/scriptrunner/Options_'..lang_name..'.html') html = stringop.replace(html,'',helpitems) html = stringop.replace(html,'',self:get_scriptlist(lang_ext)) html = stringop.replace(html,'',extraoptions) browser.loadpagex(lang_ext..'runner',html,'ScriptRunner.ui') --tab:showcodeedit('','.'..lang_ext,html) local ui = self.ui ui.labprogdir.value = app.dir ui.lablangext.value = lang_ext if lang_desc == nil then lang_desc = lang_name end ui.for_run.value = 'Execute '..lang_desc ui.btnscripts:setstyle('foreground-image','url(Syhunt.scx#Images\\icon_lang_'..string.lower(lang_name)..'.png)') ui.buttonrun:setattrib('onclick',"ScriptRunner:execute('"..lang_ext.."')") ui.scriptfile:setattrib('filter',lang_name..' script file:*.'..lang_ext..';All files:*.*') end