IllogicTC commented on a Page, Hawkee Snippet Search 3.0  -  Mar 19, 2011
;Hawkee Snippet Grabber by _Dean_

on *:sockopen:sps:{ 
  if ($sockerr) { $iif($dialog(hcode), did -ra hcode 16 ERROR: $sock($sockname).wsmsg) }
  else {
    var %x = sockwrite -nt $sockname
    %x GET /snippets/search/ $+ %src $+ / HTTP/1.1
    %x HOST: www.hawkee.com
    %x
  }
}

on *:sockread:sps:{
  if ($sockerr) { $iif($dialog(hcode), did -ra hcode 16 ERROR: $sock($sockname).wsmsg)  }
  else {
    var %x 
    sockread %x
    if $regex(%x,/<a href='\/snippet\/(\d+)\/' class='large'>(.+)<\/a><br>/) { 
      $iif($dialog(hcode), did -za hcode 5 http://www.hawkee.com/snippet/ $+ $regml(1) $+ / - $regml(2)) | inc %Results 1
    }
    if (*We couldn't* iswm %x) {
      $iif($dialog(hcode),did -za hcode 5 $gettok(%x,1,46)) | did -ar hcode 16 Done | did -ar hcode 9 Results found: 0 | did -r hcode 13 | tags | sockclose $sockname
    }
    if (</html> isin %x) { 
      sockclose $sockname | did -ar hcode 16 Done | did -ar hcode 9 Results found: %Results | unset %Results
    }
  }
}

on *:sockopen:spslatest:{
  if ($sockerr) { did -ar hcode 16 ERROR: $sock(spslatest).wsmsg }
  else {
    var %x = sockwrite -nt $sockname
    %x GET /mirc/snippets/ HTTP/1.1
    %x HOST: www.hawkee.com
    %x
  }
}

on *:sockread:spslatest:{
  if ($sockerr) { did -ar hcode 16 ERROR: $sock(spslatest).wsmsg }
  else {
    var %x
    sockread %x
    if $regex(%x,/<a href='\/snippet\/(\d+)\/' class='large'>(.+)<\/a><br>/) {
      $iif($dialog(hcode), did -za hcode 5 http://www.hawkee.com/snippet/ $+ $regml(1) $+ / - $regml(2)) | inc %Results 1
    }
    if (*We couldn't* iswm %x) {
      $iif($dialog(hcode),did -za hcode 5 $gettok(%x,1,46)) | did -ar hcode 16 Done | did -ar hcode 9 Results found: 0 | did -r hcode 13 | sockclose $sockname
    }
    if (</html> isin %x) {
      sockclose $sockname | did -ar hcode 16 Done | did -ar hcode 9 Results found: %Results | unset %Results
    }
  }
}

on *:sockopen:spsprevious:{
  if ($sockerr) { did -ar hcode 16 ERROR: $sock(spsprevious).wsmsg }
  else {
    var %x = sockwrite -nt $sockname
    %x GET /mirc/snippets/?&orderby=Date&p= $+ %hcode_latest HTTP/1.1
    %x HOST: www.hawkee.com
    %x
  }
}

on *:sockread:spsprevious:{
  if ($sockerr) { did -ar hcode 16 ERROR: $sock(spsprevious).wsmsg }
  else {
    var %x
    sockread %x
    if $regex(%x,/<a href='\/snippet\/(\d+)\/' class='large'>(.+)<\/a><br>/) {
      $iif($dialog(hcode), did -za hcode 5 http://www.hawkee.com/snippet/ $+ $regml(1) $+ / - $regml(2)) | inc %Results 1
    }
    if (*We couldn't* iswm %x) {
      $iif($dialog(hcode),did -za hcode 5 $gettok(%x,1,46)) | did -ar hcode 16 Done | did -ar hcode 9 Results found: 0 | did -r hcode 13 | sockclose $sockname
    }
    if (</html> isin %x) {
      sockclose $sockname | did -ar hcode 16 Done | did -ar hcode 9 Results found: %Results | unset %Results
    }
  }
}

on *:sockopen:xa:{ 
  if ($sockerr) { $iif($dialog(hcode), did -ra hcode 16 ERROR: $sock($sockname).wsmsg) }
  else {
    var %x = sockwrite -nt $sockname
    %x GET /snippet/ $+ %y $+ / HTTP/1.1
    %x HOST: www.hawkee.com
    %x
  }
}

on *:sockread:xa:{
  if ($sockerr) { $iif($dialog(hcode), did -ra hcode 16 ERROR: $sock($sockname).wsmsg) }
  else {
    var %x 
    sockread %x
    if $regex(%x,/<span class="\w+">/i) {
      did -az hcode 8 $html_tags($char_r($regsubex(%x,/<[^>]+>|\t/g,))) $crlf
    }
    if (*&quot;* iswm %x) && (!$regex(%x,/(?:<br\s\/>|</br>)/)) {
      did -az hcode 8 $html_tags($char_r($regsubex(%x,/<[^>]+>|\t/g,))) $crlf
    }
    if $regex(%x,/<td align=left><b>([a-z]{3}\s[0-9]{2}\54\s[0-9]{4})<\/b><\/td>/i) {
      did -a hcode 12 Posted on: $regml(1)
    }
    if $regex(%x,/<td align=left width=290 style="font-size: 14px"><b>(.+)<\/b> <span style="font-size: 12px;">(.+)<\/span><\/td>/) {
      did -a hcode 15 Score: $regml(1) $regml(2)
    }
    if $regex(%x,/<a href='\/snippets\/user\/\d+\/'>(.+)'s\sSnippets<\/a> >/) {
      did -a hcode 11 Author: $regml(1)
    }
    if $regex(%x,/<a href='\/snippets\/cat\/mirc\/tags\/(.+)\/'>/g) {
      set -u3 %tags %tags $+ $chr(32) $regml(1)
      did -a hcode 14 Tags: $regsubex(%tags,/<[^]+>|\t/g,)
    }
    if $regex(%x,/<span class\='like_link'><b>(\d+)<\/b>\s.*<\/span><br>/) {
      did -ar hcode 26 Like(s): $regml(1)
    }
    if (</form><br> isin %x) {
      sockclose $sockname | did -v hcode 7,17 | did -ar hcode 16 Done | did -ar hcode 13 Script link
    }
  }
}

alias char_r {
  var %x = $regsubex($1-,/\46\43(\d+)\73/g,$chr(\1))
  return %x
}

alias html_tags {
  var %x = $replace($1-,&lt;,<,&gt;,>,&amp;,&,&quot;,",&nbsp;,$chr(160))
  return %x
}

dialog hcode {
  title "Hawkee Snippet Search 3.0"
  size -1 -1 235 306
  option dbu
  edit "", 1, 9 16 50 10, autohs
  text "Seach for:", 2, 9 7 26 8
  button "Search", 3, 62 15 32 12, default
  box "Search Results", 4, 5 30 226 82
  list 5, 9 38 217 69, size hsbar vsbar
  box "Code", 6, 6 122 227 163
  button "Select code", 7, 11 132 53 12
  edit "", 8, 9 145 219 136, read multi hsbar vsbar
  text "", 9, 168 114 63 8
  text "Snippet Info:", 10, 6 286 40 8
  text "", 11, 6 296 68 8
  text "", 12, 79 286 64 8
  link "", 13, 148 295 34 8
  text "", 14, 148 286 83 8
  text "", 15, 79 296 64 8
  text "", 16, 22 113 114 8
  button "Load Code", 17, 136 132 37 12
  button "Save to Favorites", 18, 109 2 50 10
  button "Open Favorites", 19, 109 22 50 10
  button "Close Favorites", 20, 109 12 50 10
  text "Here you can save your favorites scripts links", 21, 243 27 111 9
  box "Favorites", 22, 242 37 114 161
  list 23, 246 45 105 129, size hsbar vsbar
  button "Del", 24, 311 177 37 12
  button "Add manually", 25, 263 177 37 12
  text "", 26, 192 295 39 8
  box "Comments", 27, 242 200 115 101
  edit "", 28, 244 208 108 90, read multi hsbar vsbar
  button "Check Latest", 99, 179 3 50 12
  button "<<", 100, 179 19 12 12, disable
  button ">>", 101, 217 18 12 12, disable
}

menu channel {
  .Hawkee Snippet Search: dialog $iif($dialog(hcode), -v, -m hcode) hcode
}
on *:dialog:hcode:init:*:{
  did -h hcode 7,17,18,20,24
  $iif(!$exists(favorites.txt), write favorites.txt, loadbuf -o hcode 23 favorites.txt)
  $iif($exists(favorites.txt), did -z hcode 23)
}

on *:dialog:hcode:sclick:*:{
  if ($did == 3) && ($did(1) != $null) {
    $iif($sock(sps), sockclose sps)
    $iif($sock(tags), sockclose tags)
    $iif($sock(xa), sockclose xa)
    sockopen sps www.hawkee.com 80 
    set -u3 %src $replace($did(1).text,$chr(32),+)
    did -r hcode 5,8,9,11,12,13,14,15,16,26,28
    did -a hcode 16 Getting list...
    unset %Tags
  }
  if ($did == 5) {
    clipboard $did(5).seltext
    did -v hcode 18
  }
  if ($did == 7) {
    did -ar hcode 16 Code selected
    var %x 1,%y
    while ($did(hcode, 8, %x).text) { 
      %y = %y $+ $did(hcode, 8, %x).text $crlf
      inc %x 
    }
    clipboard %y
  }
  if ($did == 13) {
    url www.hawkee.com/snippet/ $+ $iif($did(5).seltext,$gettok($did(5).seltext,4,47),$gettok($did(23).seltext,4,47)) $+ /
  }
  if ($did == 17) {
    var %x 1,%z = $replace($gettok($did(5).seltext,2,45),$chr(32),$chr(95)) $+ .mrc
    while ($did(hcode, 8, %x).text) { 
      write %z $did(hcode, 8, %x).text
      inc %x 
    }
    load -rs %z
  }
  if ($did == 18) && ($did(5).seltext) && (!$read(favorites.txt,w,* $+ $did(5).seltext $+ *)) { 
    write favorites.txt $did(5).seltext
    loadbuf -ro hcode 23 favorites.txt
  }
  if ($did == 19) { dialog -rs hcode -1 -1 724 612 | did -h hcode 19 | did -v hcode 20 }
  if ($did == 20) { dialog -rs hcode -1 -1 476 612 | did -h hcode 20 | did -v hcode 19 }
  if ($did == 23) && ($did(23).seltext) { did -v hcode 24 | clipboard $did(23).seltext }
  if ($did == 24) {
    write -dw $+ $qt($did(23).seltext) favorites.txt 
    loadbuf -ro hcode 23 favorites.txt
  }
  if ($did == 25) {
    var %favorites = $input(Here you can add your favorites manually,ey,Add links manually)
    if $regex(%favorites,/http:\/\/www\.hawkee\.com\/snippet\/\d+\//) {
      favorites %favorites
    }
    else { noop $input(You need to put a correct link,w,Warning) | halt }
  }
  if ($did == 99) {
    $iif($sock(spslatest), sockclose spslatest)
    sockopen spslatest www.hawkee.com 80
    did -r hcode 5,8,9,11,12,14,15,16
    did -a hcode 16 Getting latest snippets...
    did -e hcode 101
    set %hcode_latest 0
  }
  if ($did == 100) {
    dec %hcode_latest
    if (%hcode_latest > 0) {
      $iif($sock(spsprevious), sockclose spsprevious)
      sockopen spsprevious www.hawkee.com 80
    }
    else {
      did -b hcode 100
      $iif($sock(spslatest), sockclose spslatest)
      sockopen spslatest www.hawkee.com 80
    }
    did -r hcode 5,8,9,11,12,14,15,16
    did -a hcode 16 Getting next 25 snippets...
  }
  if ($did == 101) {
    inc %hcode_latest
    did -e hcode 100
    $iif($sock(spsprevious), sockclose spsprevious)
    sockopen spsprevious www.hawkee.com 80
    did -r hcode 5,8,9,11,12,14,15,16
    did -a hcode 16 Getting previous 25 snippets...
  }
}
on *:dialog:hcode:dclick:*:{
  if ($did == 5) {
    if (*We couldn't* iswm $did(5).seltext) || (*Tags* iswm $did(5).seltext) { halt }
    else {
      $iif($sock(xa), sockclose xa) 
      sockopen xa www.hawkee.com 80 
      set -u3 %y $gettok($did(5).seltext,4,47)
      $iif($sock(cds),sockclose $v1,sockopen cds www.hawkee.com 80)
      did -r hcode 8,11,12,14,15,16,28
      did -z hcode 28
      did -a hcode 16 Getting code...
    }
  }
  if ($did == 23) && ($did(23).seltext) {
    $iif($sock(xa), sockclose xa) 
    sockopen xa www.hawkee.com 80 
    set -u3 %y $gettok($did(23).seltext,4,47)
    $iif($sock(cds),sockclose $v1,sockopen cds www.hawkee.com 80)
    did -r hcode 8,11,12,14,15,16,28
    did -z hcode 28
    did -a hcode 16 Getting code...
  }
}

on *:load:{
  if ($version < 6.35) {
    echo -a Some functions of this script will only work on 6.35+
  }
}

on *:dialog:hcode:close:*:{
  $iif($sock(sps), sockclose sps)
  $iif($sock(xa), sockclose xa)
  $iif($sock(favorites), sockclose favorites)
  $iif($sock(tags), sockclose tags)
  unset %Tags
}

alias tags {
  $iif($sock(tags), sockclose tags)
  sockopen tags www.hawkee.com 80
}

on *:sockopen:tags:{
  if ($sockerr) { $iif($dialog(hcode), did -ra hcode 16 ERROR: $sock($sockname).wsmsg) }
  else {
    var %x = sockwrite -n $sockname
    %x GET /snippets/tags HTTP/1.1
    %x HOST: www.hawkee.com
    %x
  }
}

on *:sockread:tags:{
  if ($sockerr) { $iif($dialog(hcode), did -ra hcode 16 ERROR: $sock($sockname).wsmsg) }
  else {
    var %x
    sockread %x
    if $regex(%x,/<a href='\/snippets\/cat\/mirc\/tags\/\w+\/'>(.+)<\/a>/ig) {
      set %tags %tags $chr(32) $regml(1) | inc %htags 1 
    }
    if (%htags == 20) { sockclose $sockname | $iif($dialog(hcode), did -za hcode 5 Avaliable Tags: %tags) | unset %htags }
  }
}

alias favorites {
  $iif($sock(favorites), sockclose favorites)
  sockopen favorites www.hawkee.com 80
  set -u5 %favorites $$1
}

on *:sockopen:favorites:{
  if ($sockerr) { $iif($dialog(hcode), did -ra hcode 16 ERROR: $sock($sockname).wsmsg) }
  else {
    var %x = sockwrite -n $sockname
    %x GET /snippet/ $+ $gettok(%favorites,4,47) $+ / HTTP/1.1
    %x HOST: www.hawkee.com
    %x
  }
}

on *:sockread:favorites:{
  if ($sockerr) { $iif($dialog(hcode), did -ra hcode 16 ERROR: $sock($sockname).wsmsg) }
  else {
    var %x 
    sockread %x
    if $regex(%x,/<title>(.+)\s-\s.*<\/title>/i) {
      $iif(!$read(favorites.txt,w,* $+ %favorites $+ *), write favorites.txt %favorites - $regml(1))
      loadbuf -ro hcode 23 favorites.txt
    }
  }
}

on *:sockopen:cds:{
  if ($sockerr) { $iif($dialog(hcode), did -ra hcode 16 ERROR: $sock($sockname).wsmsg) }
  else {
    var %x = sockwrite -n $sockname
    %x GET /snippet/ $+ %y $+ / HTTP/1.1
    %x HOST: www.hawkee.com
    %x
  }
}
on *:sockread:cds:{
  if ($sockerr) { $iif($dialog(hcode), did -ra hcode 16 ERROR: $sock($sockname).wsmsg) }
  else {
    var %x
    sockread %x
    if $regex(%x,/<b><a href='.*'>(.+)<\/a><\/b>/) {
      $iif($dialog(hcode),did -a hcode 28 • $regml(1) wrote: $crlf)
    }
    if $regex(%x,/(?:\11{4})?(.+)(?:<br>|<br\s\/>)/) {
      var %y = $regml(1)
      $iif($dialog(hcode),did -a hcode 28 $html_tags($char_r($regsubex(%y,/<[^>]*>|\t/g,))) $crlf)
    }
    if (*div comments* iswm %x) {
      sockclose cds 
    }
  }
}

Same as original snippet post, with the addition of a "check latest" button =P. Also, after selecting check latest, you can use the "<<" and ">>" buttons to search through snippets on previous pages.

 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.