Guest User

browser4.1

a guest
Oct 24th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.17 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.1 (*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.   sbgc(colors.green)
  227.   stc(colors.black)
  228.   scp(1,3)
  229.   anLoop = nil
  230.   anF1 = nil
  231.   anF2 = nil
  232.   anF3 = nil
  233.   anF4 = nil
  234.   anF5 = nil
  235.   if msg:match("--browser.anim=1") ~= nil then
  236.     temp = fs.open("temp", "w")
  237.     temp.write(msg)
  238.     temp.close()
  239.     shell.run("temp")
  240.     --print(anF1, anF2, anF3, anF4, anF5)
  241.     function Aanim()
  242.       if anMax == 2 then
  243.         id = anF1
  244.         Rconnect()
  245.         s(2)
  246.         id = anF2
  247.         Rconnect()
  248.         s(2)
  249.       elseif anMax == 3 then
  250.         id = anF1
  251.         Rconnect()
  252.         s(2)
  253.         id = anF2
  254.         Rconnect()
  255.         s(2)
  256.         id = anF3
  257.         Rconnect()
  258.         s(2)
  259.       elseif anMax == 4 then
  260.         id = anF1
  261.         Rconnect()
  262.         s(2)
  263.         id = anF2
  264.         Rconnect()
  265.         s(2)
  266.         id = anF3
  267.         Rconnect()
  268.         s(2)
  269.         id = anF4
  270.         Rconnect()
  271.         s(2)
  272.       elseif anMax == 5 then
  273.         id = anF1
  274.         Rconnect()
  275.         s(2)
  276.         id = anF2
  277.         Rconnect()
  278.         s(2)
  279.         id = anF3
  280.         Rconnect()
  281.         s(2)
  282.         id = anF4
  283.         Rconnect()
  284.         s(2)
  285.         id = anF5
  286.         Rconnect()
  287.         s(2)
  288.       end
  289.       begin()
  290.          
  291.     end
  292.     Aanim()
  293.   end
  294.   if anLoop == "true" then
  295.     s(.2)
  296.     Aanim()
  297.   end
  298.   fs.delete("temp")
  299.   anCondt = true
  300. end
  301. function setFav()
  302.   scp(44,3)
  303.   sbgc(colors.yellow)
  304.   print("Fav:")
  305.   scp(44,4)
  306.   print("          ")
  307.   scp(44,4)
  308.   Hfav = read()
  309.   if Hfav ~= nil then
  310.     e = fs.open("brconfig", "a")
  311.     e.writeLine('fav = "'..Hfav..'"')
  312.     e.close()
  313.     autoConfig()
  314.   end
  315. end
  316. function goFav()
  317.   id = fav
  318.   connect()
  319. end
  320. function setHome()
  321.   scp(44,3)
  322.   sbgc(colors.yellow)
  323.   print("home:")
  324.   scp(44,4)
  325.   print("          ")
  326.   scp(44,4)
  327.   Hhome = read()
  328.   if Hhome ~= nil then
  329.     e = fs.open("brconfig", "a")
  330.     e.writeLine('home = "'..Hhome..'"')
  331.     e.close()
  332.     autoConfig()
  333.   end
  334. end
  335. function goHome()
  336.   id = home
  337.   connect()
  338. end
  339. function refresh()
  340.   gui()
  341.   begin()
  342.   connect()
  343. end
  344. function comeBack()
  345.   gui()
  346.   begin()
  347.   if id == id2 and id3 ~= nil then
  348.     id = id3
  349.   elseif id == id3 and id4 ~= nil then
  350.     id = id4
  351.   end
  352.   if Csha == true then
  353.     Csha = false
  354.   end
  355.   s(.2)
  356.   connect()
  357. end
  358. function comeOn()
  359.   gui()
  360.   begin()
  361.   if id4 ~= nil and id == id4 and id3 ~= nil then
  362.     id = id3
  363.   elseif id3 ~= nil and id == id3 and id2 ~= nil then
  364.     id = id2
  365.   end
  366.   if Csha == true then
  367.     Csha = false
  368.   end
  369.   s(.2)
  370.   connect()
  371. end
  372. function connect()
  373.   if lPp ~= true then
  374.     actL = false
  375.   end
  376.   rednet.send(default, id)
  377.   ids, msg = rednet.receive(10)
  378.   if msg ~= nil then
  379.     if cndDns ~= 1 then
  380.       cndDns = 1
  381.     end
  382.     scp(1,3)
  383.     stc(colors.black)
  384.     sbgc(colors.green)
  385.     autoDown()
  386.     Llink()
  387.   else
  388.     scp(1,3)
  389.     stc(colors.red)
  390.     sbgc(colors.green)
  391.     if cndDns == 1 then
  392.       default = dns2
  393.       cndDns = 2
  394.       connect()
  395.     elseif cndDns == 2 then
  396.       default = dns1
  397.       cndDns = 1
  398.       print("time out")
  399.     end
  400.   end
  401.   if Csha == true then
  402.     id4 = id3
  403.     id3 = id2
  404.     id2 = id
  405.   end
  406. end
  407.  
  408. function autoDown()
  409.   Fline = msg:match("--browser.download=1")
  410.   if Fline ~= nil then
  411.     if Aks == 1 then
  412.       scp(10,5)
  413.       stc(colors.black)
  414.       sbgc(colors.yellow)
  415.       print("       warning             ")
  416.       scp(10,6)
  417.       print("want to download from here?")
  418.       scp(10,7)
  419.       print("YES                     NO ")
  420.       event, bu, X, Y = os.pullEvent()
  421.       function warnDown()
  422.         if event == "mouse_click" then
  423.           if X >= 10 and X <= 12 and Y == 7 then
  424.             Rp = "1"
  425.           elseif X >= 34 and X <= 35 and Y == 7 then
  426.             Rp = "2"
  427.           else
  428.             scp(1,3)
  429.             print("reloading")
  430.             sleep(.2)
  431.             sbgc(colors.green)
  432.             scp(1,3)
  433.             print("         ")
  434.             cL()
  435.             autoDown()
  436.           end
  437.         else
  438.           sleep(.2)
  439.           autoDown()
  440.         end
  441.       end
  442.       warnDown()
  443.       if Rp == "1" then
  444.         Down()
  445.       else
  446.         scp(1,3)
  447.         sbgc(colors.green)
  448.         print(msg)
  449.         gui()
  450.         begin()
  451.       end
  452.     else
  453.       Down()
  454.     end
  455.   else
  456.     print(msg)
  457.     if anCondt == true then
  458.       anim()
  459.     end
  460.   end
  461. end
  462.        
  463. function Down()
  464.   sbgc(colors.green)
  465.   scp(10,6)
  466.   cL()
  467.   scp(10,7)
  468.   cL()
  469.   scp(10,6)
  470.   sbgc(colors.yellow)
  471.   write("Local:                     ")
  472.   scp(16,6)
  473.   Dlocal = read()
  474.   if Dlocal == nil then
  475.     Dlocal = "download"
  476.   end
  477.   e = fs.open(Dlocal, "w")
  478.   e.write(msg)
  479.   e.close()
  480.   scp(10,7)
  481.   print("download sucessful")
  482.   Rp = nil
  483. end
  484. autoConfig()
  485. click()
  486. rednet.close(side)
Advertisement
Add Comment
Please, Sign In to add comment