require "Gelo" JSRunner = {} JSRunner.default_jsdir = ProgDir..'Scripts\\' function JSRunner:runjs() if extbar.getval('button[name="clearlog"]') == 'True' then tab:clearlog() end local script = extbar.getval('plaintext[name="script"]') local startline = extbar.getval('input[name="startline"]') extbar.setattrib('button[name="run"]','disabled','True') app.processmessages() tab:runjavascript(script,tab.url,startline) extbar.setattrib('button[name="run"]','disabled','') end function JSRunner:openjs() extbar.setattrib('button[name="run"]','disabled','') local f = extbar.getval('select[name="scriptlist"]') local fcontents = '' if file_exists(self.default_jsdir..f) then fcontents = file_gettostr(self.default_jsdir..f) end extbar.setval('plaintext[name="script"]',fcontents) end function JSRunner:get_scriptlist() local p = GStrListParser:new() local flist = GStrList:new() local l = file_getdirfiles(self.default_jsdir..'*.js') p:loadfromstr(l) while p:parsing() do flist:add('') end local result = flist.text flist:release() p:release() return result end function JSRunner:viewjseditor(script,scbxname) local defaultjs = [[]] local html = [[
</plaintext> </td> <td style="width:3px;"></td> <td width="40%" valign="top"> External Scripts: <font color="gray">(Place your .js scripts in <b>]]..ProgDir..[[Scripts\</b>)</font> <select .file-list name="scriptlist" size="5" style="width:100%;" onchange="JSRunner:openjs()"> ]] local html_end = [[ </select><br><br> You can use <b>Sandcat.WriteLn()</b> and <b>Sandcat.Write()</b> to print to the Log tab. </td> </tr></table> <button name="run" onclick="JSRunner:runjs()">Execute JavaScript in Loaded Page <img src="Syhunt.scx#Images\icon_lang_javascript.png" style="height:10px;width:10px;"></button> &nbsp;&nbsp;Start Line: <INPUT name="startline" type="number" step=1 minvalue="0" value="0" size="10"> &nbsp;&nbsp;<button type="checkbox" name="clearlog" checked>Clear log before execution</button> ]] if str_beginswith(tab.url,'http') then if script ~= nil then defaultjs = browser.readfile(scbxname,script) end extbar.load(html..self:get_scriptlist()..html_end) extbar.setval('plaintext[name="script"]',defaultjs) else app.showmessage('No URL loaded.') end end