Guest User

browser4.2

a guest
Oct 25th, 2015
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.13 KB | None | 0 0
  1. function c(...) return term.clear(...) end
  2. function cL(...) return term.clearLine(...) end
  3. function p(...) return print(...) end
  4. function w(...) return write(...) end
  5. function sbgc(...) return term.setBackgroundColor(...) end
  6. function stc(...) return term.setTextColor(...) end
  7. function scp(...) return term.setCursorPos(...) end
  8. function s(...) return sleep(...) end
  9.  
  10.  
  11.  
  12.  
  13.  
  14. --This is the official provider of the prBr
  15. --Enter your browser in the download mode
  16. --Thanks.
  17. --browser.download=1
  18. anCondt = true
  19. cndDns = 1
  20. function autoConfig()
  21.   if fs.exists("brconfig") == true then
  22.     shell.run("brconfig")
  23.     rednet.open(side)
  24.     begin()
  25.   else
  26.     print("first time config setup")
  27.     sleep(1)
  28.     print("modem side")
  29.     AtSide = tostring(read())
  30.     print("write the dns id")
  31.     write("dns1:")
  32.     atDns1 = read()
  33.     write("dns2:")
  34.     atDns2 = read()
  35.     print("ask for download? ")
  36.     print("[1]yes")
  37.     print("[2]no")
  38.     atAks = read()
  39.     if atAsk ~= 1 and atAsk ~= 2 then
  40.       atAsk = 1
  41.     end
  42.     print("saving")
  43.     e = fs.open("brconfig", "a")
  44.     e.writeLine("dns1 = "..atDns1)
  45.     e.writeLine("dns2 = "..atDns2)
  46.     e.writeLine("Aks = "..atAsk)
  47.     e.writeLine('side = "'..AtSide..'"')
  48.     e.close()
  49.     sleep(2)
  50.     term.clear()
  51.     autoConfig()
  52.   end
  53. end
  54. function gui()
  55.   sbgc(colors.green)
  56.   c()
  57.   scp(1,1)
  58.   sbgc(colors.blue)
  59.   cL()
  60.   sbgc(colors.white)
  61.   scp(1,2)
  62.   cL()
  63.   scp(2,2)
  64.   sbgc(colors.cyan)
  65.   p("<")
  66.   scp(4,2)
  67.   p(">")
  68.   scp(6,2)
  69.   stc(colors.black)
  70.   p("http://                            ")
  71.   scp(42,2)
  72.   stc(colors.white)
  73.   p("@")
  74.   scp(44,2)
  75.   p("^")
  76.   scp(46,2)
  77.   stc(colors.yellow)
  78.   p("*")
  79.   scp(51,1)
  80.   stc(colors.white)
  81.   sbgc(colors.red)
  82.   p("X")
  83.  
  84. end
  85. function begin()
  86.   gui()
  87.   scp(1,1)
  88.   sbgc(colors.blue)
  89.   stc(colors.white)
  90.   print("Web Browser 4.2 (*bugs reports*)")
  91.   sleep(1)
  92.   default = dns1
  93. end
  94. function click()
  95.   goHome()
  96.   while true do
  97.     event, bu , X, Y = os.pullEvent()
  98.     if event == "mouse_click" then
  99.       if X == 51 and Y == 1 then
  100.         sbgc(colors.black)
  101.         stc(colors.white)
  102.         scp(1,1)
  103.         c()
  104.         break
  105.       elseif X>= 6 and X<=41 and Y == 2 then
  106.         gui()
  107.         begin()
  108.         scp(13,2)
  109.         stc(colors.black)
  110.         sbgc(colors.cyan)
  111.         p("                            ")
  112.         scp(13,2)
  113.         id = read()
  114.         Csha = true
  115.         connect()
  116.       elseif X == 2 and Y == 2 then
  117.         comeBack()
  118.       elseif X == 4 and Y == 2 then
  119.         comeOn()
  120.       elseif X == 42 and Y == 2 then
  121.         refresh()
  122.       elseif X == 44 and Y == 2 then
  123.         if bu == 1 then
  124.           goHome()
  125.         elseif bu == 2 then
  126.           setHome()
  127.         end
  128.       elseif X == 46 and Y == 2 then
  129.         if bu == 1 then
  130.           goFav()
  131.         elseif bu == 2 then
  132.           setFav()
  133.         end
  134.       else
  135.         Llinky()
  136.       end
  137.     end
  138.   end
  139. end
  140. function Llinky()
  141.   if actL == true then
  142.   Lcnt = 0
  143.   lDone = false
  144.     repeat
  145.       Lcnt = Lcnt + 1
  146.       if X >= lX[Lcnt] and X <= lXx[Lcnt] and Y == lY[Lcnt] then
  147.         if lI[Lcnt] == "package" then
  148.           scp(lX[Lcnt], Y)
  149.           whatSend = read()
  150.           id = lL[Lcnt].."="..whatSend
  151.           begin()
  152.           connect()
  153.           lDone = true
  154.         elseif lI[Lcnt] == "link" then
  155.           id = lL[Lcnt]
  156.           begin()
  157.           connect()
  158.           lDone = true
  159.         end
  160.       end
  161.     until Lcnt >= lNumber or lDone == true
  162.   end
  163. end
  164. function Llink()
  165.   Rllink = msg:match("--browser.link=1")
  166.   if Rllink ~= nil then
  167.     temp = fs.open("temp2", "w")
  168.     temp.write(msg)
  169.     temp.close()
  170.     shell.run("temp2")
  171.     id = lPage
  172.     lPp = true
  173.     begin()
  174.     connect()
  175.     lPp = false
  176.     actL = true
  177.     fs.delete("temp2")
  178.   end
  179. end
  180. function Rconnect()
  181.   rednet.send(default,id)
  182.   ids,msg = rednet.receive(5)
  183.   if msg ~= nil then
  184.     sbgc(colors.green)
  185.     scp(1,3)
  186.     cL()
  187.     scp(1,4)
  188.     cL()
  189.     scp(1,5)
  190.     cL()
  191.     scp(1,6)
  192.     cL()
  193.     scp(1,7)
  194.     cL()
  195.     scp(1,8)
  196.     cL()
  197.     scp(1,9)
  198.     cL()
  199.     scp(1,10)
  200.     cL()
  201.     scp(1,11)
  202.     cL()
  203.     scp(1,12)
  204.     cL()
  205.     scp(1,13)
  206.     cL()
  207.     scp(1,14)
  208.     cL()
  209.     scp(1,15)
  210.     cL()
  211.     scp(1,16)
  212.     cL()
  213.     scp(1,17)
  214.     cL()
  215.     scp(1,18)
  216.     cL()
  217.     scp(1,19)
  218.     cL()
  219.     scp(1,3)
  220.     stc(colors.black)
  221.     print(msg)
  222.   end
  223. end
  224. function anim()
  225.   anCondt = false
  226.   anF = nil
  227.   if msg:match("--browser.anim=1") ~= nil then
  228.     temp = fs.open("temp", "w")
  229.     temp.write(msg)
  230.     temp.close()
  231.     shell.run("temp")
  232.     nOfF = 0
  233.     repeat
  234.       nOfF = nOfF + 1
  235.       id = anF[nOfF]
  236.       Rconnect()
  237.       s(2)
  238.     until nOfF >= anMax
  239.   end
  240.   anCondt = true
  241. end
  242. function setFav()
  243.   scp(44,3)
  244.   sbgc(colors.yellow)
  245.   print("Fav:")
  246.   scp(44,4)
  247.   print("          ")
  248.   scp(44,4)
  249.   Hfav = read()
  250.   if Hfav ~= nil then
  251.     e = fs.open("brconfig", "a")
  252.     e.writeLine('fav = "'..Hfav..'"')
  253.     e.close()
  254.     autoConfig()
  255.   end
  256. end
  257. function goFav()
  258.   id = fav
  259.   connect()
  260. end
  261. function setHome()
  262.   scp(44,3)
  263.   sbgc(colors.yellow)
  264.   print("home:")
  265.   scp(44,4)
  266.   print("          ")
  267.   scp(44,4)
  268.   Hhome = read()
  269.   if Hhome ~= nil then
  270.     e = fs.open("brconfig", "a")
  271.     e.writeLine('home = "'..Hhome..'"')
  272.     e.close()
  273.     autoConfig()
  274.   end
  275. end
  276. function goHome()
  277.   id = home
  278.   connect()
  279. end
  280. function refresh()
  281.   gui()
  282.   begin()
  283.   connect()
  284. end
  285. function comeBack()
  286.   gui()
  287.   begin()
  288.   if id == id2 and id3 ~= nil then
  289.     id = id3
  290.   elseif id == id3 and id4 ~= nil then
  291.     id = id4
  292.   end
  293.   if Csha == true then
  294.     Csha = false
  295.   end
  296.   s(.2)
  297.   connect()
  298. end
  299. function comeOn()
  300.   gui()
  301.   begin()
  302.   if id4 ~= nil and id == id4 and id3 ~= nil then
  303.     id = id3
  304.   elseif id3 ~= nil and id == id3 and id2 ~= nil then
  305.     id = id2
  306.   end
  307.   if Csha == true then
  308.     Csha = false
  309.   end
  310.   s(.2)
  311.   connect()
  312. end
  313. function connect()
  314.   if lPp ~= true then
  315.     actL = false
  316.   end
  317.   rednet.send(default, id)
  318.   ids, msg = rednet.receive(10)
  319.   if msg ~= nil then
  320.     if cndDns ~= 1 then
  321.       cndDns = 1
  322.     end
  323.     scp(1,3)
  324.     stc(colors.black)
  325.     sbgc(colors.green)
  326.     autoDown()
  327.     Llink()
  328.   else
  329.     scp(1,3)
  330.     stc(colors.red)
  331.     sbgc(colors.green)
  332.     if cndDns == 1 then
  333.       default = dns2
  334.       cndDns = 2
  335.       connect()
  336.     elseif cndDns == 2 then
  337.       default = dns1
  338.       cndDns = 1
  339.       print("time out")
  340.     end
  341.   end
  342.   if Csha == true then
  343.     id4 = id3
  344.     id3 = id2
  345.     id2 = id
  346.   end
  347. end
  348.  
  349. function autoDown()
  350.   Fline = msg:match("--browser.download=1")
  351.   if Fline ~= nil then
  352.     if Aks == 1 then
  353.       scp(10,5)
  354.       stc(colors.black)
  355.       sbgc(colors.yellow)
  356.       print("       warning             ")
  357.       scp(10,6)
  358.       print("want to download from here?")
  359.       scp(10,7)
  360.       print("YES                     NO ")
  361.       event, bu, X, Y = os.pullEvent()
  362.       function warnDown()
  363.         if event == "mouse_click" then
  364.           if X >= 10 and X <= 12 and Y == 7 then
  365.             Rp = "1"
  366.           elseif X >= 34 and X <= 35 and Y == 7 then
  367.             Rp = "2"
  368.           else
  369.             scp(1,3)
  370.             print("reloading")
  371.             sleep(.2)
  372.             sbgc(colors.green)
  373.             scp(1,3)
  374.             print("         ")
  375.             cL()
  376.             autoDown()
  377.           end
  378.         else
  379.           sleep(.2)
  380.           autoDown()
  381.         end
  382.       end
  383.       warnDown()
  384.       if Rp == "1" then
  385.         Down()
  386.       else
  387.         scp(1,3)
  388.         sbgc(colors.green)
  389.         print(msg)
  390.         gui()
  391.         begin()
  392.       end
  393.     else
  394.       Down()
  395.     end
  396.   else
  397.     print(msg)
  398.     if anCondt == true then
  399.       anim()
  400.     end
  401.   end
  402. end
  403.        
  404. function Down()
  405.   sbgc(colors.green)
  406.   scp(10,6)
  407.   cL()
  408.   scp(10,7)
  409.   cL()
  410.   scp(10,6)
  411.   sbgc(colors.yellow)
  412.   write("Local:                     ")
  413.   scp(16,6)
  414.   Dlocal = read()
  415.   if Dlocal == nil then
  416.     Dlocal = "download"
  417.   end
  418.   e = fs.open(Dlocal, "w")
  419.   e.write(msg)
  420.   e.close()
  421.   scp(10,7)
  422.   print("download sucessful")
  423.   Rp = nil
  424. end
  425. autoConfig()
  426. click()
  427. rednet.close(side)
Advertisement
Add Comment
Please, Sign In to add comment