HTML Viewer

By ^Neptune on Sep 25, 2008

Image

First off, thanks to Lindrian for helping me with the html.search alias. $didwm and $didreg on their own were being kinda gay, but whatever.


            NOTICE

This script is probably useless for a lot of people, but it can come in great use when someone is say, making a socket script. If you have no use for this, please don't post stating so.

Put this in your remotes and type /html.

This is the HTML Viewer I made, seeing as I've learned sockets now, I decided to make something around HTML itself. Pretty original idea, that's what I wanted, and I don't think I've seen one of these before.

What this does is view the HTML of the site that you put into the dialog. I can see a hell of a load of posts coming my way on "how do I use this?", so let me clarify.

Steps:
1) Get a website you want to use (obviously).
2) In the HOST edit box, put the host. So whatever site you are using, this is the main bit. For example, if I were to search anywhere in hawkee, the host would be: www.hawkee.com. Basically, put whatever is in your internet browser before any subdirectories of the site, excluding the http://
3) Choose the socket name. Not that this really matters.
4) Input the directory. Example: if I was viewing http://www.hawkee.com/profile/img/2158/, I would put /profile/img/2158/ as the directory.
5) Choose your port. If you're using this script you should know what you're doing. If you don't by any chance, use 80, as it's usually the best.
6) Choose your HTTP protocol. Not much difference between them really.
7) Press OK.

Woo! Now you've loaded some HTML into the viewer. Obviously, you're gonna want to be able to have edit options to ease your use.

Features:
;Search
A really good option. If you need to find some text, use this! You can also search with regex, which is a neat option too.

;HTMLFREE
This strips what's in the list of its HTML.

;Clear
Um.. no explanation needed. :/

;Del Numbers
This deletes any added numbers (see Add Numbers).

;Add Numbers
This adds line numbers to the HTML so you can easily find what you're looking for.

;Clipboard
Copies the selected line to your clipboard for pasting.

Suggestions and feedback would be much appreciated. Enjoy!

alias html { dialog $iif($dialog(html),-v,-m) html html }
dialog html {
  title "HTML Viewer"
  size -1 -1 315 309
  option dbu
  edit "", 1, 30 2 230 10, autohs center
  list 3, 2 69 311 225, hsbar vsbar size
  button "HTMLFREE", 4, 133 295 32 12
  button "Clear", 5, 166 295 32 12
  button "Add numbers", 6, 239 295 37 12
  button "Clipboard", 7, 277 295 35 12
  text "Host:", 2, 2 3 17 8
  edit "", 8, 30 26 230 10, autohs center
  text "Directory:", 9, 2 27 25 8
  edit "", 10, 30 38 35 10, autohs center
  text "Port:", 11, 2 39 17 8
  text "HTTP:", 12, 2 51 20 8
  combo 13, 30 50 50 35, drop
  box "", 14, 0 64 320 1
  button "OK", 15, 280 51 32 12
  edit "", 16, 30 14 35 10, autohs center
  text "Name:", 17, 2 15 17 8
  button "Search", 18, 100 295 32 12
  button "Del Numbers", 19, 199 295 39 12
}
on *:dialog:html:init:0: {
  did -a $dname 13 $str($chr(160) $+,10) 1.0
  did -a $dname 13 $str($chr(160) $+,10) 1.1
  did -c $dname 13 1
  did -a $dname 10 80
  did -a $dname 16 socket $+ $rand(1,1000)
}
on *:dialog:html:sclick:*: {
  if ($did == 15) {
    set %sockhtml $did(1).text
    set %socksock $did(16).text
    set %sockport $did(10).text
    sockopen %socksock %sockhtml %sockport
    sockmark %socksock $did(1).text $did(8).text
    set %sockhttp HTTP/ $+ $iif($did(13),$v1,1.1)
  }
  if ($did == 4) {
    if (!$did(3).lines) { 
      noop $input(There is no text to strip HTML from!,uwo,Error!) 
    }
    else {
      var %c = 1
      while (%c <= $did(3).lines) {
        did -o $dname 3 %c $htmlfree($did($dname,3,%c))
        inc %c
      }
    }
  }
  if ($did == 5) {
    if (!$did(3).lines) {
      noop $input(There is nothing to clear!,uwo,Error!) 
    }
    else {
      did -rz $dname 3
      unset %sockvar %sockhtml %socksock %sockhttp %sockport 
    }
  }
  if ($did == 6) {
    if (!$did(3).lines) {
      noop $input(There is no HTML to add numbers to!,uwo,Error!)
    }
    else {
      var %n = 1
      while (%n <= $did(3).lines) {
        did -o $dname 3 %n %n $+ . $did($dname,3,%n)
        inc %n
      }
    }
  }
  if ($did == 7) { 
    if (!$did(3).sel) {
      noop $input(You have not selected anything to copy!,uwo,Error!)
    }
    else {
      clipboard $did(3).seltext 
    }
  }
  if ($did == 18) { 
    noop $iif($did(3).lines,$dialog(htmlsearch,htmlsearch,-4),$input(There is nothing to search for!,uwo,Error!))
  }
  if ($did == 19) {
    if (!$did(3).lines) {
      noop $input(There is no HTML to delete numbers from!,uwo,Error!)
    }
    else {
      var %v = 1
      while (%v <= $did(3).lines) {
        var %remnum = $did(3,%v).text
        if ($gettok(%remnum,1,46) isnum) {
          did -o $dname 3 %v $remove(%remnum,$gettok(%remnum,1,32))
        }
        inc %v
      }
    }
  }
}
alias htmlfree { return $regsubex($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)|&[^;]+;|       /g,$null) }
on *:SOCKOPEN:%socksock: {
  if ($sockerr) {
    noop $input(An error occurred while opening the socket.,uwo,Error!)
    unset %sockvar %sockhtml %socksock %sockhttp %sockport    
  }
  else {
    sockwrite -nt $sockname GET $iif($gettok($sock($sockname).mark,2,32),$v1,/) %sockhttp
    sockwrite -nt $sockname Host: $gettok($sock($sockname).mark,1,32)
    sockwrite -nt $sockname $crlf
  }
}
on *:SOCKREAD:%socksock: {
  if ($sockerr) {
    noop $input(An error occurred while reading data from the socket.,uwo,Error!) 
    unset %sockvar %sockhtml %socksock %sockhttp %sockport 
  }
  else {
    var %sockvar
    sockread -f %sockvar
    if ($dialog(html)) {
      did -a html 3 $replace(%sockvar,$chr(32),$chr(160))
      .timerhtml -m 1 200 did -z html 3
    }
  }
}
dialog htmlsearch {
  title "Search HTML"
  size -1 -1 162 38
  option dbu
  radio "Match text:", 1, 2 3 42 8
  radio "Match regex:", 2, 2 13 45 9
  edit "", 3, 50 2 110 10, autohs
  edit "", 4, 50 13 110 10, autohs
  button "Find next", 5, 95 24 32 12
  button "Cancel", 6, 128 24 32 12, cancel
}
on *:dialog:htmlsearch:edit:*: {
  if ($did == 3) {
    if ($did(1).state == 1) {
      if (!$did(3).text) { 
        did -b $dname 5 
      }
      else {
        did -e $dname 5
      }
    }
  }
  if ($did == 4) {
    if ($did(2).state == 1) {
      if (!$did(4).text) {
        did -b $dname 5
      }
      else {
        did -e $dname 5
      }
    }
  }
}
on *:dialog:htmlsearch:init:0: {
  did -b $dname 4,5
  did -c $dname 1
}
on *:dialog:htmlsearch:close:*: { unset %html.search }
on *:dialog:htmlsearch:sclick:*: {
  if ($did == 2) {
    did -e $dname 4
    did -b $dname 3
  }
  if ($did == 1) {
    did -e $dname 3
    did -b $dname 4 
  }
  if ($did == 5) { 
    if ($did(1).state == 1) {
      html.search $did(3).text
    }
    elseif ($did(2).state == 1) {
      html.search -r $did(4).text
    }
  }
}
alias html.search {
  if (-r == $1) { var %a $didreg(html,3,$2,$iif(%html.search,$v1,1)) }
  else { var %a $didwm(html,3,$iif(-w = $1,$2,$1),$iif(%html.search,$v1,1)) }
  if (%a) { did -c html 3 %a }
  else { 
    did -c html 3 1 
    noop $input(End of HTML. No other matches have been found.,uwo,Find text)
  }
  %html.search = %a + 1
}

Comments

Sign in to comment.
Zmodem   -  Mar 18, 2009

Yea, the main concern should be to change the source output edit box to a 'rich' type editbox, that way the indentations will be left alone.

 Respond  
PATX   -  Mar 14, 2009

all right lets see where to begain....

  1. for those of you who have problem with html being in upper case. sorry it does not matter html can be in both cases and still be valid code with w3c validator

  2. As for the purpose of the script i love. I am a html code for Freecode Team so i very much like this. because i have those times when i am chatting with the rest of freecode and going back and forth to our dev site looking at the source. good job!

  3. sorry neptune but indented html is very messy. i think u should have left it the way the page is coded. but thats just me so not taking any rating points off for tht :p

  4. the mirc code itself it nice. think it could go into a .mrc file but this works too.

  5. ur score is 7
 Respond  
Zmodem   -  Jan 30, 2009

Change the box from a listbox to a rich edit box. That way, all of the emphasis on the spaces will be saved, ie: indentations.

 Respond  
^Neptune   -  Sep 29, 2008

Sorry about parsing the address in one line, I just really haven't gotten around to do it. Although, the HTML now has spaces and isn't bunched up to the left. Not gonna bother with updating the pic.. you should know what indented HTML looks like :>

 Respond  
Eugenio   -  Sep 26, 2008

/me agrees with Napa

 Respond  
Hawkee   -  Sep 26, 2008

Just about all of them are on port 80. The only time you'll see a different port is on a secure connection like cpanel or webmail.

 Respond  
^Neptune   -  Sep 26, 2008

Hmm, OK. I'll work on that after school.

By the way, are ALL website ports 80?

 Respond  
napalm`   -  Sep 25, 2008

What ever happened to good ole /echo -s r: %read

 Respond  
napa182   -  Sep 25, 2008

thats one fugly dialog =/

 Respond  
Paul_1337noob   -  Sep 25, 2008

well ill use this,
excellent work neptune,
very handy

 Respond  
Hawkee   -  Sep 25, 2008

You do the port like this: http://www.hawkee.com:80/snippets/ but the default should just be 80 if it's not in the URL.

 Respond  
guest598594   -  Sep 25, 2008
Although you can't pull a port to use. 

I guess you could do "http://www.somesite.com/something.html:80". But it'd probably be better to just leave the port field.

 Respond  
Eugenio   -  Sep 25, 2008

if its of no use.....
/me rates 3
^_^

and no I havnt actually rated yet ;@
/me tests

 Respond  
^Neptune   -  Sep 25, 2008

I think I'll do that.

Although you can't pull a port to use.

 Respond  
Hawkee   -  Sep 25, 2008

You should just have a single field for the domain, directory and port. Just parse the URL and pull apart the values yourself. It's much easier for somebody to paste a URL than break it apart themselves.

 Respond  
guest598594   -  Sep 25, 2008
      if (!$did(4).text) {
        did -b $dname 5
      }
      else {
        did -e $dname 5
      }

I'd use $iif there

did $iif($did(4).text,-e,-b) $dname 5
 Respond  
^Neptune   -  Sep 25, 2008

The thing I can't stand is when people rate out of jealously. :<

If this script is of no use to you, please don't rate.

 Respond  
Jonesy44   -  Sep 25, 2008

I voted 7 mate.. i'll probably boost it to 10 to increase. i hate people who rate w/o explination. :|

 Respond  
^Neptune   -  Sep 25, 2008

Er, what's with the suddenly-gone-quite-low rating?

Can people actually explain themselves?

 Respond  
Jonesy44   -  Sep 25, 2008

Oh my bad :P other way round xDxD. I take it back, sorry.

 Respond  
vaseline28   -  Sep 25, 2008

jonesy: http://www.w3schools.com/xhtml/xhtml_html.asp

XHTML elements must be in lowercase

 Respond  
^Neptune   -  Sep 25, 2008

Er, never used anything like it before, so how could I retrieve the IP/DNS of the currently socketing site? I could add it in as a 'lil extra feature.

 Respond  
Jonesy44   -  Sep 25, 2008

Nice one Nips. :]

 Respond  
vaseline28   -  Sep 25, 2008

Excellent :)

 Respond  
^Neptune   -  Sep 25, 2008

Just updated the screenshot to the exact same page we're on right now. You can see that it's now in lowercase.

 Respond  
Jonesy44   -  Sep 25, 2008

XHTML is all uppercase..
I perfer to use lowercase tbf. But anyways, nice one Nips

7/10

Just fyi; port 80 is the http port. others like 8080 is generally a streaming port. but im not that good on servers/ports so dont ask me for more info :P

 Respond  
^Neptune   -  Sep 25, 2008

Woops! Yeah, I just noticed that the screenshot I took was of an error because that site uses a script that won't let me access the true HTML. Sorry about that, I'll get another screenshot.

Also, about the caps thing. Other sites DO show in lowercase, as far as I've tested.

 Respond  
vaseline28   -  Sep 25, 2008

A note to add (just from looking at the image), HTML should be coded with lowercase tags. i.e.

rather than
 Respond  
Lindrian   -  Sep 25, 2008

When I get around to it, i'll help you improve it! :P
I still have a bunch of ideas and even more improvements in mind now!

You know where to find me bud ;)

 Respond  
^Neptune   -  Sep 25, 2008

Update: 25/9/08

Added socket error checking and added loads of $input. Also made the search function disable and enable the buttons according to text.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.