diff --git a/bookmarks/models.py b/bookmarks/models.py
index 4efa7af..5821ff6 100644
--- a/bookmarks/models.py
+++ b/bookmarks/models.py
@@ -75,7 +75,9 @@ class BookmarkForm(forms.ModelForm):
required=False)
description = forms.CharField(required=False,
widget=forms.Textarea())
+ # Hidden field that determines whether to close window/tab after saving the bookmark
+ auto_close = forms.CharField(required=False)
class Meta:
model = Bookmark
- fields = ['url', 'tag_string', 'title', 'description']
+ fields = ['url', 'tag_string', 'title', 'description', 'auto_close']
diff --git a/bookmarks/templates/bookmarks/bookmarklet.html b/bookmarks/templates/bookmarks/bookmarklet.html
new file mode 100644
index 0000000..91eaf64
--- /dev/null
+++ b/bookmarks/templates/bookmarks/bookmarklet.html
@@ -0,0 +1,24 @@
+{% extends "bookmarks/layout.html" %}
+
+{% block content %}
+
+
+
+ The bookmarklet is a quick way to add new bookmarks without opening the linkding application
+ first. Here's how it works:
+
+ - Drag the bookmarklet below into your browsers bookmark bar / toolbar
+ - Open the website that you want to bookmark
+ - Click the bookmarklet in your browsers toolbar
+ - linkding opens in a new window or tab and allows you to add a bookmark for the site
+ - After saving the bookmark the linkding window closes and you are back on your website
+
+ Drag the following bookmarklet to your browsers toolbar:
+ 📎 Add bookmark
+
+
+{% endblock %}
+
diff --git a/bookmarks/templates/bookmarks/bookmarklet.js b/bookmarks/templates/bookmarks/bookmarklet.js
new file mode 100644
index 0000000..ba0ab08
--- /dev/null
+++ b/bookmarks/templates/bookmarks/bookmarklet.js
@@ -0,0 +1,9 @@
+(function() {
+ var bookmarkUrl = window.location;
+ var applicationUrl = '{{ application_url }}';
+
+ applicationUrl += '?url=' + bookmarkUrl;
+ applicationUrl += '&auto_close';
+
+ window.open(applicationUrl);
+})();
diff --git a/bookmarks/templates/bookmarks/close.html b/bookmarks/templates/bookmarks/close.html
new file mode 100644
index 0000000..f560857
--- /dev/null
+++ b/bookmarks/templates/bookmarks/close.html
@@ -0,0 +1,9 @@
+{% extends "bookmarks/layout.html" %}
+
+{% block content %}
+
+ You can now close this window.
+{% endblock %}
+
diff --git a/bookmarks/templates/bookmarks/form.html b/bookmarks/templates/bookmarks/form.html
index bede7c9..767a6b5 100644
--- a/bookmarks/templates/bookmarks/form.html
+++ b/bookmarks/templates/bookmarks/form.html
@@ -2,6 +2,7 @@
diff --git a/bookmarks/templates/bookmarks/layout.html b/bookmarks/templates/bookmarks/layout.html
index 1f24076..2c16ce3 100644
--- a/bookmarks/templates/bookmarks/layout.html
+++ b/bookmarks/templates/bookmarks/layout.html
@@ -22,7 +22,7 @@
{% if request.user.is_authenticated %}
diff --git a/bookmarks/templates/bookmarks/new.html b/bookmarks/templates/bookmarks/new.html
index b7ee771..5cbc9fa 100644
--- a/bookmarks/templates/bookmarks/new.html
+++ b/bookmarks/templates/bookmarks/new.html
@@ -8,7 +8,7 @@
New bookmark
diff --git a/bookmarks/templatetags/bookmarks.py b/bookmarks/templatetags/bookmarks.py
index 5ba6020..29c55a5 100644
--- a/bookmarks/templatetags/bookmarks.py
+++ b/bookmarks/templatetags/bookmarks.py
@@ -8,9 +8,10 @@ register = template.Library()
@register.inclusion_tag('bookmarks/form.html', name='bookmark_form')
-def bookmark_form(form: BookmarkForm):
+def bookmark_form(form: BookmarkForm, auto_close: bool = False):
return {
'form': form,
+ 'auto_close': auto_close
}
diff --git a/bookmarks/urls.py b/bookmarks/urls.py
index df08386..dcfea83 100644
--- a/bookmarks/urls.py
+++ b/bookmarks/urls.py
@@ -11,8 +11,10 @@ urlpatterns = [
# Bookmarks
path('bookmarks', views.bookmarks_index, name='index'),
path('bookmarks/new', views.bookmarks_new, name='new'),
+ path('bookmarks/close', views.bookmarks_close, name='close'),
path('bookmarks//edit', views.bookmarks_edit, name='edit'),
path('bookmarks//remove', views.bookmarks_remove, name='remove'),
+ path('bookmarklet', views.bookmarks_bookmarklet, name='bookmarklet'),
# Settings
path('settings', views.settings_index, name='settings_index'),
path('settings/import', views.settings_bookmark_import, name='settings_import'),
diff --git a/bookmarks/views/bookmarks.py b/bookmarks/views/bookmarks.py
index 9694e41..a3946bb 100644
--- a/bookmarks/views/bookmarks.py
+++ b/bookmarks/views/bookmarks.py
@@ -35,16 +35,27 @@ def bookmarks_index(request):
@login_required
def bookmarks_new(request):
+ initial_url = request.GET.get('url')
+ initial_auto_close = 'auto_close' in request.GET
+
if request.method == 'POST':
form = BookmarkForm(request.POST)
+ auto_close = form.data['auto_close']
if form.is_valid():
current_user = request.user
create_bookmark(form, current_user)
- return HttpResponseRedirect(reverse('bookmarks:index'))
+ if auto_close:
+ return HttpResponseRedirect(reverse('bookmarks:close'))
+ else:
+ return HttpResponseRedirect(reverse('bookmarks:index'))
else:
form = BookmarkForm()
+ if initial_url:
+ form.initial['url'] = initial_url
+ if initial_auto_close:
+ form.initial['auto_close'] = 'true'
- return render(request, 'bookmarks/new.html', {'form': form})
+ return render(request, 'bookmarks/new.html', {'form': form, 'auto_close': initial_auto_close})
@login_required
@@ -67,3 +78,15 @@ def bookmarks_remove(request, bookmark_id: int):
bookmark = Bookmark.objects.get(pk=bookmark_id)
bookmark.delete()
return HttpResponseRedirect(reverse('bookmarks:index'))
+
+
+@login_required
+def bookmarks_bookmarklet(request):
+ return render(request, 'bookmarks/bookmarklet.html', {
+ 'application_url': request.build_absolute_uri("/bookmarks/new")
+ })
+
+
+@login_required
+def bookmarks_close(request):
+ return render(request, 'bookmarks/close.html')