From 6a757e240e74b46d8c9d100882e50b5c7bc2d823 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Wed, 24 May 2017 08:37:33 +0200 Subject: A bookmarklet for bookmarks has been added. --- src/web/templates/edit_bookmark.html | 6 ++++++ src/web/views/bookmark.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'src/web') diff --git a/src/web/templates/edit_bookmark.html b/src/web/templates/edit_bookmark.html index 384e641c..573e3d7a 100644 --- a/src/web/templates/edit_bookmark.html +++ b/src/web/templates/edit_bookmark.html @@ -62,5 +62,11 @@ + {% if action == "Add a bookmark" %} +
+

{{ _('You can add a bookmark with a bookmarklet. Drag the following button to your browser bookmarks.') }}

+ {{ _('Manage your bookmarks using Newspipe', bookmarklet='javascript:window.location="%s?href="+encodeURIComponent(document.location)' % url_for('bookmark.bookmarklet', _external=True)) }} +
+ {% endif %} {% endblock %} diff --git a/src/web/views/bookmark.py b/src/web/views/bookmark.py index 70d9bf9a..546f4996 100644 --- a/src/web/views/bookmark.py +++ b/src/web/views/bookmark.py @@ -96,3 +96,31 @@ def delete(bookmark_id=None): flash(gettext("Bookmark %(bookmark_name)s successfully deleted.", bookmark_name=bookmark.title), 'success') return redirect(redirect_url()) + + +@bookmark_bp.route('/bookmarklet', methods=['GET', 'POST']) +@login_required +def bookmarklet(): + bookmark_contr = BookmarkController(current_user.id) + href = (request.args if request.method == 'GET' else request.form)\ + .get('href', None) + if not href: + flash(gettext("Couldn't add bookmark: url missing."), "error") + raise BadRequest("url is missing") + + bookmark_exists = bookmark_contr.read(**{'href': href}).all() + if bookmark_exists: + flash(gettext("Couldn't add bookmark: bookmark already exists."), + "warning") + return redirect(url_for('bookmark.form', + bookmark_id=bookmark_exists[0].id)) + + bookmark_attr = {'href': href, + 'description': '', + 'title': href, + 'shared': False, + 'to_read': True} + + new_bookmark = bookmark_contr.create(**bookmark_attr) + flash(gettext('Bookmark successfully created.'), 'success') + return redirect(url_for('bookmark.form', bookmark_id=new_bookmark.id)) -- cgit