xXm0dzXx

Untitled

Jul 20th, 2012
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. local x,y = term.getSize()
  2. rednet.open("top")
  3. local EditingValue = "";
  4.  
  5. function rednetV()
  6. return "3.0 - BETA"
  7. end
  8.  
  9. title = "Rednet Explorer " ..rednetV() --Add title = "name" to change the webpage's title!
  10. local website = "home";
  11. if fs.exists(".cache") then fs.delete(".cache") end
  12. if fs.exists(".websiteedited") then fs.delete(".websiteedited") end
  13. fs.makeDir(".cache")
  14.  
  15. local cPrint = function(text)
  16. local x2,y2 = term.getCursorPos()
  17. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  18.  
  19. print(text)
  20. end
  21.  
  22. function reDirect(url)
  23. website = url
  24. loadWebpage()
  25. end
  26.  
  27. local Address = function()
  28. text = "http://"
  29. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), 2)
  30. term.clearLine()
  31.  
  32. write(text)
  33. website = read()
  34. loadWebpage()
  35. end
  36.  
  37. function done()
  38. term.setCursorPos(1, y)
  39. name = "F5 = Refresh"
  40. write("Press CTRL to travel the web! :D")
  41. term.setCursorPos(x - name:len(), y)
  42. write(name)
  43.  
  44. while true do
  45. sleep(0) -- stop crashing
  46. e, k = os.pullEvent("key")
  47. if k == 63 then
  48. loadWebpage()
  49. break
  50. elseif k == 29 then
  51. Address()
  52. break
  53. end
  54. end
  55. end
  56.  
  57.  
  58. loadWebpage = function()
  59. term.clear()
  60. term.setCursorPos(1,1)
  61. cPrint(title)
  62. cPrint("http://" ..website.. "\n")
  63. if website == "home" then
  64. print("Welcome to RedNet explorer (3.0)! This requires you to have a wireless modem on your computer.")
  65. print("Host a website at: ")
  66. print("http://newsite! ")
  67. print(" -ComputerCraftFan11 ")
  68. elseif website == "newsite" then
  69. print("Unfinished")
  70. else
  71. title = "Rednet Explorer " ..rednetV()
  72. print("Connecting...")
  73. website1 = ".depagecrash"
  74. while true do
  75. http.request("http://" ..website)
  76. local event, url, response = os.pullEvent()
  77. if event == "http_success" then
  78. message = response.readAll()
  79. break
  80. elseif event == "http_failed" then
  81. break
  82. end
  83. end
  84.  
  85. if event == "http_failed" then
  86. print("Unable to load webpage.")
  87. else
  88. if fs.exists(".cache/" ..website1) then fs.delete(".cache/" ..website1) end
  89. webpage = fs.open(".cache/" ..website1, "w")
  90. webpage.write(message)
  91. webpage.close()
  92. term.clear()
  93. term.setCursorPos(1,1)
  94. cPrint(title)
  95. cPrint("http://" ..website.. "\n")
  96. shell.run(".cache/" ..website1)
  97. end
  98. end
  99.  
  100. done()
  101. end
  102.  
  103. loadWebpage()
Advertisement
Add Comment
Please, Sign In to add comment