pinboard-elinks

Check-in [bb5603e612]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Use .netrc for storing API token
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256: bb5603e612d1ce0926ad7ff93e5fd56000eee5e8662fe9afecb37940ffbbb23a
User & Date: atomicules@lavabit.com 2012-12-28 12:35:33
Context
2012-12-29
12:06
Make sure everything is local ref. check-in: e662f63e44 user: atomicules@lavabit.com tags: master, trunk
2012-12-28
12:35
Use .netrc for storing API token check-in: bb5603e612 user: atomicules@lavabit.com tags: master, trunk
2012-12-20
12:14
Add some notes about edit/delete functionality, etc check-in: 9e80d1ff8a user: atomicules@lavabit.com tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to README.markdown.

7
8
9
10
11
12
13
14




15
16
17
18
19
20
21
- Reformats the mobile site to be better for ELinks (Adds working edit/delete links)

Javascript support in ELinks is a bit lacking (it's never worked well for me anyway) so it's not possible to use the Pinboard bookmarklets. Lua support in ELinks is much better, so this script does what the bookmarklets would do, but via lua. Since CSS support in ELinks is also a bit lacking - there's a lot of cruft on the Pinboard mobile sight in ELinks (stuff that's set as `display: none`, etc) - this script also cleans that up. The Pinboard edit and delete links won't work in ELinks because of javascript again, so this script generates replacement ones: Editing is done by "saving" the bookmark again, since the add page works fine; Deleting is done via the AP, since it is immediately destructive the delete link is only visible on the individual bookmark page, not when browsing through a list of bookmarks.

##Installation

Source from your `~/.elinks/hooks.lua` file with `dofile("pinboard.lua")`
If you want to be able to delete bookmarks on Pinboard then you need to add in your auth\_token to the `pinboard.lua` file





##Notes

Developed and tested with ELinks 0.12pre5 and Lua 5.0 (both of which are well out of date, but if it works there it should work with if you are building from the repository master and using Lua 5.1, etc; and if it doesn't since you are clever enough to build yourself I'm sure you can adapt the scripts as necessary). 

##Extras








|
>
>
>
>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
- Reformats the mobile site to be better for ELinks (Adds working edit/delete links)

Javascript support in ELinks is a bit lacking (it's never worked well for me anyway) so it's not possible to use the Pinboard bookmarklets. Lua support in ELinks is much better, so this script does what the bookmarklets would do, but via lua. Since CSS support in ELinks is also a bit lacking - there's a lot of cruft on the Pinboard mobile sight in ELinks (stuff that's set as `display: none`, etc) - this script also cleans that up. The Pinboard edit and delete links won't work in ELinks because of javascript again, so this script generates replacement ones: Editing is done by "saving" the bookmark again, since the add page works fine; Deleting is done via the AP, since it is immediately destructive the delete link is only visible on the individual bookmark page, not when browsing through a list of bookmarks.

##Installation

Source from your `~/.elinks/hooks.lua` file with `dofile("pinboard.lua")`
If you want to be able to delete bookmarks on Pinboard then you need to add in your auth\_token to a `~/.netrc` file in the following format:

	machine pinboard.in
		login <Your pinboard login name>
		password <Your pinboard API token>

##Notes

Developed and tested with ELinks 0.12pre5 and Lua 5.0 (both of which are well out of date, but if it works there it should work with if you are building from the repository master and using Lua 5.1, etc; and if it doesn't since you are clever enough to build yourself I'm sure you can adapt the scripts as necessary). 

##Extras

Changes to pinboard.lua.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70
71
72


























73
74
75
76
77
78
79
--Pinboard tools for ELinks
--source from your ~/.elinks/hooks.lua file with `dofile("pinboard.lua")`

--ALT+p to save a bookmark. Brings up an XDialog, first row is to enter a description, second row is for tags
--ALT+l to read later. 
--Reformats the mobile site to be better for ELinks

--In order to be able to delete need to enter auth_token below
local pb_auth = ""
local pb_base = 'https://pinboard.in/add?'
local pb_url

function addto_pinboard (description, tags)
	url = current_url ()
	title = current_title ()
	doc_url = pb_base..'url='..escape (url)..'&title='..escape (title)..'&description='..escape (description)..'&tags='..escape (tags)..'&next='..escape (url)..' ','Pinboard','toolbar=no,width=700,height=350';
................................................................................
		return html
	end
end


function new_edit_link (s)
	_,_,link = string.find (s, '<a class="bookmark_title.-href="(.-)"')

	--But need to escape any %X (where X is a digit) in the URL http://stackoverflow.com/a/6705995/208793
	link = string.gsub (link, "([%%])", "%%%1")
	if string.find(pb_url, "/b:") and not (pb_auth == "") then --if on individual bm page, add Delete button as well
		delete_link = '<a href="https://api.pinboard.in/v1/posts/delete?url='..link..'&auth_token='..pb_auth..'" class="delete">Delete</a>'
	else
		delete_link = ''
	end
	replacement = string.gsub (s, '<a onclick="edit.-</a>', '<a href="'..pb_base..'url='..link..'" class="edit">Edit</a> '..delete_link..'<br>')
	return replacement
end




























--The following taken from the contrib hooks.lua sample
function hx (c)
    return string.char((c >= 10 and (c - 10) + string.byte ('A')) or c + string.byte ('0'))
end

function char2hex (c)







|
<







 







>


|
|







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
..
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
--Pinboard tools for ELinks
--source from your ~/.elinks/hooks.lua file with `dofile("pinboard.lua")`

--ALT+p to save a bookmark. Brings up an XDialog, first row is to enter a description, second row is for tags
--ALT+l to read later. 
--Reformats the mobile site to be better for ELinks

--In order to be able to delete need to enter auth_token in `.netrc`. See README

local pb_base = 'https://pinboard.in/add?'
local pb_url

function addto_pinboard (description, tags)
	url = current_url ()
	title = current_title ()
	doc_url = pb_base..'url='..escape (url)..'&title='..escape (title)..'&description='..escape (description)..'&tags='..escape (tags)..'&next='..escape (url)..' ','Pinboard','toolbar=no,width=700,height=350';
................................................................................
		return html
	end
end


function new_edit_link (s)
	_,_,link = string.find (s, '<a class="bookmark_title.-href="(.-)"')
	login,token = readnetrc()
	--But need to escape any %X (where X is a digit) in the URL http://stackoverflow.com/a/6705995/208793
	link = string.gsub (link, "([%%])", "%%%1")
	if string.find(pb_url, "/b:") and not (login == nil) then --if on individual bm page, add Delete button as well
		delete_link = '<a href="https://api.pinboard.in/v1/posts/delete?url='..link..'&auth_token='..login..":"..token..'" class="delete">Delete</a>'
	else
		delete_link = ''
	end
	replacement = string.gsub (s, '<a onclick="edit.-</a>', '<a href="'..pb_base..'url='..link..'" class="edit">Edit</a> '..delete_link..'<br>')
	return replacement
end


function readnetrc () 
	local login
	local password
	local getnextlines = 0
	for line in io.lines (os.getenv("HOME").."/.netrc") do
		if string.find (line, "pinboard.in") then
			if string.find (line, "login") then
				--login and password on one line	
				_,_,login,password = string.find(line, "login%s(%w+)%spassword%s(%w+)")
			else
			--else need to get from the next two lines	
				getnextlines = 2
			end
		elseif getnextlines > 0 then
			if string.find (line, "login") then
				_,_,login = string.find(line, "login%s(%w+)")
			elseif string.find (line, "password") then
				_,_,password = string.find(line, "password%s(%w+)")
			end	
			getnextlines = getnextlines - 1
		end
	end
	return login,password
end


--The following taken from the contrib hooks.lua sample
function hx (c)
    return string.char((c >= 10 and (c - 10) + string.byte ('A')) or c + string.byte ('0'))
end

function char2hex (c)