pinboard-elinks

Hex Artifact Content
Login

Artifact ca70f0a8264a88229e156f6378739479a9d02d3e528bed65bd692773f3822d7b:


0000: 2d 2d 50 69 6e 62 6f 61 72 64 20 74 6f 6f 6c 73  --Pinboard tools
0010: 20 66 6f 72 20 45 4c 69 6e 6b 73 0a 2d 2d 73 6f   for ELinks.--so
0020: 75 72 63 65 20 66 72 6f 6d 20 79 6f 75 72 20 7e  urce from your ~
0030: 2f 2e 65 6c 69 6e 6b 73 2f 68 6f 6f 6b 73 2e 6c  /.elinks/hooks.l
0040: 75 61 20 66 69 6c 65 20 77 69 74 68 20 60 64 6f  ua file with `do
0050: 66 69 6c 65 28 22 70 69 6e 62 6f 61 72 64 2e 6c  file("pinboard.l
0060: 75 61 22 29 60 0a 0a 2d 2d 43 54 52 4c 2b 70 20  ua")`..--CTRL+p 
0070: 74 6f 20 73 61 76 65 20 61 20 62 6f 6f 6b 6d 61  to save a bookma
0080: 72 6b 2e 20 42 72 69 6e 67 73 20 75 70 20 61 6e  rk. Brings up an
0090: 20 58 44 69 61 6c 6f 67 2c 20 66 69 72 73 74 20   XDialog, first 
00a0: 72 6f 77 20 69 73 20 74 6f 20 65 6e 74 65 72 20  row is to enter 
00b0: 61 20 64 65 73 63 72 69 70 74 69 6f 6e 2c 20 73  a description, s
00c0: 65 63 6f 6e 64 20 72 6f 77 20 69 73 20 66 6f 72  econd row is for
00d0: 20 74 61 67 73 0a 2d 2d 43 54 52 4c 2b 6f 20 74   tags.--CTRL+o t
00e0: 6f 20 72 65 61 64 20 6c 61 74 65 72 20 28 49 74  o read later (It
00f0: 27 73 20 6e 65 78 74 20 74 6f 20 70 2e 20 59 6f  's next to p. Yo
0100: 75 20 74 72 79 20 61 6e 64 20 66 69 6e 64 20 61  u try and find a
0110: 20 6e 6f 6e 65 20 63 6f 6e 66 6c 69 63 74 69 6e   none conflictin
0120: 67 20 6b 65 79 62 6f 61 72 64 20 73 68 6f 72 74  g keyboard short
0130: 63 75 74 20 69 6e 20 45 6c 69 6e 6b 73 29 0a 2d  cut in Elinks).-
0140: 2d 52 65 66 6f 72 6d 61 74 73 20 74 68 65 20 6d  -Reformats the m
0150: 6f 62 69 6c 65 20 73 69 74 65 20 74 6f 20 62 65  obile site to be
0160: 20 62 65 74 74 65 72 20 66 6f 72 20 45 4c 69 6e   better for ELin
0170: 6b 73 0a 0a 2d 2d 49 6e 20 6f 72 64 65 72 20 74  ks..--In order t
0180: 6f 20 62 65 20 61 62 6c 65 20 74 6f 20 64 65 6c  o be able to del
0190: 65 74 65 20 6e 65 65 64 20 74 6f 20 65 6e 74 65  ete need to ente
01a0: 72 20 61 75 74 68 5f 74 6f 6b 65 6e 20 69 6e 20  r auth_token in 
01b0: 60 2e 6e 65 74 72 63 60 2e 20 53 65 65 20 52 45  `.netrc`. See RE
01c0: 41 44 4d 45 0a 6c 6f 63 61 6c 20 70 62 5f 62 61  ADME.local pb_ba
01d0: 73 65 20 3d 20 27 68 74 74 70 73 3a 2f 2f 70 69  se = 'https://pi
01e0: 6e 62 6f 61 72 64 2e 69 6e 2f 61 64 64 3f 27 0a  nboard.in/add?'.
01f0: 6c 6f 63 61 6c 20 70 62 5f 75 72 6c 0a 0a 66 75  local pb_url..fu
0200: 6e 63 74 69 6f 6e 20 61 64 64 74 6f 5f 70 69 6e  nction addto_pin
0210: 62 6f 61 72 64 20 28 64 65 73 63 72 69 70 74 69  board (descripti
0220: 6f 6e 2c 20 74 61 67 73 29 0a 09 6c 6f 63 61 6c  on, tags)..local
0230: 20 75 72 6c 20 3d 20 63 75 72 72 65 6e 74 5f 75   url = current_u
0240: 72 6c 20 28 29 0a 09 6c 6f 63 61 6c 20 74 69 74  rl ()..local tit
0250: 6c 65 20 3d 20 63 75 72 72 65 6e 74 5f 74 69 74  le = current_tit
0260: 6c 65 20 28 29 0a 09 6c 6f 63 61 6c 20 64 6f 63  le ()..local doc
0270: 5f 75 72 6c 20 3d 20 70 62 5f 62 61 73 65 2e 2e  _url = pb_base..
0280: 27 75 72 6c 3d 27 2e 2e 65 73 63 61 70 65 20 28  'url='..escape (
0290: 75 72 6c 29 2e 2e 27 26 74 69 74 6c 65 3d 27 2e  url)..'&title='.
02a0: 2e 65 73 63 61 70 65 20 28 74 69 74 6c 65 29 2e  .escape (title).
02b0: 2e 27 26 64 65 73 63 72 69 70 74 69 6f 6e 3d 27  .'&description='
02c0: 2e 2e 65 73 63 61 70 65 20 28 64 65 73 63 72 69  ..escape (descri
02d0: 70 74 69 6f 6e 29 2e 2e 27 26 74 61 67 73 3d 27  ption)..'&tags='
02e0: 2e 2e 65 73 63 61 70 65 20 28 74 61 67 73 29 2e  ..escape (tags).
02f0: 2e 27 26 6e 65 78 74 3d 27 2e 2e 65 73 63 61 70  .'&next='..escap
0300: 65 20 28 75 72 6c 29 2e 2e 27 20 27 2c 27 50 69  e (url)..' ','Pi
0310: 6e 62 6f 61 72 64 27 2c 27 74 6f 6f 6c 62 61 72  nboard','toolbar
0320: 3d 6e 6f 2c 77 69 64 74 68 3d 37 30 30 2c 68 65  =no,width=700,he
0330: 69 67 68 74 3d 33 35 30 27 3b 0a 20 20 20 20 72  ight=350';.    r
0340: 65 74 75 72 6e 20 64 6f 63 5f 75 72 6c 0a 65 6e  eturn doc_url.en
0350: 64 0a 09 62 69 6e 64 5f 6b 65 79 20 28 22 6d 61  d..bind_key ("ma
0360: 69 6e 22 2c 20 22 43 74 72 6c 2d 70 22 2c 0a 09  in", "Ctrl-p",..
0370: 09 66 75 6e 63 74 69 6f 6e 20 28 29 20 78 64 69  .function () xdi
0380: 61 6c 6f 67 28 22 3c 44 65 73 63 72 69 70 74 69  alog("<Descripti
0390: 6f 6e 3e 22 2c 20 22 3c 54 61 67 73 3e 22 2c 0a  on>", "<Tags>",.
03a0: 09 09 09 66 75 6e 63 74 69 6f 6e 20 28 64 65 73  ...function (des
03b0: 63 72 69 70 74 69 6f 6e 2c 20 74 61 67 73 29 0a  cription, tags).
03c0: 09 09 09 09 72 65 74 75 72 6e 20 22 67 6f 74 6f  ....return "goto
03d0: 5f 75 72 6c 22 2c 0a 09 09 09 09 61 64 64 74 6f  _url",.....addto
03e0: 5f 70 69 6e 62 6f 61 72 64 20 28 64 65 73 63 72  _pinboard (descr
03f0: 69 70 74 69 6f 6e 2c 20 74 61 67 73 29 20 0a 09  iption, tags) ..
0400: 09 65 6e 64 29 0a 09 65 6e 64 29 0a 0a 0a 66 75  .end)..end)...fu
0410: 6e 63 74 69 6f 6e 20 72 65 61 64 6c 61 74 65 72  nction readlater
0420: 5f 70 69 6e 62 6f 61 72 64 20 28 29 0a 09 6c 6f  _pinboard ()..lo
0430: 63 61 6c 20 75 72 6c 20 3d 20 63 75 72 72 65 6e  cal url = curren
0440: 74 5f 75 72 6c 20 28 29 0a 09 6c 6f 63 61 6c 20  t_url ()..local 
0450: 74 69 74 6c 65 20 3d 20 63 75 72 72 65 6e 74 5f  title = current_
0460: 74 69 74 6c 65 20 28 29 0a 09 6c 6f 63 61 6c 20  title ()..local 
0470: 64 6f 63 5f 75 72 6c 20 3d 20 70 62 5f 62 61 73  doc_url = pb_bas
0480: 65 2e 2e 27 6c 61 74 65 72 3d 79 65 73 26 6e 65  e..'later=yes&ne
0490: 78 74 3d 73 61 6d 65 26 6e 6f 75 69 3d 79 65 73  xt=same&noui=yes
04a0: 26 6a 75 6d 70 3d 63 6c 6f 73 65 26 75 72 6c 3d  &jump=close&url=
04b0: 27 2e 2e 65 73 63 61 70 65 20 28 75 72 6c 29 2e  '..escape (url).
04c0: 2e 27 26 74 69 74 6c 65 3d 27 2e 2e 65 73 63 61  .'&title='..esca
04d0: 70 65 20 28 74 69 74 6c 65 29 3b 0a 09 2d 2d 55  pe (title);..--U
04e0: 73 65 73 20 26 6e 65 78 74 3d 73 61 6d 65 20 74  ses &next=same t
04f0: 6f 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 72 65  o immediately re
0500: 74 75 72 6e 20 74 6f 20 70 61 67 65 20 62 65 69  turn to page bei
0510: 6e 67 20 62 6f 6f 6b 6d 61 72 6b 65 64 0a 20 20  ng bookmarked.  
0520: 20 20 72 65 74 75 72 6e 20 64 6f 63 5f 75 72 6c    return doc_url
0530: 0a 65 6e 64 0a 09 62 69 6e 64 5f 6b 65 79 20 28  .end..bind_key (
0540: 22 6d 61 69 6e 22 2c 20 22 43 74 72 6c 2d 6f 22  "main", "Ctrl-o"
0550: 2c 0a 09 09 66 75 6e 63 74 69 6f 6e 20 28 29 20  ,...function () 
0560: 72 65 74 75 72 6e 20 22 67 6f 74 6f 5f 75 72 6c  return "goto_url
0570: 22 2c 20 72 65 61 64 6c 61 74 65 72 5f 70 69 6e  ", readlater_pin
0580: 62 6f 61 72 64 20 28 29 20 65 6e 64 29 0a 0a 0a  board () end)...
0590: 66 75 6e 63 74 69 6f 6e 20 70 72 65 5f 66 6f 72  function pre_for
05a0: 6d 61 74 5f 68 74 6d 6c 5f 68 6f 6f 6b 20 28 75  mat_html_hook (u
05b0: 72 6c 2c 20 68 74 6d 6c 29 0a 09 2d 2d 73 74 72  rl, html)..--str
05c0: 69 70 20 73 74 75 66 66 20 74 68 61 74 20 73 68  ip stuff that sh
05d0: 6f 75 6c 64 6e 61 65 20 62 65 20 64 69 73 70 6c  ouldnae be displ
05e0: 61 79 65 64 20 61 6e 79 77 61 79 0a 09 69 66 20  ayed anyway..if 
05f0: 73 74 72 69 6e 67 2e 66 69 6e 64 28 75 72 6c 2c  string.find(url,
0600: 20 22 3a 2f 2f 6d 2e 70 69 6e 62 6f 61 72 64 2e   "://m.pinboard.
0610: 69 6e 22 29 20 74 68 65 6e 0a 09 09 70 62 5f 75  in") then...pb_u
0620: 72 6c 20 3d 20 75 72 6c 20 2d 2d 73 69 6e 63 65  rl = url --since
0630: 20 63 61 6e 27 74 20 70 61 73 73 20 61 64 64 69   can't pass addi
0640: 74 69 6f 6e 61 6c 20 61 72 67 73 20 74 6f 20 6e  tional args to n
0650: 65 77 5f 65 64 69 74 5f 6c 69 6e 6b 0a 09 09 68  ew_edit_link...h
0660: 74 6d 6c 20 3d 20 73 74 72 69 6e 67 2e 67 73 75  tml = string.gsu
0670: 62 20 28 68 74 6d 6c 2c 20 27 3c 64 69 76 20 6e  b (html, '<div n
0680: 61 6d 65 3d 22 65 64 69 74 5f 63 68 65 63 6b 62  ame="edit_checkb
0690: 6f 78 22 2e 2d 3c 2f 64 69 76 3e 27 2c 20 27 27  ox".-</div>', ''
06a0: 29 20 2d 2d 6f 6b 20 61 73 20 6e 6f 20 63 68 69  ) --ok as no chi
06b0: 6c 64 20 64 69 76 73 0a 09 09 68 74 6d 6c 20 3d  ld divs...html =
06c0: 20 73 74 72 69 6e 67 2e 67 73 75 62 20 28 68 74   string.gsub (ht
06d0: 6d 6c 2c 20 27 3c 64 69 76 20 63 6c 61 73 73 3d  ml, '<div class=
06e0: 22 73 74 61 72 2e 2d 3c 2f 64 69 76 3e 27 2c 20  "star.-</div>', 
06f0: 27 27 29 20 2d 2d 6f 6b 20 61 73 20 6e 6f 20 63  '') --ok as no c
0700: 68 69 6c 64 20 64 69 76 73 0a 09 09 68 74 6d 6c  hild divs...html
0710: 20 3d 20 73 74 72 69 6e 67 2e 67 73 75 62 20 28   = string.gsub (
0720: 68 74 6d 6c 2c 20 27 3c 66 69 65 6c 64 73 65 74  html, '<fieldset
0730: 20 69 64 3d 22 62 75 6c 6b 5f 65 64 69 74 5f 62   id="bulk_edit_b
0740: 6f 78 22 3e 2e 2d 3c 2f 66 69 65 6c 64 73 65 74  ox">.-</fieldset
0750: 3e 27 2c 20 27 27 29 20 2d 2d 64 6f 20 74 68 69  >', '') --do thi
0760: 73 20 69 6e 73 74 65 61 64 20 6f 66 20 70 61 72  s instead of par
0770: 65 6e 74 20 64 69 76 0a 09 09 68 74 6d 6c 20 3d  ent div...html =
0780: 20 73 74 72 69 6e 67 2e 67 73 75 62 20 28 68 74   string.gsub (ht
0790: 6d 6c 2c 20 27 3c 61 20 63 6c 61 73 73 3d 22 62  ml, '<a class="b
07a0: 6f 6f 6b 6d 61 72 6b 5f 74 69 74 6c 65 2e 2d 65  ookmark_title.-e
07b0: 64 69 74 3c 2f 61 3e 27 2c 20 6e 65 77 5f 65 64  dit</a>', new_ed
07c0: 69 74 5f 6c 69 6e 6b 29 0a 09 09 68 74 6d 6c 20  it_link)...html 
07d0: 3d 20 73 74 72 69 6e 67 2e 67 73 75 62 20 28 68  = string.gsub (h
07e0: 74 6d 6c 2c 20 27 3c 64 69 76 20 63 6c 61 73 73  tml, '<div class
07f0: 3d 22 64 65 6c 65 74 65 5f 6c 69 6e 6b 22 2e 2d  ="delete_link".-
0800: 3c 2f 64 69 76 3e 27 2c 20 27 27 29 0a 09 09 68  </div>', '')...h
0810: 74 6d 6c 20 3d 20 73 74 72 69 6e 67 2e 67 73 75  tml = string.gsu
0820: 62 20 28 68 74 6d 6c 2c 20 27 3c 64 69 76 20 73  b (html, '<div s
0830: 74 79 6c 65 3d 22 64 69 73 70 6c 61 79 3a 69 6e  tyle="display:in
0840: 6c 69 6e 65 22 20 63 6c 61 73 73 3d 22 72 65 61  line" class="rea
0850: 64 22 3e 2e 2d 3c 2f 64 69 76 3e 27 2c 20 27 27  d">.-</div>', ''
0860: 29 0a 09 09 68 74 6d 6c 20 3d 20 73 74 72 69 6e  )...html = strin
0870: 67 2e 67 73 75 62 20 28 68 74 6d 6c 2c 20 27 3c  g.gsub (html, '<
0880: 64 69 76 20 69 64 3d 22 65 64 69 74 5f 62 6f 6f  div id="edit_boo
0890: 6b 6d 61 72 6b 5f 66 6f 72 6d 22 2e 2d 3c 2f 66  kmark_form".-</f
08a0: 6f 72 6d 3e 5c 6e 20 20 5c 6e 3c 2f 64 69 76 3e  orm>\n  \n</div>
08b0: 27 2c 20 27 27 29 0a 09 09 2d 2d 41 64 64 20 73  ', '')...--Add s
08c0: 74 61 72 72 65 64 20 61 6e 64 20 74 77 65 65 74  tarred and tweet
08d0: 73 20 6c 69 6e 6b 73 20 74 6f 20 74 68 65 20 6e  s links to the n
08e0: 61 76 20 6d 65 6e 75 0a 09 09 68 74 6d 6c 20 3d  av menu...html =
08f0: 20 73 74 72 69 6e 67 2e 67 73 75 62 20 28 68 74   string.gsub (ht
0900: 6d 6c 2c 20 27 28 3c 64 69 76 20 69 64 3d 22 74  ml, '(<div id="t
0910: 6f 70 5f 6d 65 6e 75 22 3e 5c 6e 3c 61 20 68 72  op_menu">\n<a hr
0920: 65 66 3d 22 2f 75 3a 29 28 25 77 2d 29 28 2f 22  ef="/u:)(%w-)(/"
0930: 2e 2d 3c 2f 61 3e 20 e2 80 a7 20 29 27 2c 20 27  .-</a> ‧ )', '
0940: 25 31 25 32 25 33 3c 61 20 68 72 65 66 3d 22 2f  %1%2%3<a href="/
0950: 75 3a 25 32 2f 73 74 61 72 72 65 64 2f 22 20 3e  u:%2/starred/" >
0960: 73 74 61 72 72 65 64 3c 2f 61 3e 20 20 e2 80 a7  starred</a>  ‧
0970: 20 3c 61 20 68 72 65 66 3d 22 2f 75 3a 25 32 2f   <a href="/u:%2/
0980: 74 77 65 65 74 73 2f 22 20 3e 74 77 65 65 74 73  tweets/" >tweets
0990: 3c 2f 61 3e 20 e2 80 a7 27 29 0a 09 09 72 65 74  </a> ‧')...ret
09a0: 75 72 6e 20 68 74 6d 6c 0a 09 65 6c 73 65 69 66  urn html..elseif
09b0: 20 73 74 72 69 6e 67 2e 66 69 6e 64 28 75 72 6c   string.find(url
09c0: 2c 20 22 3a 2f 2f 70 69 6e 62 6f 61 72 64 2e 69  , "://pinboard.i
09d0: 6e 2f 61 64 64 25 3f 75 72 6c 3d 22 29 20 74 68  n/add%?url=") th
09e0: 65 6e 20 2d 2d 6e 65 65 64 20 74 6f 20 65 73 63  en --need to esc
09f0: 61 70 65 20 74 68 65 20 3f 20 68 65 72 65 0a 09  ape the ? here..
0a00: 09 2d 2d 52 65 6d 6f 76 65 20 64 65 6c 65 74 65  .--Remove delete
0a10: 20 61 6e 64 20 64 65 73 74 72 6f 79 20 66 72 6f   and destroy fro
0a20: 6d 20 74 68 65 20 61 64 64 20 70 61 67 65 2e 0a  m the add page..
0a30: 09 09 68 74 6d 6c 20 3d 20 73 74 72 69 6e 67 2e  ..html = string.
0a40: 67 73 75 62 20 28 68 74 6d 6c 2c 20 27 3c 64 69  gsub (html, '<di
0a50: 76 20 73 74 79 6c 65 3d 22 64 69 73 70 6c 61 79  v style="display
0a60: 3a 69 6e 6c 69 6e 65 22 20 69 64 3d 22 64 65 6c  :inline" id="del
0a70: 65 74 65 5f 2e 2d 3c 2f 64 69 76 3e 27 2c 20 27  ete_.-</div>', '
0a80: 27 29 0a 09 09 68 74 6d 6c 20 3d 20 73 74 72 69  ')...html = stri
0a90: 6e 67 2e 67 73 75 62 20 28 68 74 6d 6c 2c 20 27  ng.gsub (html, '
0aa0: 3c 64 69 76 20 73 74 79 6c 65 3d 22 76 69 73 69  <div style="visi
0ab0: 62 69 6c 69 74 79 3a 68 69 64 64 65 6e 3b 64 69  bility:hidden;di
0ac0: 73 70 6c 61 79 3a 6e 6f 6e 65 22 20 63 6c 61 73  splay:none" clas
0ad0: 73 3d 22 64 65 6c 65 74 65 5f 64 69 76 22 20 69  s="delete_div" i
0ae0: 64 3d 22 64 65 73 74 72 6f 79 5f 2e 2d 3c 2f 64  d="destroy_.-</d
0af0: 69 76 3e 27 2c 20 27 27 29 0a 09 09 72 65 74 75  iv>', '')...retu
0b00: 72 6e 20 68 74 6d 6c 0a 09 65 6e 64 0a 65 6e 64  rn html..end.end
0b10: 0a 0a 0a 66 75 6e 63 74 69 6f 6e 20 6e 65 77 5f  ...function new_
0b20: 65 64 69 74 5f 6c 69 6e 6b 20 28 73 29 0a 09 6c  edit_link (s)..l
0b30: 6f 63 61 6c 20 5f 2c 5f 2c 6c 69 6e 6b 20 3d 20  ocal _,_,link = 
0b40: 73 74 72 69 6e 67 2e 66 69 6e 64 20 28 73 2c 20  string.find (s, 
0b50: 27 3c 61 20 63 6c 61 73 73 3d 22 62 6f 6f 6b 6d  '<a class="bookm
0b60: 61 72 6b 5f 74 69 74 6c 65 2e 2d 68 72 65 66 3d  ark_title.-href=
0b70: 22 28 2e 2d 29 22 27 29 0a 09 6c 6f 63 61 6c 20  "(.-)"')..local 
0b80: 6c 6f 67 69 6e 2c 74 6f 6b 65 6e 20 3d 20 72 65  login,token = re
0b90: 61 64 6e 65 74 72 63 28 29 0a 09 2d 2d 42 75 74  adnetrc()..--But
0ba0: 20 6e 65 65 64 20 74 6f 20 65 73 63 61 70 65 20   need to escape 
0bb0: 61 6e 79 20 25 58 20 28 77 68 65 72 65 20 58 20  any %X (where X 
0bc0: 69 73 20 61 20 64 69 67 69 74 29 20 69 6e 20 74  is a digit) in t
0bd0: 68 65 20 55 52 4c 20 68 74 74 70 3a 2f 2f 73 74  he URL http://st
0be0: 61 63 6b 6f 76 65 72 66 6c 6f 77 2e 63 6f 6d 2f  ackoverflow.com/
0bf0: 61 2f 36 37 30 35 39 39 35 2f 32 30 38 37 39 33  a/6705995/208793
0c00: 0a 09 6c 69 6e 6b 20 3d 20 73 74 72 69 6e 67 2e  ..link = string.
0c10: 67 73 75 62 20 28 6c 69 6e 6b 2c 20 22 28 5b 25  gsub (link, "([%
0c20: 25 5d 29 22 2c 20 22 25 25 25 31 22 29 0a 09 69  %])", "%%%1")..i
0c30: 66 20 73 74 72 69 6e 67 2e 66 69 6e 64 28 70 62  f string.find(pb
0c40: 5f 75 72 6c 2c 20 22 2f 62 3a 22 29 20 61 6e 64  _url, "/b:") and
0c50: 20 6e 6f 74 20 28 6c 6f 67 69 6e 20 3d 3d 20 6e   not (login == n
0c60: 69 6c 29 20 74 68 65 6e 20 2d 2d 69 66 20 6f 6e  il) then --if on
0c70: 20 69 6e 64 69 76 69 64 75 61 6c 20 62 6d 20 70   individual bm p
0c80: 61 67 65 2c 20 61 64 64 20 44 65 6c 65 74 65 20  age, add Delete 
0c90: 62 75 74 74 6f 6e 20 61 73 20 77 65 6c 6c 0a 09  button as well..
0ca0: 09 64 65 6c 65 74 65 5f 6c 69 6e 6b 20 3d 20 27  .delete_link = '
0cb0: 3c 61 20 68 72 65 66 3d 22 68 74 74 70 73 3a 2f  <a href="https:/
0cc0: 2f 61 70 69 2e 70 69 6e 62 6f 61 72 64 2e 69 6e  /api.pinboard.in
0cd0: 2f 76 31 2f 70 6f 73 74 73 2f 64 65 6c 65 74 65  /v1/posts/delete
0ce0: 3f 75 72 6c 3d 27 2e 2e 6c 69 6e 6b 2e 2e 27 26  ?url='..link..'&
0cf0: 61 75 74 68 5f 74 6f 6b 65 6e 3d 27 2e 2e 6c 6f  auth_token='..lo
0d00: 67 69 6e 2e 2e 22 3a 22 2e 2e 74 6f 6b 65 6e 2e  gin..":"..token.
0d10: 2e 27 22 20 63 6c 61 73 73 3d 22 64 65 6c 65 74  .'" class="delet
0d20: 65 22 3e 44 65 6c 65 74 65 3c 2f 61 3e 27 0a 09  e">Delete</a>'..
0d30: 65 6c 73 65 0a 09 09 64 65 6c 65 74 65 5f 6c 69  else...delete_li
0d40: 6e 6b 20 3d 20 27 27 0a 09 65 6e 64 0a 09 6c 6f  nk = ''..end..lo
0d50: 63 61 6c 20 72 65 70 6c 61 63 65 6d 65 6e 74 20  cal replacement 
0d60: 3d 20 73 74 72 69 6e 67 2e 67 73 75 62 20 28 73  = string.gsub (s
0d70: 2c 20 27 3c 61 20 6f 6e 63 6c 69 63 6b 3d 22 65  , '<a onclick="e
0d80: 64 69 74 2e 2d 3c 2f 61 3e 27 2c 20 27 3c 61 20  dit.-</a>', '<a 
0d90: 68 72 65 66 3d 22 27 2e 2e 70 62 5f 62 61 73 65  href="'..pb_base
0da0: 2e 2e 27 75 72 6c 3d 27 2e 2e 6c 69 6e 6b 2e 2e  ..'url='..link..
0db0: 27 22 20 63 6c 61 73 73 3d 22 65 64 69 74 22 3e  '" class="edit">
0dc0: 45 64 69 74 3c 2f 61 3e 20 27 2e 2e 64 65 6c 65  Edit</a> '..dele
0dd0: 74 65 5f 6c 69 6e 6b 2e 2e 27 3c 62 72 3e 27 29  te_link..'<br>')
0de0: 0a 09 72 65 74 75 72 6e 20 72 65 70 6c 61 63 65  ..return replace
0df0: 6d 65 6e 74 0a 65 6e 64 0a 0a 0a 66 75 6e 63 74  ment.end...funct
0e00: 69 6f 6e 20 72 65 61 64 6e 65 74 72 63 20 28 29  ion readnetrc ()
0e10: 20 0a 09 6c 6f 63 61 6c 20 6c 6f 67 69 6e 0a 09   ..local login..
0e20: 6c 6f 63 61 6c 20 70 61 73 73 77 6f 72 64 0a 09  local password..
0e30: 6c 6f 63 61 6c 20 67 65 74 6e 65 78 74 6c 69 6e  local getnextlin
0e40: 65 73 20 3d 20 30 0a 09 66 6f 72 20 6c 69 6e 65  es = 0..for line
0e50: 20 69 6e 20 69 6f 2e 6c 69 6e 65 73 20 28 6f 73   in io.lines (os
0e60: 2e 67 65 74 65 6e 76 28 22 48 4f 4d 45 22 29 2e  .getenv("HOME").
0e70: 2e 22 2f 2e 6e 65 74 72 63 22 29 20 64 6f 0a 09  ."/.netrc") do..
0e80: 09 69 66 20 73 74 72 69 6e 67 2e 66 69 6e 64 20  .if string.find 
0e90: 28 6c 69 6e 65 2c 20 22 70 69 6e 62 6f 61 72 64  (line, "pinboard
0ea0: 2e 69 6e 22 29 20 74 68 65 6e 0a 09 09 09 69 66  .in") then....if
0eb0: 20 73 74 72 69 6e 67 2e 66 69 6e 64 20 28 6c 69   string.find (li
0ec0: 6e 65 2c 20 22 6c 6f 67 69 6e 22 29 20 74 68 65  ne, "login") the
0ed0: 6e 0a 09 09 09 09 2d 2d 6c 6f 67 69 6e 20 61 6e  n.....--login an
0ee0: 64 20 70 61 73 73 77 6f 72 64 20 6f 6e 20 6f 6e  d password on on
0ef0: 65 20 6c 69 6e 65 09 0a 09 09 09 09 5f 2c 5f 2c  e line......_,_,
0f00: 6c 6f 67 69 6e 2c 70 61 73 73 77 6f 72 64 20 3d  login,password =
0f10: 20 73 74 72 69 6e 67 2e 66 69 6e 64 28 6c 69 6e   string.find(lin
0f20: 65 2c 20 22 6c 6f 67 69 6e 25 73 28 25 77 2b 29  e, "login%s(%w+)
0f30: 25 73 70 61 73 73 77 6f 72 64 25 73 28 25 77 2b  %spassword%s(%w+
0f40: 29 22 29 0a 09 09 09 65 6c 73 65 0a 09 09 09 2d  )")....else....-
0f50: 2d 65 6c 73 65 20 6e 65 65 64 20 74 6f 20 67 65  -else need to ge
0f60: 74 20 66 72 6f 6d 20 74 68 65 20 6e 65 78 74 20  t from the next 
0f70: 74 77 6f 20 6c 69 6e 65 73 09 0a 09 09 09 09 67  two lines......g
0f80: 65 74 6e 65 78 74 6c 69 6e 65 73 20 3d 20 32 0a  etnextlines = 2.
0f90: 09 09 09 65 6e 64 0a 09 09 65 6c 73 65 69 66 20  ...end...elseif 
0fa0: 67 65 74 6e 65 78 74 6c 69 6e 65 73 20 3e 20 30  getnextlines > 0
0fb0: 20 74 68 65 6e 0a 09 09 09 69 66 20 73 74 72 69   then....if stri
0fc0: 6e 67 2e 66 69 6e 64 20 28 6c 69 6e 65 2c 20 22  ng.find (line, "
0fd0: 6c 6f 67 69 6e 22 29 20 74 68 65 6e 0a 09 09 09  login") then....
0fe0: 09 5f 2c 5f 2c 6c 6f 67 69 6e 20 3d 20 73 74 72  ._,_,login = str
0ff0: 69 6e 67 2e 66 69 6e 64 28 6c 69 6e 65 2c 20 22  ing.find(line, "
1000: 6c 6f 67 69 6e 25 73 28 25 77 2b 29 22 29 0a 09  login%s(%w+)")..
1010: 09 09 65 6c 73 65 69 66 20 73 74 72 69 6e 67 2e  ..elseif string.
1020: 66 69 6e 64 20 28 6c 69 6e 65 2c 20 22 70 61 73  find (line, "pas
1030: 73 77 6f 72 64 22 29 20 74 68 65 6e 0a 09 09 09  sword") then....
1040: 09 5f 2c 5f 2c 70 61 73 73 77 6f 72 64 20 3d 20  ._,_,password = 
1050: 73 74 72 69 6e 67 2e 66 69 6e 64 28 6c 69 6e 65  string.find(line
1060: 2c 20 22 70 61 73 73 77 6f 72 64 25 73 28 25 77  , "password%s(%w
1070: 2b 29 22 29 0a 09 09 09 65 6e 64 09 0a 09 09 09  +)")....end.....
1080: 67 65 74 6e 65 78 74 6c 69 6e 65 73 20 3d 20 67  getnextlines = g
1090: 65 74 6e 65 78 74 6c 69 6e 65 73 20 2d 20 31 0a  etnextlines - 1.
10a0: 09 09 65 6e 64 0a 09 65 6e 64 0a 09 72 65 74 75  ..end..end..retu
10b0: 72 6e 20 6c 6f 67 69 6e 2c 70 61 73 73 77 6f 72  rn login,passwor
10c0: 64 0a 65 6e 64 0a 0a 0a 2d 2d 54 68 65 20 66 6f  d.end...--The fo
10d0: 6c 6c 6f 77 69 6e 67 20 74 61 6b 65 6e 20 66 72  llowing taken fr
10e0: 6f 6d 20 74 68 65 20 63 6f 6e 74 72 69 62 20 68  om the contrib h
10f0: 6f 6f 6b 73 2e 6c 75 61 20 73 61 6d 70 6c 65 20  ooks.lua sample 
1100: 61 6e 64 20 73 6f 20 6e 6f 74 20 63 6f 76 65 72  and so not cover
1110: 65 64 20 62 79 20 61 63 63 6f 6d 70 61 6e 79 69  ed by accompanyi
1120: 6e 67 20 4c 49 43 45 4e 53 45 0a 66 75 6e 63 74  ng LICENSE.funct
1130: 69 6f 6e 20 68 78 20 28 63 29 0a 20 20 20 20 72  ion hx (c).    r
1140: 65 74 75 72 6e 20 73 74 72 69 6e 67 2e 63 68 61  eturn string.cha
1150: 72 28 28 63 20 3e 3d 20 31 30 20 61 6e 64 20 28  r((c >= 10 and (
1160: 63 20 2d 20 31 30 29 20 2b 20 73 74 72 69 6e 67  c - 10) + string
1170: 2e 62 79 74 65 20 28 27 41 27 29 29 20 6f 72 20  .byte ('A')) or 
1180: 63 20 2b 20 73 74 72 69 6e 67 2e 62 79 74 65 20  c + string.byte 
1190: 28 27 30 27 29 29 0a 65 6e 64 0a 0a 66 75 6e 63  ('0')).end..func
11a0: 74 69 6f 6e 20 63 68 61 72 32 68 65 78 20 28 63  tion char2hex (c
11b0: 29 0a 20 20 20 20 72 65 74 75 72 6e 20 27 25 27  ).    return '%'
11c0: 2e 2e 68 78 20 28 6d 61 74 68 2e 66 6c 6f 6f 72  ..hx (math.floor
11d0: 28 73 74 72 69 6e 67 2e 62 79 74 65 20 28 63 29  (string.byte (c)
11e0: 20 2f 20 31 36 29 29 2e 2e 68 78 20 28 6d 61 74   / 16))..hx (mat
11f0: 68 2e 6d 6f 64 28 73 74 72 69 6e 67 2e 62 79 74  h.mod(string.byt
1200: 65 20 28 63 29 2c 20 31 36 29 29 0a 65 6e 64 0a  e (c), 16)).end.
1210: 0a 66 75 6e 63 74 69 6f 6e 20 65 73 63 61 70 65  .function escape
1220: 20 28 73 74 72 29 0a 20 20 20 20 72 65 74 75 72   (str).    retur
1230: 6e 20 73 74 72 69 6e 67 2e 67 73 75 62 20 28 73  n string.gsub (s
1240: 74 72 2c 20 22 28 25 57 29 22 2c 20 63 68 61 72  tr, "(%W)", char
1250: 32 68 65 78 29 0a 65 6e 64 0a 2d 2d 65 6e 64 20  2hex).end.--end 
1260: 73 74 65 61 6c 69 6e 67 0a                       stealing.