Simple web browser with bookmarks (iPad/iPhone/iPod touch)

User avatar
Dutchman
Posts: 853
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Simple web browser with bookmarks (iPad/iPhone/iPod touch)

Post by Dutchman » Fri Aug 26, 2016 9:02 am

Dav's browser is now an essential component in the Launcher-'package' :idea:
The included version has been extended with page loading via Clipboard.
It is used to deliver info about programs in the launcher etc.
Due to the excellent structure of the program, the changes were easy to make. :!:
Changes are marked in red.
The main loop (marked in green) has been simplified by the addition of the function 'Buttonpressed'
I hope that Dav will adopt the changes ;)

Code: Select all

'=========================================
'Simple web browser in smart BASIC - v1.08+
'=========================================
'Works on ipad, iphone, ipod touch
'Coded by Dav, December/2015
'
'A simple web browser made in smart Basic.
'Uses javascript for browsing functions.
'Has a basic bookmark manager. Only loads
'one page at a time, but I'm working on a
'multitab version right now...
'
'NEW:  Shows info bar at top: Connection
'      status, Time, Battery level.  The
'      current url now shown below menu.
'      You can select it to copy url.
'      Bookmark menu now drops down and
'      closes up out of sight (moving).
'r'
'Dutchman added conditional recall to launcher
'     and URL-transfer from launcher
''
'NOTE: Bookmarks saved in file in current
'      directory named: 'bookmarks.ini'
'      Homepage is set to GOOGLE.COM, but
'      you can change this by changing
'      the home$ variable below...

home$="http://www.google.com" '<<< change
'----- detect users device
if lowstr$(device_type$())="ipad" then
  dev=1
else
  dev=0
end if
'----- initialise
graphics
option base 1
set buttons custom
page "main" set
'----- init screen
graphics clear .4,.4,.4
set toolbar off
set browsers scaled 'allow zooming in/out
'----- get current screen width
curwidth= screen_width()
gosub drawinfobar
''
'r' ### Before loading startpage !!
''----- make buttons
draw color 0,0,0
fill color .9,.9,.9
if dev = 1 then
  set buttons font size 36
  button "back" text " "&chr$(9666)&" " at 10, 28
  button "forward" text " "&chr$(9656)&" " at 70, 28
  button "stop" text " "&chr$(9679)&" " at 130,28
  button "reload" text " "&chr$(8634)&" " at 194,28
  button "home" text " "&chr$(9751)&" " at 266,28
  button "bookmarks" text "Bookmarks..." at 344,28
  button "url" text "Url..." at 579,28
  button "quit" text "Quit" at 676,28
else
  set buttons font size 20
  button "back" text chr$(9666) at 3, 28
  button "forward" text chr$(9656) at 40, 28
  button "stop" text chr$(9679) at 78,28
  button "reload" text chr$(8634) at 113,28
  button "home" text chr$(9751) at 153,28
  button "bookmarks" text chr$(9873) at 195,28
  button "url" text chr$(9166) at 235,28
  button "quit" text "X" at 285,28
end if
'r'----- load the startpage
'  ### after buttons set !!!
IF Launch$="launcher" THEN url$=launch$.line$
IF url$="" THEN url$=home$
gosub loadpage
''
'g'----- M A I N  L O O P -----
do
  SLOWDOWN
  '------ handle buttons
  IF ButtonPressed THEN 'check AND reset all buttons at once
    if ._back then u$ = browser_text$("n", "window.history.go(-1)")
    if ._forward then u$ = browser_text$("n", "window.history.go(1)")
    if ._quit then break
    if ._home then ! url$=home$ ! gosub loadpage ! endif
    if ._url then gosub geturl
    if ._stop then u$ = browser_text$("n", "stop()")
    if ._reload then u$ = browser_text$("n", "location.reload(true)")
    if ._bookmarks then gosub bookmarks
  ENDIF 'buttonpressed
  '----- if screen rotated...
  if screen_width() <> curwidth then
    curwidth = screen_width()
    url$=browser_text$("n", "window.location.href")
    gosub loadpage
    gosub drawinfobar
  end if
  '----- update infobar and connection every 10 secs
  if time()>10 then
    refresh off
    gosub drawinfobar
    refresh on
    time reset
  end if
  '----- check current url location every other second
  'if it changes, update field to show the change
  if odd(time()) then
    title$=browser_text$("n", "window.location.href")
    ft$=field_text$("url")
    'if it's changed, show change in field
    if title$ <> ft$ then
      field "url" back color 1,1,1
      field "url" font color 0,0,0 
      if dev=1 then
        field "url" text title$ at 10,85 size screen_width()-20,24
      else
        field "url" text title$ at 5,65 size screen_width()-5,25
      end if
    end if
  end if
until 0
'r'----- Exit
Exit:
IF Launch$="launcher" THEN
  {/- Launcher.sb}
ENDIF
''
set toolbar on
page bm$ hide
page "main" hide
text

END
'===== S U B R O U T I N E S and F U N C T I O N S =============
'r'
DEF ButtonPressed
._back=button_pressed("back")
._forward=button_pressed("forward")
._stop=button_pressed("stop")
._reload=button_pressed("reload")
._home=button_pressed("home")
._bookmarks=button_pressed("bookmarks")
._url=button_pressed("url")
._quit=button_pressed("quit")
exit=._back+._forward+._stop+._reload
exit+=._home+._bookmarks+._url+._quit
RETURN exit
END DEF
''
loadpage:'-------
field "url" back color 1,1,1
field "url" font color 0,0,0 
if dev=1 then
  browser "n" url url$ at 0,110 size screen_width(),screen_height() -110 
  title$=browser_text$("n", "window.location.href")
  field "url" text title$ at 10,85 size screen_width()-20,24
else
  browser "n" url url$ at 0,95 size screen_width(),screen_height() -95
  title$=browser_text$("n", "window.location.href")
  field "url" text title$ at 5,65 size screen_width()-5,25 
end if
return
'
hidebuttons:'----------
button "back" hide
button "forward" hide
button "stop" hide
button "reload" hide
button "home" hide
button "bookmarks" hide
button "url" hide
button "quit" hide
return
'
showbuttons:'----------
button "back" show
button "forward" show
button "stop" show
button "reload" show
button "home" show
button "bookmarks" show
button "url" show
button "quit" show
return
'
geturl:'-----
gosub hidebuttons
if dev=1 then
  field "geturl" text "" at 0,0 size screen_width(), 60
else
  field "geturl" text "" at 0,0 size screen_width(), 38
end if
field "geturl" set text "http://"
field "geturl" select
if dev=1 then
  button "cancel" text "Cancel" at screen_width()-150,3
else
  button "cancel" text "Cancel" at screen_width()-80,3
end if
do
  if button_pressed("cancel") then goto skip
until field_changed("geturl") = 1
u2$ = field_text$("geturl")
if u2$ <> "" and u2$ <>"http://" then
   u2$=ltrim$(u2$)
   'make sure http:// given
   if capstr$(left$(u2$,7))<> "HTTP://" then
     u2$="http://"&u2$
   end if
   url$=u2$
   gosub loadpage
end if
skip:
button "cancel" delete
field "geturl" delete
gosub showbuttons
return
'
bookmarks:'--------
gosub loadbookmarks
sw=screen_width()
sh=screen_height()
'make bookmarks page
bm$ = "Bookmarks"
page bm$ set
page bm$ frame 0,0,sw-10,sh/2
page bm$ color .7,.7,.7,1
if dev=1 then
  page bm$ at 5,-1000 '60
else
  page bm$ at 5,-1000 '50
end if
button "bookmarks" hide
showbookmarks:
if dev=1 then
  list bm$ text list$(1) at 4,4 size sw-18,sh/2-62
else
  list bm$ text list$(1) at 4,4 size sw-18,sh/2-42
end if
list bm$ set text list$
if dev=1 then
  button "close" text "Close" at sw- 130,sh/2-57
  button "addpage" text "Add Current" at 5,sh/2-57
  button "deletepage" text "Delete page" at 225,sh/2-57
  button "deletepage" hide
  button "loadpage" text "Load page" at 442,sh/2-57
  button "loadpage" hide
else
  button "close" text "Close" at sw- 85,sh/2-36
  button "addpage" text "Add" at 5,sh/2-36
  button "deletepage" text "Delete" at 65,sh/2-36
  button "deletepage" hide
  button "loadpage" text "Load" at 145,sh/2-36
  button "loadpage" hide
end if
'only drop down menu first time
if bdown=0 then
  for yy = -500 to 100 step 4
    page bm$ at 5,yy
    pause .001
  next yy
  bdown=1 'mark as down
end if
do
  if list_selected(bm$) <> -1 and booknum > 0 then 
    button "deletepage" show
    button "loadpage" show
     
    if button_pressed("loadpage") then
      pause .2 'delay to look like a click
      url$=list$(list_selected(bm$))
      'page "main" set
      gosub showbuttons
      for yy = 100 to -550 step -4
        page bm$ at 5,yy
        pause .001
      next yy
      gosub loadpage
      goto bookdone
    end if
    if button_pressed("deletepage") then
      list$(list_selected(bm$))=""
      gosub deletebookmark
      gosub savebookmarks
      goto showbookmarks
    end if
  end if
  if button_pressed("addpage") then
     url$=browser_text$("n", "window.location.href")
     if url$<>"" then
        gosub addbookmark
        gosub savebookmarks
        goto showbookmarks
     end if 
  end if
  if screen_width() <> curwidth then
     curwidth = screen_width()
     url$=browser_text$("n", "window.location.href")
     gosub drawinfobar
     gosub loadpage
     goto bookmarks
  end if
until button_pressed("close")
'raise menu back up
for yy = 100 to -550 step -4
   page bm$ at 5,yy
   pause .001
next yy
bookdone:
page "main" set
gosub showbuttons
bdown=0
return
'
loadbookmarks:'------------
if file_exists("bookmarks.ini") =0 then
   makenew:
   'make default list of bookmarks
   booknum=5
   DIM list$(booknum)
   list$(1)="http://www.google.com"
   list$(2)="http://www.qbasicnews.com/dav/"
   list$(3)="http://www.yahoo.com"
   list$(4)="http://kibernetik.pro"
   list$(5)="http://www.bing.com"
   gosub savebookmarks
else
   file "bookmarks.ini" setpos 0
   file "bookmarks.ini" readline a$
   if a$ = "" then goto makenew
   booknum = val(a$)
   if booknum < 0 then goto makenew
   if booknum = 0 then
     dim list$(1)
   else
     dim list$(booknum)
     for p = 1 to booknum
       file "bookmarks.ini" readline a$
       'if invalid entry for some reason
       if a$ ="" then
         'last booknum was last
         bookmark = p -1
         break
       end if
       list$(p) = a$
     next p
   end if
end if
return
'
savebookmarks:'------------
'out with the old...
file "bookmarks.ini" delete
'in with the new...
if booknum = 0 then
   file "bookmarks.ini" writeline str$(0)
else
   file "bookmarks.ini" writeline str$(booknum)
   for p = 1 to booknum
     file "bookmarks.ini" writeline list$(p)
   next p
end if
return
'
deletebookmark:'-------------
if booknum > 1 then
  'temporary holder array
  dim temp$(booknum)
  bc=1
  for h=1 to booknum
    if list$(h) <>"" then
      temp$(bc)=list$(h)
      bc=bc+1
    end if
  next h
  'remake list$()
  booknum =bc -1
  dim list$(booknum)
  'copy temp$() to list$()
  for p = 1 to booknum
    list$(p)= temp$(p)
  next p
else
  booknum=0
end if
return
'
addbookmark:'----------
booknum=booknum + 1
if booknum = 1 then
  dim list$(1)
  list$(1) = url$
else
  'make temp array holder
  dim temp$(booknum)
  for p = 1 to booknum -1
      temp$(p) = list$(p)
  next p
  temp$(booknum) = url$
  'make new list$()
  dim list$(booknum)
  for p = 1 to booknum
     list$(p) = temp$(p)
  next p
end if
return
'
drawinfobar:'----------
sw=screen_width()
fill color .7,.7,.7
fill rect 0,0 to sw,25
draw color .3,.3,.3
ampm$="AM" ! hr=current_hour()
min$=str$(current_minute())
if len(min$)=1 then min$="0"&min$
if hr>12 then
  hr=hr-12 ! ampm$="PM"
end if
tm$=str$(hr)&":"&min$&" "&ampm$
draw text tm$ at ((sw/2)-text_width(tm$)/2),4
if dev=1 then
  bat$=str$(battery_level())&"%"
  draw text bat$ at sw-text_width(bat$)-80,4
end if
draw rect sw-70,5 to sw-20,19
f=battery_level()/2
fill color .3,.3,.3
fill rect sw-70,5 to sw-70+f,19
fill rect sw-20, 9 to sw-17, 14
if system_ext_ip$() ="" then
     fill color .7,.7,.7
     fill rect 0,0 to 110,25
     fill color .7,0,0
     draw color .3,.3,.3
     if dev=1 then
        draw text "OFFLINE" at 25,3
     else
        draw text "OFF" at 25,3
     end if
else 
     fill color .7,.7,.7
     fill rect 0,0 to 110,25
     fill color 0,.7,0
     draw color .3,.3,.3
     if dev=1 then
        draw text "ONLINE" at 25,3
     else
        draw text "ON" at 25,3
     end if
end if
fill circle 12,12 size 5,5
draw color 0,0,0
fill color .9,.9,.9
return
We consider it a refreshing mental exercise to figure out ways to circumvent foolishness (Quote from Richard)

User avatar
GeorgeMcGinn
Posts: 417
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro
IMac
Location: Venice, FL
Flag: United States of America
Contact:

Re: Simple web browser with bookmarks (iPad/iPhone/iPod touch)

Post by GeorgeMcGinn » Fri Sep 22, 2017 1:37 am

I found that the icons in the top bar are way too big.

So this version makes them what would be the normal size for the browser Dav designed. There is more room for other buttons to be added:

Code: Select all

'=========================================
'Simple web browser in smart BASIC - v1.08
'=========================================
'Works on ipad, iphone, ipod touch
'Coded by Dav, December/2015
'
'A simple web browser made in smart Basic.
'Uses javascript for browsing functions.
'Has a basic bookmark manager. Only loads
'one page at a time, but I'm working on a
'multitab version right now...
'
'NEW:  Shows info bar at top: Connection
'      status, Time, Battery level.  The
'      current url now shown below menu.
'      You can select it to copy url.
'      Bookmark menu now drops down and
'      closes up out of sight (moving).
'
'NOTE: Bookmarks saved in file in current
'      directory named: 'bookmarks.ini'
'      Homepage is set to GOOGLE.COM, but
'      you can change this by changing
'      the home$ variable below...

home$="http://www.google.com" '<<< change

'detect users device
IF LOWSTR$(DEVICE_TYPE$())="ipad" THEN
  dev=1
ELSE
  dev=0
END IF

GRAPHICS
OPTION BASE 1
SET BUTTONS CUSTOM

PAGE "main" SET

'init screen
GRAPHICS CLEAR .4,.4,.4
SET TOOLBAR OFF

SET BROWSERS SCALED 'allow zooming in/out

'get current screen width
curwidth= SCREEN_WIDTH()

GOSUB drawinfobar

'load the homepage
URL$=home$
GOSUB loadpage

DRAW COLOR 0,0,0
FILL COLOR .9,.9,.9

'make buttons
IF dev = 1 THEN
  SET BUTTONS FONT SIZE 18
  BUTTON "back" TEXT " "&CHR$(9666)&" " AT 10, 28
  BUTTON "forward" TEXT " "&CHR$(9656)&" " AT 70, 28
  BUTTON "stop" TEXT " "&CHR$(9679)&" " AT 130,28
  BUTTON "reload" TEXT " "&CHR$(8634)&" " AT 194,28
  BUTTON "home" TEXT " "&CHR$(9751)&" " AT 266,28
  BUTTON "bookmarks" TEXT "Bookmarks..." AT 344,28
  BUTTON "url" TEXT "Url..." AT 579,28
  BUTTON "quit" TEXT "Quit" AT 676,28
ELSE
  SET BUTTONS FONT SIZE 18
  BUTTON "back" TEXT CHR$(9666) AT 3, 28
  BUTTON "forward" TEXT CHR$(9656) AT 40, 28
  BUTTON "stop" TEXT CHR$(9679) AT 78,28
  BUTTON "reload" TEXT CHR$(8634) AT 113,28
  BUTTON "home" TEXT CHR$(9751) AT 153,28
  BUTTON "bookmarks" TEXT CHR$(9873) AT 195,28 
  BUTTON "url" TEXT CHR$(9166) AT 235,28
  BUTTON "quit" TEXT "X" AT 285,28
END IF

'main loop...
DO

  IF BUTTON_PRESSED("back") THEN
    u$ = BROWSER_TEXT$("n", "window.history.go(-1)")
  END IF

  IF BUTTON_PRESSED("forward") THEN
    u$ = BROWSER_TEXT$("n", "window.history.go(1)")
  END IF

  IF BUTTON_PRESSED("quit") THEN BREAK

  IF BUTTON_PRESSED("home") THEN 
   URL$=home$ ! GOSUB loadpage
  END IF

  IF BUTTON_PRESSED("url") THEN
   GOSUB geturl
  END IF

  IF BUTTON_PRESSED("stop") THEN
    u$ = BROWSER_TEXT$("n", "stop()")
  END IF

  IF BUTTON_PRESSED("reload") THEN
    u$ = BROWSER_TEXT$("n", "location.reload(true)")
  END IF

  IF BUTTON_PRESSED("bookmarks") THEN
    GOSUB bookmarks
  END IF

  'if screen rotated...
  IF SCREEN_WIDTH() <> curwidth THEN
    curwidth = SCREEN_WIDTH()
'*** Load URL and call get page
       URL$=BROWSER_TEXT$("n", "window.location.href")
    GOSUB loadpage
    GOSUB drawinfobar
  END IF

  'update infobar and connection every 10 secs
  IF TIME()>10 THEN
    REFRESH OFF
    GOSUB drawinfobar
    REFRESH ON
    TIME RESET
  END IF

  'check current url location every other second
  'if it changes, update field to show the change
  IF ODD(TIME()) THEN
    title$=BROWSER_TEXT$("n", "window.location.href")
    ft$=FIELD_TEXT$("url")
    'if it's changed, show change in field
    IF title$ <> ft$ THEN
      FIELD "url" BACK COLOR 1,1,1
      FIELD "url" FONT COLOR 0,0,0 
      IF dev=1 THEN
        FIELD "url" TEXT title$ AT 10,85 SIZE SCREEN_WIDTH()-20,24
      ELSE
        FIELD "url" TEXT title$ AT 5,65 SIZE SCREEN_WIDTH()-5,25
      END IF
    END IF
  END IF

UNTIL 0

SET TOOLBAR ON

PAGE bm$ HIDE
PAGE "main" HIDE
TEXT

END


'==========================================
'              G O S U B S
'==========================================

'-------
loadpage:
'-------

FIELD "url" BACK COLOR 1,1,1
FIELD "url" FONT COLOR 0,0,0 
IF dev=1 THEN
  BROWSER "n" URL URL$ AT 0,110 SIZE SCREEN_WIDTH(),SCREEN_HEIGHT() -110 
  title$=BROWSER_TEXT$("n", "window.location.href")
  FIELD "url" TEXT title$ AT 10,85 SIZE SCREEN_WIDTH()-20,24
ELSE
  BROWSER "n" URL URL$ AT 0,95 SIZE SCREEN_WIDTH(),SCREEN_HEIGHT() -95
  title$=BROWSER_TEXT$("n", "window.location.href")
  FIELD "url" TEXT title$ AT 5,65 SIZE SCREEN_WIDTH()-5,25  
END IF
RETURN


'----------
hidebuttons:
'----------

BUTTON "back" HIDE
BUTTON "forward" HIDE
BUTTON "stop" HIDE
BUTTON "reload" HIDE
BUTTON "home" HIDE
BUTTON "bookmarks" HIDE
BUTTON "url" HIDE
BUTTON "quit" HIDE
RETURN


'----------
showbuttons:
'----------

BUTTON "back" SHOW
BUTTON "forward" SHOW
BUTTON "stop" SHOW
BUTTON "reload" SHOW
BUTTON "home" SHOW
BUTTON "bookmarks" SHOW
BUTTON "url" SHOW
BUTTON "quit" SHOW
RETURN


'-----
geturl:
'-----

GOSUB hidebuttons

IF dev=1 THEN
  FIELD "geturl" TEXT "" AT 0,0 SIZE SCREEN_WIDTH(), 60
ELSE
  FIELD "geturl" TEXT "" AT 0,0 SIZE SCREEN_WIDTH(), 38
END IF

FIELD "geturl" SET TEXT "http://"
FIELD "geturl" SELECT

IF dev=1 THEN
  BUTTON "cancel" TEXT "Cancel" AT SCREEN_WIDTH()-150,3
ELSE
  BUTTON "cancel" TEXT "Cancel" AT SCREEN_WIDTH()-80,3
END IF

DO
  IF BUTTON_PRESSED("cancel") THEN GOTO skip
UNTIL FIELD_CHANGED("geturl") = 1

u2$ = FIELD_TEXT$("geturl")

IF u2$ <> "" AND u2$ <>"http://" THEN
   u2$=LTRIM$(u2$)
   'make sure http:// given
   IF CAPSTR$(LEFT$(u2$,7))<> "HTTP://" THEN
     u2$="http://"&u2$
   END IF
   URL$=u2$
   GOSUB loadpage
END IF

skip:
BUTTON "cancel" DELETE
FIELD "geturl" DELETE
GOSUB showbuttons
RETURN


'--------
bookmarks:
'--------

GOSUB loadbookmarks

sw=SCREEN_WIDTH()
sh=SCREEN_HEIGHT()

'make bookmarks page
bm$ = "Bookmarks"
PAGE bm$ SET
PAGE bm$ FRAME 0,0,sw-10,sh/2
PAGE bm$ COLOR .7,.7,.7,1
IF dev=1 THEN
  PAGE bm$ AT 5,-1000 '60
ELSE
  PAGE bm$ AT 5,-1000 '50
END IF

BUTTON "bookmarks" HIDE

showbookmarks:

IF dev=1 THEN
  LIST bm$ TEXT LIST$(1) AT 4,4 SIZE sw-18,sh/2-62
ELSE
  LIST bm$ TEXT LIST$(1) AT 4,4 SIZE sw-18,sh/2-42
END IF

LIST bm$ SET TEXT LIST$

IF dev=1 THEN
  BUTTON "close" TEXT "Close" AT sw- 130,sh/2-57
  BUTTON "addpage" TEXT "Add Current" AT 5,sh/2-57
  BUTTON "deletepage" TEXT "Delete page" AT 225,sh/2-57
  BUTTON "deletepage" HIDE
  BUTTON "loadpage" TEXT "Load page" AT 442,sh/2-57
  BUTTON "loadpage" HIDE
ELSE
  BUTTON "close" TEXT "Close" AT sw- 85,sh/2-36
  BUTTON "addpage" TEXT "Add" AT 5,sh/2-36
  BUTTON "deletepage" TEXT "Delete" AT 65,sh/2-36
  BUTTON "deletepage" HIDE
  BUTTON "loadpage" TEXT "Load" AT 145,sh/2-36
  BUTTON "loadpage" HIDE
END IF

'only drop down menu first time
IF bdown=0 THEN
  FOR yy = -500 TO 100 STEP 4
    PAGE bm$ AT 5,yy
    PAUSE .001
  NEXT yy
  bdown=1 'mark as down
END IF

DO

  IF LIST_SELECTED(bm$) <> -1 AND booknum > 0 THEN 
    BUTTON "deletepage" SHOW
    BUTTON "loadpage" SHOW
     
    IF BUTTON_PRESSED("loadpage") THEN
      PAUSE .2 'delay to look like a click
      URL$=LIST$(LIST_SELECTED(bm$))
      'page "main" set
      GOSUB showbuttons
      FOR yy = 100 TO -550 STEP -4
        PAGE bm$ AT 5,yy
        PAUSE .001
      NEXT yy
      GOSUB loadpage
      GOTO bookdone
    END IF

    IF BUTTON_PRESSED("deletepage") THEN
      LIST$(LIST_SELECTED(bm$))=""
      GOSUB deletebookmark
      GOSUB savebookmarks
      GOTO showbookmarks
    END IF

  END IF

  IF BUTTON_PRESSED("addpage") THEN
     URL$=BROWSER_TEXT$("n", "window.location.href")
     IF URL$<>"" THEN
        GOSUB addbookmark
        GOSUB savebookmarks
        GOTO showbookmarks
     END IF 
  END IF

  IF SCREEN_WIDTH() <> curwidth THEN
     curwidth = SCREEN_WIDTH()
     URL$=BROWSER_TEXT$("n", "window.location.href")
     GOSUB drawinfobar
     GOSUB loadpage
     GOTO bookmarks
  END IF

UNTIL BUTTON_PRESSED("close")

'raise menu back up
FOR yy = 100 TO -550 STEP -4
   PAGE bm$ AT 5,yy
   PAUSE .001
NEXT yy

bookdone:

PAGE "main" SET
GOSUB showbuttons
bdown=0
RETURN


'------------
loadbookmarks:
'------------

IF FILE_EXISTS("bookmarks.ini") =0 THEN
   makenew:
   'make default list of bookmarks
   booknum=5
   DIM LIST$(booknum)
   LIST$(1)="http://www.google.com"
   LIST$(2)="http://www.qbasicnews.com/dav/"
   LIST$(3)="http://www.yahoo.com"
   LIST$(4)="http://kibernetik.pro"
   LIST$(5)="http://www.bing.com"
   GOSUB savebookmarks
ELSE
   FILE "bookmarks.ini" SETPOS 0
   FILE "bookmarks.ini" READLINE a$
   IF a$ = "" THEN GOTO makenew
   booknum = VAL(a$)
   IF booknum < 0 THEN GOTO makenew
   IF booknum = 0 THEN
     DIM LIST$(1)
   ELSE
     DIM LIST$(booknum)
     FOR p = 1 TO booknum
       FILE "bookmarks.ini" READLINE a$
       'if invalid entry for some reason
       IF a$ ="" THEN
         'last booknum was last
         bookmark = p -1
         BREAK
       END IF
       LIST$(p) = a$
     NEXT p
   END IF
END IF
RETURN


'------------
savebookmarks:
'------------

'out with the old...
FILE "bookmarks.ini" DELETE

'in with the new...
IF booknum = 0 THEN
   FILE "bookmarks.ini" WRITELINE STR$(0)
ELSE
   FILE "bookmarks.ini" WRITELINE STR$(booknum)
   FOR p = 1 TO booknum
     FILE "bookmarks.ini" WRITELINE LIST$(p)
   NEXT p
END IF
RETURN


'-------------
deletebookmark:
'-------------

IF booknum > 1 THEN
  'temporary holder array
  DIM temp$(booknum)
  bc=1
  FOR h=1 TO booknum
    IF LIST$(h) <>"" THEN
      temp$(bc)=LIST$(h)
      bc=bc+1
    END IF
  NEXT h
  'remake list$()
  booknum =bc -1
  DIM LIST$(booknum)
  'copy temp$() to list$()
  FOR p = 1 TO booknum
    LIST$(p)= temp$(p)
  NEXT p
ELSE
  booknum=0
END IF
RETURN


'----------
addbookmark:
'----------

booknum=booknum + 1

IF booknum = 1 THEN
  DIM LIST$(1)
  LIST$(1) = URL$
ELSE
  'make temp array holder
  DIM temp$(booknum)
  FOR p = 1 TO booknum -1
      temp$(p) = LIST$(p)
  NEXT p
  temp$(booknum) = URL$
  'make new list$()
  DIM LIST$(booknum)
  FOR p = 1 TO booknum
     LIST$(p) = temp$(p)
  NEXT p
END IF
RETURN


'----------
drawinfobar:
'----------

sw=SCREEN_WIDTH()
FILL COLOR .7,.7,.7
FILL RECT 0,0 TO sw,25
DRAW COLOR .3,.3,.3
ampm$="AM" ! hr=CURRENT_HOUR()
MIN$=STR$(CURRENT_MINUTE())
IF LEN(MIN$)=1 THEN MIN$="0"&MIN$
IF hr>12 THEN
  hr=hr-12 ! ampm$="PM"
END IF
tm$=STR$(hr)&":"&MIN$&" "&ampm$
DRAW TEXT tm$ AT ((sw/2)-TEXT_WIDTH(tm$)/2),4
IF dev=1 THEN
  bat$=STR$(BATTERY_LEVEL())&"%"
  DRAW TEXT bat$ AT sw-TEXT_WIDTH(bat$)-80,4
END IF
DRAW RECT sw-70,5 TO sw-20,19
f=BATTERY_LEVEL()/2
FILL COLOR .3,.3,.3
FILL RECT sw-70,5 TO sw-70+f,19
FILL RECT sw-20, 9 TO sw-17, 14
IF SYSTEM_EXT_IP$() ="" THEN
     FILL COLOR .7,.7,.7
     FILL RECT 0,0 TO 110,25
     FILL COLOR .7,0,0
     DRAW COLOR .3,.3,.3
     IF dev=1 THEN
        DRAW TEXT "OFFLINE" AT 25,3
     ELSE
        DRAW TEXT "OFF" AT 25,3
     END IF
ELSE 
     FILL COLOR .7,.7,.7
     FILL RECT 0,0 TO 110,25
     FILL COLOR 0,.7,0
     DRAW COLOR .3,.3,.3
     IF dev=1 THEN
        DRAW TEXT "ONLINE" AT 25,3
     ELSE
        DRAW TEXT "ON" AT 25,3
     END IF
END IF
FILL CIRCLE 12,12 SIZE 5,5
DRAW COLOR 0,0,0
FILL COLOR .9,.9,.9
RETURN
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)
http://georgemcginn.wordpress.com
http://cosmologyandspace.wordpress.com

User avatar
Dav
Posts: 302
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: Simple web browser with bookmarks (iPad/iPhone/iPod touch)

Post by Dav » Fri Sep 22, 2017 11:43 am

Thanks, George. On the old iPad mini I developed it on they didn't look too oversized, but on my new iPad the are too big for sure. Thanks for the fix. There's room for extra things now.

- Dav.

User avatar
MarkP
Posts: 32
Joined: Tue Apr 07, 2015 9:32 pm

Re: Simple web browser with bookmarks (iPad/iPhone/iPod touch)

Post by MarkP » Wed May 16, 2018 9:13 am

I'm not sure whether this minor error in Dav's browser code was original or whether it was introduced as someone else's mod, but the time in the status bar is incorrect between noon and 1pm.

The test...

Code: Select all

IF hr>12 THEN
  hr=hr-12 ! ampm$="PM"
END IF
... should be ...

Code: Select all

IF hr>=12 THEN
  ampm$="PM"
END IF
IF hr>12 THEN
  hr=hr-12
END IF
Just a minor fix. Nice browser, and nicely organized and documented code.

User avatar
rbytes
Posts: 1794
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone X
iPad 4
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Simple web browser with bookmarks (iPad/iPhone/iPod touch)

Post by rbytes » Wed May 16, 2018 1:41 pm

Good that you reported this error, Mark. There is one other fix that is needed. In looking through my programs that use Dav's infobar (and there are a lot!), I found that I had made this correction in about half of them:

IF hr>11 THEN ampm$="PM"
IF hr>12 THEN hr=hr-12
IF hr=0 THEN hr=12

The last line is important. Otherwise, between midnight and 1 am, the time will read 0:17 AM instead of 12:17 AM
The 24 hour clock hour range is from 00 to 23, not 01 to 24.

Now I need to go back and fix this in my other programs! :o
####### Living the colorful life #######

User avatar
Dav
Posts: 302
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: Simple web browser with bookmarks (iPad/iPhone/iPod touch)

Post by Dav » Wed May 16, 2018 2:06 pm

Thanks for pointing that out, MarkP. I'll make the change.

The time bug was fixed in the original infobar post (here) but I failed to correct every program I stuck infobar into.

- Dav

User avatar
MarkP
Posts: 32
Joined: Tue Apr 07, 2015 9:32 pm

Re: Simple web browser with bookmarks (iPad/iPhone/iPod touch)

Post by MarkP » Thu May 17, 2018 1:42 am

Good point, rbytes - that last test is important. Plus, your code gets rid of those pesky unnecessary ENDIFs! Concise code rules!

User avatar
rbytes
Posts: 1794
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone X
iPad 4
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Simple web browser with bookmarks (iPad/iPhone/iPod touch)

Post by rbytes » Thu May 17, 2018 3:41 am

Thanks, Mark.

Dav, you provided a link to the original infobar code and you felt that it was correct. I checked it, and while you do have the correct test for "if hr=0", the code still needs correcting for AM-PM. PM needs to start when hr>11, not when hr>12. Otherwise, since CURRENT_HOUR() results are integers, PM will not be displayed until 1:00 PM .
####### Living the colorful life #######

User avatar
Dav
Posts: 302
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: Simple web browser with bookmarks (iPad/iPhone/iPod touch)

Post by Dav » Thu May 17, 2018 2:27 pm

You're right, rbytes. I corrected the infobar program posts using your better code posted here, and also corrected the browser code with it.

Thanks.

- Dav

Post Reply