pinboard-elinks

Check-in [68a1601284]
Login

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

Overview
Comment:Add delete "button" to bookmark page, works via Pinboard API - Can't use normal delete/destroy since requires posting form data and as far as I know that can only be done via Javascript. However, the API works great just as a get request. Therefore make a delete link that works via an API call - Since this is immediately destructive only put the delete link on the individual bookmark page, not when browsing through a list of bookmarks - Requires API token to be entered into file - Also use some file level variables to avoid repetition and duplication. - Clear up naming. Was a mix of camel case and underscores
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256: 68a1601284077e7b6296032c74be781f7b98d3851d6ea6805757a689afa42837
User & Date: atomicules@lavabit.com 2012-12-20 00:04:29
Context
2012-12-20
00:09
Remove done item from todo check-in: 7a09c1b2d3 user: atomicules@lavabit.com tags: master, trunk
00:04
Add delete "button" to bookmark page, works via Pinboard API - Can't use normal delete/destroy since requires posting form data and as far as I know that can only be done via Javascript. However, the API works great just as a get request. Therefore make a delete link that works via an API call - Since this is immediately destructive only put the delete link on the individual bookmark page, not when browsing through a list of bookmarks - Requires API token to be entered into file - Also use some file level variables to avoid repetition and duplication. - Clear up naming. Was a mix of camel case and underscores check-in: 68a1601284 user: atomicules@lavabit.com tags: master, trunk
2012-12-16
23:11
Bug fix: Redirect back to original page after bookmarking check-in: 54472f67b0 user: atomicules@lavabit.com tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to pinboard.lua.

1
2
3
4
5
6
7




8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50
..
54
55
56
57
58
59
60
61




62
63
64
65
66
67
68
69
--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






function addto_pinboard (description, tags)
	pinboardBase = 'https://pinboard.in/add?'
	url = current_url ()
	title = current_title ()
	docURL = pinboardBase..'url='..escape (url)..'&title='..escape (title)..'&description='..escape (description)..'&tags='..escape (tags)..'&next='..escape (url)..' ','Pinboard','toolbar=no,width=700,height=350';
    return docURL
end
	bind_key ("main", "Alt-p",
		function () xdialog("<Description>", "<Tags>",
			function (description, tags)
				return "goto_url",
				addto_pinboard (description, tags) 
		end)
	end)


function readlater_pinboard ()
	pinboardBase = 'https://pinboard.in/add?'
	url = current_url ()
	title = current_title ()
	docURL = pinboardBase..'later=yes&next=same&noui=yes&jump=close&url='..escape (url)..'&title='..escape (title)..' ','Pinboard','toolbar=no,width=100,height=100';
	--Uses &next=same to immediately return to page being bookmarked
    return docURL
end
	bind_key ("main", "Alt-l",
		function () return "goto_url", readlater_pinboard () end)


function pre_format_html_hook (url, html)
	--strip stuff that shouldnae be displayed anyway
	if string.find(url, "://m.pinboard.in") then

		html = string.gsub (html, '<div name="edit_checkbox".-</div>', '') --ok as no child divs
		html = string.gsub (html, '<div class="star.-</div>', '') --ok as no child divs
		html = string.gsub (html, '<fieldset id="bulk_edit_box">.-</fieldset>', '') --do this instead of parent div
		html = string.gsub (html, '<a class="bookmark_title.-edit</a>', new_edit_link )
		html = string.gsub (html, '<div class="delete_link".-</div>', '')
		html = string.gsub (html, '<div style="display:inline" class="read">.-</div>', '')
		html = string.gsub (html, '<div id="edit_bookmark_form".-</form>\n  \n</div>', '')
		return html
	elseif string.find(url, "://pinboard.in/add%?url=") then --need to escape the ? here
		--Remove delete and destroy from the add page.
		html = string.gsub (html, '<div style="display:inline" id="delete_.-</div>', '')
................................................................................
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")
	pbbase = "https://pinboard.in/add?url="




	replacement = string.gsub (s, '<a onclick="edit.-</a>', '<a href="'..pbbase..link..'" class="edit">Edit</a><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'))







>
>
>
>


<


|
|











<


|

|








>



|







 







|
>
>
>
>
|







1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
--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 doc_url
end
	bind_key ("main", "Alt-p",
		function () xdialog("<Description>", "<Tags>",
			function (description, tags)
				return "goto_url",
				addto_pinboard (description, tags) 
		end)
	end)


function readlater_pinboard ()

	url = current_url ()
	title = current_title ()
	doc_url = pb_base..'later=yes&next=same&noui=yes&jump=close&url='..escape (url)..'&title='..escape (title)..' ','Pinboard','toolbar=no,width=100,height=100';
	--Uses &next=same to immediately return to page being bookmarked
    return doc_url
end
	bind_key ("main", "Alt-l",
		function () return "goto_url", readlater_pinboard () end)


function pre_format_html_hook (url, html)
	--strip stuff that shouldnae be displayed anyway
	if string.find(url, "://m.pinboard.in") then
		pb_url = url --since can't pass additional args to new_edit_link
		html = string.gsub (html, '<div name="edit_checkbox".-</div>', '') --ok as no child divs
		html = string.gsub (html, '<div class="star.-</div>', '') --ok as no child divs
		html = string.gsub (html, '<fieldset id="bulk_edit_box">.-</fieldset>', '') --do this instead of parent div
		html = string.gsub (html, '<a class="bookmark_title.-edit</a>', new_edit_link)
		html = string.gsub (html, '<div class="delete_link".-</div>', '')
		html = string.gsub (html, '<div style="display:inline" class="read">.-</div>', '')
		html = string.gsub (html, '<div id="edit_bookmark_form".-</form>\n  \n</div>', '')
		return html
	elseif string.find(url, "://pinboard.in/add%?url=") then --need to escape the ? here
		--Remove delete and destroy from the add page.
		html = string.gsub (html, '<div style="display:inline" id="delete_.-</div>', '')
................................................................................
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'))