From 0ff36a94fe8b3d3ca8f86b80ad3b53c6298db920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20I=C3=9Fbr=C3=BCcker?= Date: Sat, 16 Aug 2025 07:29:53 +0200 Subject: [PATCH] Add alternative bookmarklet that uses browser metadata (#1159) --- bookmarks/templates/bookmarks/bookmarklet.js | 4 +- .../bookmarks/bookmarklet_clientside.js | 25 +++++++++ .../templates/settings/integrations.html | 54 ++++++++++++++++--- docs/src/content/docs/troubleshooting.md | 8 +-- 4 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 bookmarks/templates/bookmarks/bookmarklet_clientside.js diff --git a/bookmarks/templates/bookmarks/bookmarklet.js b/bookmarks/templates/bookmarks/bookmarklet.js index 175415e..a36a189 100644 --- a/bookmarks/templates/bookmarks/bookmarklet.js +++ b/bookmarks/templates/bookmarks/bookmarklet.js @@ -1,7 +1,7 @@ (function () { - var bookmarkUrl = window.location; - var applicationUrl = '{{ application_url }}'; + const bookmarkUrl = window.location; + let applicationUrl = '{{ application_url }}'; applicationUrl += '?url=' + encodeURIComponent(bookmarkUrl); applicationUrl += '&auto_close'; diff --git a/bookmarks/templates/bookmarks/bookmarklet_clientside.js b/bookmarks/templates/bookmarks/bookmarklet_clientside.js new file mode 100644 index 0000000..d17c810 --- /dev/null +++ b/bookmarks/templates/bookmarks/bookmarklet_clientside.js @@ -0,0 +1,25 @@ +(function () { + const bookmarkUrl = window.location; + const title = + document.querySelector('title')?.textContent || + document + .querySelector(`meta[property='og:title']`) + ?.getAttribute('content') || + ''; + const description = + document + .querySelector(`meta[name='description']`) + ?.getAttribute('content') || + document + .querySelector(`meta[property='og:description']`) + ?.getAttribute(`content`) || + ''; + + let applicationUrl = '{{ application_url }}'; + applicationUrl += '?url=' + encodeURIComponent(bookmarkUrl); + applicationUrl += '&title=' + encodeURIComponent(title); + applicationUrl += '&description=' + encodeURIComponent(description); + applicationUrl += '&auto_close'; + + window.open(applicationUrl); +})(); diff --git a/bookmarks/templates/settings/integrations.html b/bookmarks/templates/settings/integrations.html index de01b0b..3b83a4b 100644 --- a/bookmarks/templates/settings/integrations.html +++ b/bookmarks/templates/settings/integrations.html @@ -25,15 +25,33 @@

The bookmarklet is an alternative, cross-browser way to quickly add new bookmarks without opening the linkding application first. Here's how it works:

-

Drag the following bookmarklet to your browser's toolbar:

- 📎 Add bookmark + +
+

Choose your preferred bookmarklet:

+ + +
+
+ 📎 Add bookmark + +
@@ -90,4 +108,28 @@

+ + {% endblock %} diff --git a/docs/src/content/docs/troubleshooting.md b/docs/src/content/docs/troubleshooting.md index 585b3d3..d99775d 100644 --- a/docs/src/content/docs/troubleshooting.md +++ b/docs/src/content/docs/troubleshooting.md @@ -13,11 +13,11 @@ To fix this, check the [reverse proxy setup documentation](/installation#reverse ## Automatically detected title and description are incorrect -linkding automatically fetches the title and description of the web page from the metadata in the HTML ``. This happens on the server, which can return different results than what you see in your browser, for example if a website uses JavaScript to dynamically change the title or description, or if a website requires login. +linkding automatically fetches the title and description of the web page from the metadata in the HTML ``. By default, this happens on the server, which can return different results than what you see in your browser, for example, if a website uses JavaScript to dynamically change the title or description, or if a website requires login. Alternatively, both the browser extension and the bookmarklet can use the metadata directly from the page you are currently viewing in your browser. Note that for some websites this can give worse results, as not all websites correctly update the metadata in `` while browsing the website (which is why fetching a fresh page on the server is still the default). -When using the linkding browser extension, you can enable the *Use browser metadata* option to use the title and description that your browser sees. This will override the server-fetched metadata. Note that for some websites this can give worse results, as not all websites correctly update the metadata in `` while browsing the website (which is why fetching a fresh page on the server is still the default). - -The bookmarklet currently does not have such an option. +To use the title and description that you see in your browser: +- When using the linkding browser extension, enable the *Use browser metadata* option in the options of the extension. +- When adding the bookmarklet, the respective settings page allows you to choose whether to detect title and description from the server or in the browser. ## Archiving fails for certain websites