Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- QUANTUM = "v1.3.2"
- args = {...}
- local function openModem()
- local tbl = redstone.getSides()
- for k, v in pairs(tbl) do
- if peripheral.getType(v) == "modem" then
- local modem = peripheral.wrap(v)
- if modem.isWireless() == true then
- rednet.open(v)
- return true
- end
- end
- end
- return false
- end
- if openModem() == false then
- error("Please attach a wireless modem!")
- end
- --[[
- local function update(vers)
- rednet.send(1157, "quantum.browser/code.txt", "GET")
- local _, tbl = rednet.receive("GET", 1)
- if type(tbl) == "table" and string.find(tbl[1], 'QUANTUM = "'..vers..'"') == nil then
- local file = fs.open(shell.getRunningProgram(), "w")
- for k, v in pairs(tbl) do
- file.writeLine(v)
- end
- file.close()
- return true
- elseif type(tbl) ~= "table" then
- return false
- end
- end
- if update(QUANTUM) == true then
- error("Successfully updated!")
- end
- --]]
- local function copyTable(...)
- tArgs={...}
- local B={}
- for _,A in pairs(tArgs) do
- if A and type(A)=="table" then
- for i,k in pairs(A) do
- if type(k)=="table" then B[i]=copyTable( B[i] or {},k)
- else B[i]=k end
- end
- end
- end
- return B
- end
- myENV = copyTable(_ENV)
- myENV.nativeopen = fs.open
- myENV.nativecopy = fs.copy
- myENV.nativedelete = fs.delete
- myENV.nativemove = fs.move
- myENV.fs.open = function(file, mode)
- if _G.confirm(file) == true then
- return nativeopen(file, mode)
- end
- end
- myENV.fs.copy = function(orig, to)
- if _G.confirm(orig) == true then
- return nativecopy(orig, to)
- end
- end
- myENV.fs.delete = function(file)
- if _G.confirm(file) == true then
- return nativedelete(file)
- end
- end
- myENV.fs.move = function(file, to)
- if _G.confirm(file) == true then
- return nativemove(file, to)
- end
- end
- local addrs
- local tab = 1
- local tabs = {}
- if args[1] ~= nil then
- loadPage(args[1])
- return true
- end
- local blacklist = {"update.browser"}
- function _G.confirm(file)
- local str = " allow website to read, edit or move: "
- local win3 = window.create(term.native(), 2, 8, 49, 3)
- term.redirect(win3)
- term.setBackgroundColor(colors.white)
- term.clear()
- term.setTextColor(colors.black)
- term.setCursorPos(1, 1)
- term.write(str)
- term.setCursorPos(1, 2)
- term.write(" "..file)
- term.setBackgroundColor(colors.lime)
- term.setCursorPos(3, 3)
- term.write("allow[y]")
- term.setBackgroundColor(colors.red)
- term.setCursorPos(16, 3)
- term.write("decline[n]")
- while true do
- local tbl = { os.pullEvent("char") }
- if tbl[2] == "y" then
- return true
- elseif tbl[2] == "n" then
- return false
- end
- end
- end
- rd = function(lmt, start, cvr)
- local col = term.getBackgroundColor()
- local x, y = term.getCursorPos()
- if lmt == nil then
- local xc = term.getCursorPos()
- local x = term.getSize()
- lmt = x - xc
- end
- term.setCursorBlink(true)
- local outstr = {}
- local function Rupdate()
- local x3, y3 = term.getCursorPos()
- paintutils.drawLine(x, y, x+lmt, y, col)
- term.setCursorPos(x+lmt, y)
- for i = 1, lmt do
- term.setCursorPos(x+lmt-i, y)
- if outstr[i] ~= nil then
- if cvr == nil then
- write(outstr[#outstr-i+1])
- else
- write(cvr)
- end
- end
- end
- term.setCursorPos(x+lmt, y)
- end
- if start ~= nil then
- for i in string.gmatch(start, ".") do
- table.insert(outstr, i)
- end
- term.setCursorPos(x, y)
- if #outstr < lmt then
- for i = 1, #outstr do
- if cvr == nil then
- write(outstr[i])
- else
- write(cvr)
- end
- end
- else
- Rupdate()
- end
- end
- while true do
- if lmt == nil then
- return false
- end
- eve, let = os.pullEvent()
- if eve == "char" then
- outstr[#outstr+1] = let
- if #outstr <= lmt then
- if cvr == nil then
- write(let)
- else
- write(cvr)
- end
- else
- Rupdate()
- end
- elseif eve == "key" then
- if let == 14 and outstr ~= {} then
- outstr[#outstr] = nil
- if #outstr <= lmt then
- paintutils.drawLine(x, y, x+lmt, y, col)
- term.setCursorPos(x, y)
- for i = 1, #outstr do
- if cvr == nil then
- write(outstr[i])
- else
- write(cvr)
- end
- end
- else
- Rupdate()
- end
- elseif let == 28 then
- local restr = ""
- for i = 1, #outstr do
- restr = restr..outstr[i]
- end
- term.setCursorBlink(false)
- return restr
- elseif let == 15 then
- local restr = ""
- for i = 1, #outstr do
- restr = restr..outstr[i]
- end
- term.setCursorBlink(false)
- return restr, "tab"
- end
- end
- end
- end
- local win = window.create(term.native(), 1, 1, 51, 18)
- local function addrsBar()
- term.redirect(term.native())
- paintutils.drawLine(1, 19, 51, 19, colors.lightGray)
- term.setCursorPos(1, 19)
- term.setTextColor(colors.black)
- if tabs[tab] ~= nil then
- term.write(tabs[tab].site)
- end
- term.write("> ")
- term.setBackgroundColor(colors.lime)
- term.setCursorPos(49, 19)
- term.write("Go")
- term.setBackgroundColor(colors.red)
- term.setCursorPos(51, 19)
- term.write("X")
- term.setBackgroundColor(colors.lightGray)
- end
- local function send(id, site)
- rednet.send(id, site, "GET")
- local _, tbl = rednet.receive("GET", 1)
- return tbl
- end
- local sites = nil
- local function getTbl()
- local tble = send(946, "omega.com/sites.tbl")
- local str = "thing = "
- for k, v in pairs(tble) do
- str = str..v
- end
- str = str.." return thing"
- local func, ok = loadstring(str)
- if ok ~= nil then
- printError(str)
- error("unable to fetch list please try again later")
- end
- sites = func()
- end
- getTbl()
- local function lookup(site)
- local ind = site:find("/")
- if ind ~= nil then
- site = site:sub(1, ind-1)
- end
- for k, v in pairs(blacklist) do
- if site == v then
- return false
- end
- end
- if sites[site] ~= nil then
- return sites[site]
- else
- return false
- end
- end
- local run = true
- local function cor()
- local ask
- while true do
- local tbl = {os.pullEvent()}
- if tbl[1] == "break" then
- printError("break")
- break
- elseif tbl[1] == "run" then
- tbl = nil
- elseif type(tabs[tab].func) ~= "thread" then
- tbl = nil
- elseif tbl[1] == "pause" then
- while true do
- local eve = os.pullEvent("resume")
- if eve == "resume" then
- break
- end
- end
- elseif tbl[1] == "mouse_click" and tbl[4] == 19 then
- tbl = nil
- elseif tbl[1] == tabs[tab].ask or tabs[tab].ask == nil then
- if coroutine.status(tabs[tab].func) ~= "dead" then
- term.redirect(win)
- win.redraw()
- local status, ask = coroutine.resume(tabs[tab].func, table.unpack(tbl))
- tabs[tab].ask = ask
- if status == false then
- printError(tabs[tab].ask)
- end
- term.redirect(term.native())
- end
- end
- end
- end
- function loadPage(url, ...)
- if type(url) ~= "string" then
- return false
- end
- local site = lookup(url)
- local id
- if site ~= false then
- id = site.id
- else
- return false
- end
- local args = {...}
- addrsBar()
- term.redirect(win)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(1, 1)
- term.clear()
- win.redraw()
- local ind = string.find(url, "/")
- local str = url
- if ind ~= nil then
- str = url:sub(1, ind-1)
- end
- for k, v in pairs(blacklist) do
- if str == v then
- return false
- end
- end
- local tbl = combine(send(id, url))
- local str = ""
- for k, v in pairs(tbl) do
- str = str..v.."\n"
- end
- local func, ok = setfenv(loadstring(str), myENV)
- run = true
- os.queueEvent("run")
- if ok ~= nil then
- print(ok)
- else
- tabs[tab].func = coroutine.create(function() func(shell.getRunningProgram(), "quantum", table.unpack(args)) end)
- tabs[tab].ask = nil
- tabs[tab].site = url
- addrsBar()
- end
- end
- _G.loadPage = loadPage
- local function search()
- os.queueEvent("pause")
- addrsBar()
- term.redirect(term.native())
- term.setTextColor(colors.black)
- term.setCursorPos(string.len(tabs[tab].site.."> ")+1, 19)
- term.setBackgroundColor(colors.lightGray)
- local t = string.lower(rd(51-string.len(tabs[tab].site.."> ")-3), tabs[tab].site)
- return t
- end
- local function goto(t)
- local tbl = lookup(t)
- if tbl == false then
- loadPage("omega.com", t)
- else
- loadPage(t)
- end
- end
- function combine(tbl)
- return tbl
- end
- local function getBar()
- while true do
- local tbl = { os.pullEvent() }
- if tbl[1] == "mouse_click" and tbl[4] == 19 then
- if tbl[3] < 49 then
- os.queueEvent("pause")
- addrs = search()
- os.queueEvent("resume")
- elseif tbl[3] == 49 or tbl[3] == 50 then
- os.queueEvent("pause")
- if addrs == nil then
- addrs = ""
- end
- goto(addrs)
- os.queueEvent("resume")
- elseif tbl[3] == 51 then
- run = false
- os.queueEvent("break")
- break
- end
- end
- end
- end
- tabs[tab] = {}
- loadPage("omega.com")
- addrsBar()
- parallel.waitForAll(cor, getBar)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement