Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Simple Web Browser for CC:Tweaked
- -- Replace with your proxy server's address
- local proxy_url = "http://192.168.0.128:8080/fetch"
- -- Function to fetch webpage content
- local function fetch_url(url)
- local response = http.post(proxy_url, "url=" .. textutils.urlEncode(url))
- if response then
- local content = response.readAll()
- response.close()
- return content
- else
- return "Failed to fetch URL. Check proxy server or connection."
- end
- end
- -- Main browser loop
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- print("=== CC:Tweaked Web Browser ===")
- write("Enter URL (or 'exit' to quit): ")
- local url = read()
- -- Exit condition
- if url == "exit" then
- print("Goodbye!")
- break
- end
- -- Add http:// if no protocol is specified
- if not url:match("^https?://") then
- url = "http://" .. url
- end
- -- Fetch and display content
- local content = fetch_url(url)
- term.clear()
- term.setCursorPos(1, 1)
- print(content)
- -- Prompt for link selection
- write("\nEnter link number to follow (or 0 to go back): ")
- local input = read()
- local choice = tonumber(input)
- if choice and choice > 0 then
- -- Extract the URL from the link line
- for line in content:gmatch("[^\n]+") do
- local num, link_url = line:match("^%[(%d+)%].*-> (.+)$")
- if num and tonumber(num) == choice then
- url = link_url
- break
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment