# HG changeset patch # User Guido Berhoerster # Date 1410371123 -7200 # Node ID e9ad4c625b7ab079f8b7508ff16fc75e8b21df7a # Parent 39c95b9826d26a4f639880d030ef93af1f762d0a Add bookmarklet for bookmarking Add a bookmarklet which gathers the URL and title of the current page which can then be copied and pasted into Booket diff -r 39c95b9826d2 -r e9ad4c625b7a booket.css --- a/booket.css Tue Sep 09 20:23:58 2014 +0200 +++ b/booket.css Wed Sep 10 19:45:23 2014 +0200 @@ -42,7 +42,8 @@ label, input[type="text"], input[type="file"], -input[type="url"] { +input[type="url"], +textarea { display: block; } @@ -129,22 +130,45 @@ margin: 1em 0 0 0; } +#bookmarklet, #keyboard-shortcuts { float: right; border: 1px solid #d3d7cf; border-radius: .5em; - background-color: #fbfbf9; padding: .5em; margin: 0 0 1em 1em; font-size: .75em; } +a#bookmarklet-link { + display: block; + margin: 1em 0 0 0; +} + +a#bookmarklet-link:link, +a#bookmarklet-link:visited, +a#bookmarklet-link:link:hover, +a#bookmarklet-link:link:focus, +a#bookmarklet-link:link:active, +a#bookmarklet-link:visited:hover, +a#bookmarklet-link:visited:focus, +a#bookmarklet-link:visited:active { + color: #000000; + text-decoration: underline; +} + +#bookmarklet h3, #keyboard-shortcuts h3 { font-size: 1em; text-align: center; margin: 0; } +#keyboard-shortcuts { + background-color: #fbfbf9; + clear: right; +} + #keyboard-shortcuts dl { margin: 1em 0 0 0; } diff -r 39c95b9826d2 -r e9ad4c625b7a booket.html --- a/booket.html Tue Sep 09 20:23:58 2014 +0200 +++ b/booket.html Wed Sep 10 19:45:23 2014 +0200 @@ -55,6 +55,9 @@ + @@ -63,6 +66,11 @@

Actions

+ + +
Load Bookmarks diff -r 39c95b9826d2 -r e9ad4c625b7a booket.js --- a/booket.js Tue Sep 09 20:23:58 2014 +0200 +++ b/booket.js Wed Sep 10 19:45:23 2014 +0200 @@ -24,6 +24,18 @@ (function () { 'use strict'; +var BOOKMARKLET_URI = + 'javascript:(function () {' + + '\'use strict\';' + + '' + + 'window.alert(\'Copy the following data and paste it into \' +' + + '\'Booket:\\n\\n\' + JSON.stringify({' + + '\'url\': document.URL,' + + '\'title\': document.title' + + '}));' + + '}) ();'; + + /* * utility stuff */ @@ -831,6 +843,7 @@ editorFormElement.querySelector('legend').textContent = 'Add Bookmark'; editorFormElement.querySelector('input:not([type="hidden"])').accessKey = 'a'; + editorFormElement.addEventListener('input', this); editorFormElement.addEventListener('click', this); editorFormElement.addEventListener('submit', this); editorFormElement.addEventListener('reset', this); @@ -841,6 +854,8 @@ saveFormElement.parentNode.insertBefore(newNode, saveFormElement.nextSibling); + + document.querySelector('a#bookmarklet-link').href = BOOKMARKLET_URI; }; extend(ActionsView, ObservableMixin); @@ -855,10 +870,31 @@ }; ActionsView.prototype.handleEvent = function (e) { + var bookmarkletData; + var parsedData; var tags = []; var i; switch (e.type) { + case 'input': + if (e.target.name === 'bookmarklet-import') { + // get rid of any preceding text + bookmarkletData = e.target.value.replace(/^[^{]*/, ''); + + try { + parsedData = JSON.parse(bookmarkletData); + } catch (exception) { + return; + } + + if (isString(parsedData.url) && parsedData.url !== '') { + e.target.form.elements.url.value = parsedData.url; + } + if (isString(parsedData.title) && parsedData.title !== '') { + e.target.form.elements.title.value = parsedData.title; + } + } + break; case 'click': if (e.target.name === 'more-tags') { e.preventDefault();