Linkding + SingleFile Test

Version 4.1 by XWikiGuest on 2026/03/11 20:22
Warning
For security reasons, the document is displayed in restricted mode as it is not the current version. There may be differences and errors due to this.

Linkding + SingleFile Test

Bookmarks met archief-viewer. Klik op het archief-icoon om de opgeslagen versie te bekijken.

#ldsf-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0;
}
#ldsf-bookmarks {
  color: #ebebeb;
}
#ldsf-bookmarks ul {
  list-style: none;
  padding: 0;
}
#ldsf-bookmarks li {
  padding: 6px 12px;
  background: #2b3e50;
  border-left: 3px solid #df691a;
  border-radius: 0 4px 4px 0;
  margin: 4px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
#ldsf-bookmarks li:hover { background: #3b4e60; }
#ldsf-bookmarks a { color: #5bc0de; text-decoration: none; }
#ldsf-bookmarks a:hover { color: #df691a; }
#ldsf-bookmarks .sf-btn {
  cursor: pointer;
  background: #4e5d6c;
  border: none;
  color: #5bc0de;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 14px;
  flex-shrink: 0;
}
#ldsf-bookmarks .sf-btn:hover { background: #df691a; color: #fff; }
#ldsf-bookmarks .sf-btn.active { background: #df691a; color: #fff; }

#ldsf-viewer-container {
  display: none;
  margin-top: 10px;
  border: 1px solid #4e5d6c;
  border-radius: 4px;
  overflow: hidden;
  background: #1a2a3a;
}
#ldsf-viewer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: #2b3e50;
  color: #6b7c8d;
  font-size: 13px;
}
#ldsf-viewer-bar .close-btn {
  cursor: pointer;
  background: none;
  border: none;
  color: #d9534f;
  font-size: 18px;
  padding: 0 4px;
}
#ldsf-viewer-bar .close-btn:hover { color: #ff6b6b; }
#ldsf-viewer-frame {
  width: 100%;
  height: 70vh;
  border: none;
  background: #fff;
}
#ldsf-status { color: #6b7c8d; font-size: 13px; margin-bottom: 8px; }
Laden...
...
(function() {
  var LINKDING_URL = 'https://bookmarks.rhebergen.org/api/bookmarks/';
  var LINKDING_TOKEN = '3b7443e0f84e2b2b269adebb96d7475e4a5e653e';
  var LINKDING_TAG = 'Nuclear-&-Energy';
  var LINKDING_COUNT = 20;

  var SHARE_TOKEN = 'eT2X9ttBHK5GoEY';
  var WEBDAV_BASE = 'https://cloud.rhebergen.org/public.php/webdav/';
  var INDEX_URL = WEBDAV_BASE + 'index.json';
  var NC_AUTH = 'Basic ' + btoa(SHARE_TOKEN + ':');

  var urlToFile = {};  // reverse map: URL -> filename
  var archiveMap = {}; // button index -> filename

  function findArchive(url) {
    // Try exact match, with/without trailing slash, and without query string
    var variants = [url, url.replace(/\/$/, ''), url + '/', url.replace(/\?.*$/, '')];
    for (var i = 0; i < variants.length; i++) {
      if (urlToFile[variants[i]]) return urlToFile[variants[i]];
    }
    return null;
  }

  // Load SingleFile index, then load bookmarks
  fetch(INDEX_URL, { headers: { 'Authorization': NC_AUTH } })
  .then(function(r) { return r.ok ? r.json() : {}; })
  .then(function(index) {
    // Build reverse map: URL -> filename
    Object.keys(index).forEach(function(fname) {
      urlToFile[index[fname]] = fname;
    });
    loadBookmarks();
  })
  .catch(function() {
    loadBookmarks();  // Continue without index
  });

  function loadBookmarks() {
    var apiUrl = LINKDING_URL + '?limit=' + LINKDING_COUNT + '&q=%23' + encodeURIComponent(LINKDING_TAG);
    fetch(apiUrl, { headers: { 'Authorization': 'Token ' + LINKDING_TOKEN } })
    .then(function(r) { return r.json(); })
    .then(function(data) {
      var total = data.count || 0;
      var archiveCount = 0;
      var container = document.getElementById('ldsf-bookmarks');
      var html = '
  • '; (data.results || []).forEach(function(bm, idx) { var title = bm.title || bm.website_title || bm.url; var fname = findArchive(bm.url); if (fname) archiveCount++; html += '
  • '; if (fname) { html += ''; archiveMap[idx] = fname; } html += '' + title + ''; html += ''; }); html += '
'; container.innerHTML = html; document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief'; // Bind click handlers directly to buttons var buttons = container.querySelectorAll('.sf-btn'); for (var b = 0; b < buttons.length; b++) { (function(btn) { var idx = btn.getAttribute('data-idx'); btn.addEventListener('click', function(ev) { ev.preventDefault(); ev.stopPropagation(); if (archiveMap[idx]) { ldsfShowArchive(archiveMap[idx], btn); } }); })(buttons[b]); } }) .catch(function(err) { document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message; }); } // Show archive in viewer panel window.ldsfShowArchive = function(filename, btn) { var container = document.getElementById('ldsf-viewer-container'); var frame = document.getElementById('ldsf-viewer-frame'); var titleEl = document.getElementById('ldsf-viewer-title'); // Toggle active button document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); }); btn.classList.add('active'); titleEl.textContent = filename.replace(/\.html?$/i, ''); container.style.display = 'block'; frame.srcdoc = '

Laden...

'; fetch(WEBDAV_BASE + encodeURIComponent(filename), { headers: { 'Authorization': NC_AUTH } }) .then(function(r) { return r.text(); }) .then(function(html) { frame.srcdoc = html; }) .catch(function(err) { frame.srcdoc = '

Fout: ' + err.message + '

'; }); }; window.ldsfCloseViewer = function() { document.getElementById('ldsf-viewer-container').style.display = 'none'; document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); }); }; })();