Orion09

browser

Mar 16th, 2025 (edited)
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. -- Simple Web Browser for CC:Tweaked
  2.  
  3. -- Replace with your proxy server's address
  4. local proxy_url = "http://192.168.0.128:8080/fetch"
  5.  
  6. -- Function to fetch webpage content
  7. local function fetch_url(url)
  8. local response = http.post(proxy_url, "url=" .. textutils.urlEncode(url))
  9. if response then
  10. local content = response.readAll()
  11. response.close()
  12. return content
  13. else
  14. return "Failed to fetch URL. Check proxy server or connection."
  15. end
  16. end
  17.  
  18. -- Main browser loop
  19. while true do
  20. term.clear()
  21. term.setCursorPos(1, 1)
  22. print("=== CC:Tweaked Web Browser ===")
  23. write("Enter URL (or 'exit' to quit): ")
  24. local url = read()
  25.  
  26. -- Exit condition
  27. if url == "exit" then
  28. print("Goodbye!")
  29. break
  30. end
  31.  
  32. -- Add http:// if no protocol is specified
  33. if not url:match("^https?://") then
  34. url = "http://" .. url
  35. end
  36.  
  37. -- Fetch and display content
  38. local content = fetch_url(url)
  39. term.clear()
  40. term.setCursorPos(1, 1)
  41. print(content)
  42.  
  43. -- Prompt for link selection
  44. write("\nEnter link number to follow (or 0 to go back): ")
  45. local input = read()
  46. local choice = tonumber(input)
  47.  
  48. if choice and choice > 0 then
  49. -- Extract the URL from the link line
  50. for line in content:gmatch("[^\n]+") do
  51. local num, link_url = line:match("^%[(%d+)%].*-> (.+)$")
  52. if num and tonumber(num) == choice then
  53. url = link_url
  54. break
  55. end
  56. end
  57. end
  58. end
Advertisement
Add Comment
Please, Sign In to add comment