Advertisement
roger109z

Untitled

Jul 25th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.89 KB | None | 0 0
  1. QUANTUM = "v1.3.2"
  2. args = {...}
  3. local function openModem()
  4. local tbl = redstone.getSides()
  5. for k, v in pairs(tbl) do
  6. if peripheral.getType(v) == "modem" then
  7. local modem = peripheral.wrap(v)
  8. if modem.isWireless() == true then
  9. rednet.open(v)
  10. return true
  11. end
  12. end
  13. end
  14. return false
  15. end
  16. if openModem() == false then
  17. error("Please attach a wireless modem!")
  18. end
  19. --[[
  20. local function update(vers)
  21. rednet.send(1157, "quantum.browser/code.txt", "GET")
  22. local _, tbl = rednet.receive("GET", 1)
  23. if type(tbl) == "table" and string.find(tbl[1], 'QUANTUM = "'..vers..'"') == nil then
  24. local file = fs.open(shell.getRunningProgram(), "w")
  25. for k, v in pairs(tbl) do
  26. file.writeLine(v)
  27. end
  28. file.close()
  29. return true
  30. elseif type(tbl) ~= "table" then
  31. return false
  32. end
  33. end
  34. if update(QUANTUM) == true then
  35. error("Successfully updated!")
  36. end
  37. --]]
  38. local function copyTable(...)
  39. tArgs={...}
  40. local B={}
  41. for _,A in pairs(tArgs) do
  42. if A and type(A)=="table" then
  43. for i,k in pairs(A) do
  44. if type(k)=="table" then B[i]=copyTable( B[i] or {},k)
  45. else B[i]=k end
  46. end
  47. end
  48. end
  49. return B
  50. end
  51.  
  52. myENV = copyTable(_ENV)
  53.  
  54. myENV.nativeopen = fs.open
  55. myENV.nativecopy = fs.copy
  56. myENV.nativedelete = fs.delete
  57. myENV.nativemove = fs.move
  58. myENV.fs.open = function(file, mode)
  59. if _G.confirm(file) == true then
  60. return nativeopen(file, mode)
  61. end
  62. end
  63. myENV.fs.copy = function(orig, to)
  64. if _G.confirm(orig) == true then
  65. return nativecopy(orig, to)
  66. end
  67. end
  68. myENV.fs.delete = function(file)
  69. if _G.confirm(file) == true then
  70. return nativedelete(file)
  71. end
  72. end
  73. myENV.fs.move = function(file, to)
  74. if _G.confirm(file) == true then
  75. return nativemove(file, to)
  76. end
  77. end
  78. local addrs
  79. local tab = 1
  80. local tabs = {}
  81. if args[1] ~= nil then
  82. loadPage(args[1])
  83. return true
  84. end
  85. local blacklist = {"update.browser"}
  86. function _G.confirm(file)
  87. local str = " allow website to read, edit or move: "
  88. local win3 = window.create(term.native(), 2, 8, 49, 3)
  89. term.redirect(win3)
  90. term.setBackgroundColor(colors.white)
  91. term.clear()
  92. term.setTextColor(colors.black)
  93. term.setCursorPos(1, 1)
  94. term.write(str)
  95. term.setCursorPos(1, 2)
  96. term.write(" "..file)
  97. term.setBackgroundColor(colors.lime)
  98. term.setCursorPos(3, 3)
  99. term.write("allow[y]")
  100. term.setBackgroundColor(colors.red)
  101. term.setCursorPos(16, 3)
  102. term.write("decline[n]")
  103. while true do
  104. local tbl = { os.pullEvent("char") }
  105. if tbl[2] == "y" then
  106. return true
  107. elseif tbl[2] == "n" then
  108. return false
  109. end
  110. end
  111. end
  112. rd = function(lmt, start, cvr)
  113. local col = term.getBackgroundColor()
  114. local x, y = term.getCursorPos()
  115. if lmt == nil then
  116. local xc = term.getCursorPos()
  117. local x = term.getSize()
  118. lmt = x - xc
  119. end
  120. term.setCursorBlink(true)
  121. local outstr = {}
  122. local function Rupdate()
  123. local x3, y3 = term.getCursorPos()
  124. paintutils.drawLine(x, y, x+lmt, y, col)
  125. term.setCursorPos(x+lmt, y)
  126. for i = 1, lmt do
  127. term.setCursorPos(x+lmt-i, y)
  128. if outstr[i] ~= nil then
  129. if cvr == nil then
  130. write(outstr[#outstr-i+1])
  131. else
  132. write(cvr)
  133. end
  134. end
  135. end
  136. term.setCursorPos(x+lmt, y)
  137. end
  138. if start ~= nil then
  139. for i in string.gmatch(start, ".") do
  140. table.insert(outstr, i)
  141. end
  142. term.setCursorPos(x, y)
  143. if #outstr < lmt then
  144. for i = 1, #outstr do
  145. if cvr == nil then
  146. write(outstr[i])
  147. else
  148. write(cvr)
  149. end
  150. end
  151. else
  152. Rupdate()
  153. end
  154. end
  155. while true do
  156. if lmt == nil then
  157. return false
  158. end
  159. eve, let = os.pullEvent()
  160. if eve == "char" then
  161. outstr[#outstr+1] = let
  162. if #outstr <= lmt then
  163. if cvr == nil then
  164. write(let)
  165. else
  166. write(cvr)
  167. end
  168. else
  169. Rupdate()
  170. end
  171. elseif eve == "key" then
  172. if let == 14 and outstr ~= {} then
  173. outstr[#outstr] = nil
  174. if #outstr <= lmt then
  175. paintutils.drawLine(x, y, x+lmt, y, col)
  176. term.setCursorPos(x, y)
  177. for i = 1, #outstr do
  178. if cvr == nil then
  179. write(outstr[i])
  180. else
  181. write(cvr)
  182. end
  183. end
  184. else
  185. Rupdate()
  186. end
  187. elseif let == 28 then
  188. local restr = ""
  189. for i = 1, #outstr do
  190. restr = restr..outstr[i]
  191. end
  192. term.setCursorBlink(false)
  193. return restr
  194. elseif let == 15 then
  195. local restr = ""
  196. for i = 1, #outstr do
  197. restr = restr..outstr[i]
  198. end
  199. term.setCursorBlink(false)
  200. return restr, "tab"
  201. end
  202. end
  203. end
  204. end
  205. local win = window.create(term.native(), 1, 1, 51, 18)
  206. local function addrsBar()
  207. term.redirect(term.native())
  208. paintutils.drawLine(1, 19, 51, 19, colors.lightGray)
  209. term.setCursorPos(1, 19)
  210. term.setTextColor(colors.black)
  211. if tabs[tab] ~= nil then
  212. term.write(tabs[tab].site)
  213. end
  214. term.write("> ")
  215. term.setBackgroundColor(colors.lime)
  216. term.setCursorPos(49, 19)
  217. term.write("Go")
  218. term.setBackgroundColor(colors.red)
  219. term.setCursorPos(51, 19)
  220. term.write("X")
  221. term.setBackgroundColor(colors.lightGray)
  222. end
  223. local function send(id, site)
  224. rednet.send(id, site, "GET")
  225. local _, tbl = rednet.receive("GET", 1)
  226. return tbl
  227. end
  228. local sites = nil
  229. local function getTbl()
  230. local tble = send(946, "omega.com/sites.tbl")
  231. local str = "thing = "
  232. for k, v in pairs(tble) do
  233. str = str..v
  234. end
  235. str = str.." return thing"
  236. local func, ok = loadstring(str)
  237. if ok ~= nil then
  238. printError(str)
  239. error("unable to fetch list please try again later")
  240. end
  241. sites = func()
  242. end
  243.  
  244. getTbl()
  245. local function lookup(site)
  246. local ind = site:find("/")
  247. if ind ~= nil then
  248. site = site:sub(1, ind-1)
  249. end
  250. for k, v in pairs(blacklist) do
  251. if site == v then
  252. return false
  253. end
  254. end
  255. if sites[site] ~= nil then
  256. return sites[site]
  257. else
  258. return false
  259. end
  260. end
  261. local run = true
  262. local function cor()
  263. local ask
  264. while true do
  265. local tbl = {os.pullEvent()}
  266. if tbl[1] == "break" then
  267. printError("break")
  268. break
  269. elseif tbl[1] == "run" then
  270. tbl = nil
  271. elseif type(tabs[tab].func) ~= "thread" then
  272. tbl = nil
  273. elseif tbl[1] == "pause" then
  274. while true do
  275. local eve = os.pullEvent("resume")
  276. if eve == "resume" then
  277. break
  278. end
  279. end
  280. elseif tbl[1] == "mouse_click" and tbl[4] == 19 then
  281. tbl = nil
  282. elseif tbl[1] == tabs[tab].ask or tabs[tab].ask == nil then
  283. if coroutine.status(tabs[tab].func) ~= "dead" then
  284. term.redirect(win)
  285. win.redraw()
  286. local status, ask = coroutine.resume(tabs[tab].func, table.unpack(tbl))
  287. tabs[tab].ask = ask
  288. if status == false then
  289. printError(tabs[tab].ask)
  290. end
  291. term.redirect(term.native())
  292. end
  293. end
  294. end
  295. end
  296.  
  297. function loadPage(url, ...)
  298. if type(url) ~= "string" then
  299. return false
  300. end
  301. local site = lookup(url)
  302. local id
  303. if site ~= false then
  304. id = site.id
  305. else
  306. return false
  307. end
  308. local args = {...}
  309. addrsBar()
  310. term.redirect(win)
  311. term.setBackgroundColor(colors.black)
  312. term.setTextColor(colors.white)
  313. term.setCursorPos(1, 1)
  314. term.clear()
  315. win.redraw()
  316. local ind = string.find(url, "/")
  317. local str = url
  318. if ind ~= nil then
  319. str = url:sub(1, ind-1)
  320. end
  321. for k, v in pairs(blacklist) do
  322. if str == v then
  323. return false
  324. end
  325. end
  326. local tbl = combine(send(id, url))
  327. local str = ""
  328. for k, v in pairs(tbl) do
  329. str = str..v.."\n"
  330. end
  331. local func, ok = setfenv(loadstring(str), myENV)
  332. run = true
  333. os.queueEvent("run")
  334. if ok ~= nil then
  335. print(ok)
  336. else
  337. tabs[tab].func = coroutine.create(function() func(shell.getRunningProgram(), "quantum", table.unpack(args)) end)
  338. tabs[tab].ask = nil
  339. tabs[tab].site = url
  340. addrsBar()
  341. end
  342. end
  343. _G.loadPage = loadPage
  344. local function search()
  345. os.queueEvent("pause")
  346. addrsBar()
  347. term.redirect(term.native())
  348. term.setTextColor(colors.black)
  349. term.setCursorPos(string.len(tabs[tab].site.."> ")+1, 19)
  350. term.setBackgroundColor(colors.lightGray)
  351. local t = string.lower(rd(51-string.len(tabs[tab].site.."> ")-3), tabs[tab].site)
  352. return t
  353. end
  354. local function goto(t)
  355. local tbl = lookup(t)
  356. if tbl == false then
  357. loadPage("omega.com", t)
  358. else
  359. loadPage(t)
  360. end
  361. end
  362. function combine(tbl)
  363. return tbl
  364. end
  365. local function getBar()
  366. while true do
  367. local tbl = { os.pullEvent() }
  368. if tbl[1] == "mouse_click" and tbl[4] == 19 then
  369. if tbl[3] < 49 then
  370. os.queueEvent("pause")
  371. addrs = search()
  372. os.queueEvent("resume")
  373. elseif tbl[3] == 49 or tbl[3] == 50 then
  374. os.queueEvent("pause")
  375. if addrs == nil then
  376. addrs = ""
  377. end
  378. goto(addrs)
  379. os.queueEvent("resume")
  380. elseif tbl[3] == 51 then
  381. run = false
  382. os.queueEvent("break")
  383. break
  384. end
  385. end
  386. end
  387. end
  388. tabs[tab] = {}
  389. loadPage("omega.com")
  390. addrsBar()
  391. parallel.waitForAll(cor, getBar)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement