Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EpicBrowser = true
- local title = nil
- local x, y = term.getSize()
- -- Cool functions
- function allColour(tColour, bColour)
- if term.isColour() then
- term.setTextColour(colours[tColour])
- term.setBackgroundColour(colours[bColour])
- else
- term.setTextColour(colours.white)
- term.setBackgroundColour(colours.black)
- end
- end
- function textColour(tColour)
- if term.isColour() then
- term.setTextColour(colours[tColour])
- else
- term.setTextColour(colours.white)
- term.setBackgroundColour(colours.black)
- end
- end
- function bgColour(bColour)
- if term.isColour() then
- term.setBackgroundColour(colours[bColour])
- else
- term.setTextColour(colours.white)
- term.setBackgroundColour(colours.black)
- end
- end
- function backgroundSet(bColour)
- bgColour(bColour)
- term.clear()
- end
- function resetBackground()
- allColour("white", "black")
- term.clear()
- end
- function centered(str, height, tColour, bColour)
- term.setCursorPos(x / 2 - #str / 2, height)
- if tColour and bColour then
- allColour(tColour, bColour)
- elseif tColour then
- textColour(tColour)
- elseif bColour then
- bgColour(bColour)
- end
- term.write(str)
- end
- function left(str, height, tColour, bColour)
- term.setCursorPos(1, height)
- if tColour and bColour then
- allColour(tColour, bColour)
- elseif tColour then
- textColour(tColour)
- elseif bColour then
- bgColour(bColour)
- end
- term.write(str)
- end
- function right(str, height, tColour, bColour)
- term.setCursorPos(x - #str, height)
- if tColour and bColour then
- allColour(tColour, bColour)
- elseif tColour then
- textColour(tColour)
- elseif bColour then
- bgColour(bColour)
- end
- term.write(str)
- end
- function indented(str, indent, height, tColour, bColour)
- term.setCursorPos(indent, height)
- if tColour and bColour then
- allColour(tColour, bColour)
- elseif tColour then
- textColour(tColour)
- elseif bColour then
- bgColour(bColour)
- end
- term.write(str)
- end
- function clearLine(bColour, height)
- term.setCursorPos(1, height)
- bgColour(bColour)
- term.clearLine()
- end
- function drawBorder(xMin, yMin, xMax, yMax, colour)
- paintutils.drawBox(xMin, yMin, xMax, yMax, colours[colour])
- end
- function drawBox(xMin, yMin, xMax, yMax, colour)
- paintutils.drawFilledBox(xMin, yMin, xMax, yMax, colours[colour])
- end
- function len(str) return str:len() end
- function upper(str) return str:upper() end
- function lower(str) return str:lower() end
- function replace(str, find, replace) return str:gsub(find, replace) end
- function makeLength(str, startLen, endLen) return str:sub(startLen, endLen) end
- function rep(str, times) return str:rep(times) end
- function findPeripheral(Perihp) --Returns side of first matching peripheral matching passed string
- for _,s in ipairs(rs.getSides()) do
- if peripheral.isPresent(s) and peripheral.getType(s) == Perihp then
- return s
- end
- end
- return false
- end
- modemSide = findPeripheral("modem")
- rednet.open(modemSide)
- epicb = {}
- -- Main Code
- function background()
- backgroundSet("white")
- for i = 1, 3 do
- clearLine("grey", i)
- end
- indented("Epic", 2, 2, "cyan")
- indented("Browser", 6, 2, "lightBlue")
- indented("By ", x - 6, 2, "white")
- indented("R", x - 3, 2, "yellow")
- indented("o", x - 2, 2, "red")
- indented("d", x - 1, 2, "lightBlue")
- allColour("lightBlue", "white")
- left(" [ Quit ]", y - 1)
- right("[ Request Page ] ", y - 1)
- end
- function main()
- background()
- title = "Access Page"
- centered(title, 2, "lightGrey", "grey")
- bgColour("white")
- indented("Server URL: ", 2, 5, "lightBlue")
- url = read()
- clearLine("white", 5)
- indented("Page: ", 2, 5, "lightBlue")
- page = read()
- if page:len() == 0 then page = "index" end
- clearLine("white", 5)
- indented("Timeout: ", 2, 5, "lightBlue")
- timeout = read()
- timeout = tonumber(timeout)
- if type(timeout) ~= "number" then timeout = 100 end
- clearLine("white", 5)
- rednet.broadcast(page, url)
- local event = { rednet.receive(3) }
- if not event[1] then
- clearLine("white", 5)
- centered("Failed to connect to "..url, 5, "red")
- sleep(2)
- main()
- else
- if not fs.exists(url) then
- fs.makeDir(url)
- else
- if not fs.isDir(url) then
- fs.delete(url)
- fs.makeDir(url)
- end
- end
- local file = fs.open(url.."/"..page, "w")
- file.write(event[2])
- file.close()
- shell.run(url.."/"..page)
- resetBackground()
- sleep(timeout)
- end
- end
- function checkExit()
- while true do
- local event = { os.pullEvent("mouse_click") }
- if event[2] == 1 and event[3] >= 2 and event[3] <= 9 and event[4] == y - 1 then
- resetBackground()
- left("CraftOS 1.6", 1, "yellow")
- term.setCursorPos(1, 2)
- return
- end
- end
- end
- function requestPage() -- 1
- local event = { os.pullEvent("mouse_click") }
- if event[2] == 1 and event[3] >= x - 16 and event[3] <= x - 2 and event[4] == y - 1 then -- 2
- clearLine("white", 5)
- title = "Download Page"
- centered(title, 2, "lightGrey", "grey")
- indented("Server URL: ", 2, 5, "lightBlue")
- url = read()
- clearLine("white", 5)
- indented("Page: ", 2, 5, "lightBlue")
- page = read()
- clearLine("white", 5)
- rednet.broadcast(page, url)
- local event = { rednet.receive(3) }
- if not event[1] then -- 3
- clearLine("white", 5)
- centered("Failed to connect to "..url, 5, "red")
- else
- if not fs.exists(url) then -- 4
- fs.makeDir(url)
- else
- if not fs.isDir(url) then -- 5
- fs.delete(url)
- fs.makeDir(url)
- end -- 5
- end -- 4
- local download = fs.open(url.."/"..page, "w")
- page.write(event[2])
- page.close()
- clearLine("white", 5)
- centered("Downloaded the page successfully!", 5, "green")
- sleep(2)
- main()
- end -- 3
- end -- 2
- end -- 1
- function begin()
- parallel.waitForAny(main, checkExit, requestPage)
- end
- begin()
Advertisement
Add Comment
Please, Sign In to add comment