Wiki source code of Linkding + SingleFile Test
Version 11.1 by XWikiGuest on 2026/03/11 20:49
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | = Linkding + SingleFile Test = | ||
| 2 | |||
| 3 | Bookmarks met archief-viewer. Klik op het archief-icoon om de opgeslagen versie te bekijken. | ||
| 4 | |||
| 5 | {{html clean="false"}} | ||
| 6 | <style> | ||
| 7 | #ldsf-wrapper { | ||
| 8 | display: flex; | ||
| 9 | flex-direction: column; | ||
| 10 | gap: 0; | ||
| 11 | } | ||
| 12 | #ldsf-bookmarks { | ||
| 13 | color: #ebebeb; | ||
| 14 | } | ||
| 15 | #ldsf-bookmarks ul { | ||
| 16 | list-style: none; | ||
| 17 | padding: 0; | ||
| 18 | } | ||
| 19 | #ldsf-bookmarks li { | ||
| 20 | padding: 6px 12px; | ||
| 21 | background: #2b3e50; | ||
| 22 | border-left: 3px solid #df691a; | ||
| 23 | border-radius: 0 4px 4px 0; | ||
| 24 | margin: 4px 0; | ||
| 25 | display: flex; | ||
| 26 | align-items: center; | ||
| 27 | gap: 8px; | ||
| 28 | } | ||
| 29 | #ldsf-bookmarks li:hover { background: #3b4e60; } | ||
| 30 | #ldsf-bookmarks a { color: #5bc0de; text-decoration: none; } | ||
| 31 | #ldsf-bookmarks a:hover { color: #df691a; } | ||
| 32 | #ldsf-bookmarks .sf-btn { | ||
| 33 | cursor: pointer; | ||
| 34 | background: #4e5d6c; | ||
| 35 | border: none; | ||
| 36 | color: #5bc0de; | ||
| 37 | padding: 2px 8px; | ||
| 38 | border-radius: 3px; | ||
| 39 | font-size: 14px; | ||
| 40 | flex-shrink: 0; | ||
| 41 | } | ||
| 42 | #ldsf-bookmarks .sf-btn:hover { background: #df691a; color: #fff; } | ||
| 43 | #ldsf-bookmarks .sf-btn.active { background: #df691a; color: #fff; } | ||
| 44 | |||
| 45 | #ldsf-viewer-container { | ||
| 46 | display: none; | ||
| 47 | margin-top: 10px; | ||
| 48 | border: 1px solid #4e5d6c; | ||
| 49 | border-radius: 4px; | ||
| 50 | overflow: hidden; | ||
| 51 | background: #1a2a3a; | ||
| 52 | } | ||
| 53 | #ldsf-viewer-bar { | ||
| 54 | display: flex; | ||
| 55 | justify-content: space-between; | ||
| 56 | align-items: center; | ||
| 57 | padding: 6px 12px; | ||
| 58 | background: #2b3e50; | ||
| 59 | color: #6b7c8d; | ||
| 60 | font-size: 13px; | ||
| 61 | } | ||
| 62 | #ldsf-viewer-bar .close-btn { | ||
| 63 | cursor: pointer; | ||
| 64 | background: none; | ||
| 65 | border: none; | ||
| 66 | color: #d9534f; | ||
| 67 | font-size: 18px; | ||
| 68 | padding: 0 4px; | ||
| 69 | } | ||
| 70 | #ldsf-viewer-bar .close-btn:hover { color: #ff6b6b; } | ||
| 71 | #ldsf-viewer-frame { | ||
| 72 | width: 100%; | ||
| 73 | height: 70vh; | ||
| 74 | border: none; | ||
| 75 | background: #fff; | ||
| 76 | } | ||
| 77 | #ldsf-status { color: #6b7c8d; font-size: 13px; margin-bottom: 8px; } | ||
| 78 | </style> | ||
| 79 | |||
| 80 | <div id="ldsf-wrapper"> | ||
| 81 | <button id="ldsf-test-btn" style="background:#df691a;color:#fff;padding:8px 16px;border:none;border-radius:4px;cursor:pointer;margin-bottom:10px;">TEST KLIK</button> | ||
| 82 | <div id="ldsf-status">Laden...</div> | ||
| 83 | <div id="ldsf-bookmarks"></div> | ||
| 84 | <div id="ldsf-viewer-container"> | ||
| 85 | <div id="ldsf-viewer-bar"> | ||
| 86 | <span id="ldsf-viewer-title">...</span> | ||
| 87 | <button class="close-btn" onclick="ldsfCloseViewer()">×</button> | ||
| 88 | </div> | ||
| 89 | <iframe id="ldsf-viewer-frame" sandbox="allow-same-origin"></iframe> | ||
| 90 | </div> | ||
| 91 | </div> | ||
| 92 | |||
| 93 | <script> | ||
| 94 | var LDSF_LINKDING_URL = 'https://bookmarks.rhebergen.org/api/bookmarks/'; | ||
| 95 | var LDSF_TOKEN = '3b7443e0f84e2b2b269adebb96d7475e4a5e653e'; | ||
| 96 | var LDSF_TAG = 'Nuclear-&-Energy'; | ||
| 97 | var LDSF_COUNT = 20; | ||
| 98 | var LDSF_SHARE = 'eT2X9ttBHK5GoEY'; | ||
| 99 | var LDSF_WEBDAV = 'https://cloud.rhebergen.org/public.php/webdav/'; | ||
| 100 | var LDSF_AUTH = 'Basic ' + btoa(LDSF_SHARE + ':'); | ||
| 101 | var ldsf_urlToFile = {}; | ||
| 102 | var ldsf_archiveMap = {}; | ||
| 103 | |||
| 104 | function ldsfFindArchive(url) { | ||
| 105 | var v = [url, url.replace(/\/$/, ''), url + '/', url.replace(/\?.*$/, '')]; | ||
| 106 | for (var i = 0; i < v.length; i++) { if (ldsf_urlToFile[v[i]]) return ldsf_urlToFile[v[i]]; } | ||
| 107 | return null; | ||
| 108 | } | ||
| 109 | |||
| 110 | function ldsfOpen(idx) { | ||
| 111 | var f = ldsf_archiveMap[idx]; | ||
| 112 | if (f) ldsfShowArchive(f); | ||
| 113 | } | ||
| 114 | |||
| 115 | function ldsfShowArchive(filename) { | ||
| 116 | document.getElementById('ldsf-viewer-title').textContent = filename.replace(/\.html?$/i, ''); | ||
| 117 | document.getElementById('ldsf-viewer-container').style.display = 'block'; | ||
| 118 | var frame = document.getElementById('ldsf-viewer-frame'); | ||
| 119 | frame.srcdoc = '<p style="padding:20px;color:#666">Laden...</p>'; | ||
| 120 | fetch(LDSF_WEBDAV + encodeURIComponent(filename), { headers: { 'Authorization': LDSF_AUTH } }) | ||
| 121 | .then(function(r) { return r.text(); }) | ||
| 122 | .then(function(html) { frame.srcdoc = html; }) | ||
| 123 | .catch(function(err) { frame.srcdoc = '<p style="padding:20px;color:red">Fout: ' + err.message + '</p>'; }); | ||
| 124 | } | ||
| 125 | |||
| 126 | function ldsfCloseViewer() { | ||
| 127 | document.getElementById('ldsf-viewer-container').style.display = 'none'; | ||
| 128 | } | ||
| 129 | |||
| 130 | function ldsfLoadBookmarks() { | ||
| 131 | var apiUrl = LDSF_LINKDING_URL + '?limit=' + LDSF_COUNT + '&q=%23' + encodeURIComponent(LDSF_TAG); | ||
| 132 | fetch(apiUrl, { headers: { 'Authorization': 'Token ' + LDSF_TOKEN } }) | ||
| 133 | .then(function(r) { return r.json(); }) | ||
| 134 | .then(function(data) { | ||
| 135 | var total = data.count || 0; | ||
| 136 | var archiveCount = 0; | ||
| 137 | var container = document.getElementById('ldsf-bookmarks'); | ||
| 138 | var html = '<ul>'; | ||
| 139 | |||
| 140 | (data.results || []).forEach(function(bm, idx) { | ||
| 141 | var title = bm.title || bm.website_title || bm.url; | ||
| 142 | var fname = ldsfFindArchive(bm.url); | ||
| 143 | if (idx < 3) console.log('BM[' + idx + ']:', bm.url, '-> match:', fname); | ||
| 144 | if (fname) { archiveCount++; ldsf_archiveMap[String(idx)] = fname; } | ||
| 145 | html += '<li>'; | ||
| 146 | if (fname) html += '<span class="sf-btn" data-sfidx="' + idx + '" title="Archief bekijken">📄</span>'; | ||
| 147 | html += '<a href="' + bm.url + '" target="_blank">' + title + '</a></li>'; | ||
| 148 | }); | ||
| 149 | |||
| 150 | html += '</ul>'; | ||
| 151 | container.innerHTML = html; | ||
| 152 | document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief'; | ||
| 153 | }) | ||
| 154 | .catch(function(err) { document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message; }); | ||
| 155 | } | ||
| 156 | |||
| 157 | // Global click handler for archive buttons | ||
| 158 | document.addEventListener('click', function(e) { | ||
| 159 | var el = e.target; | ||
| 160 | if (el && el.getAttribute && el.getAttribute('data-sfidx') !== null) { | ||
| 161 | var idx = el.getAttribute('data-sfidx'); | ||
| 162 | console.log('Archive button clicked, idx:', idx, 'file:', ldsf_archiveMap[idx]); | ||
| 163 | if (ldsf_archiveMap[idx]) ldsfShowArchive(ldsf_archiveMap[idx]); | ||
| 164 | } | ||
| 165 | }, true); | ||
| 166 | |||
| 167 | // Debug test button | ||
| 168 | document.getElementById('ldsf-test-btn').addEventListener('click', function() { | ||
| 169 | alert('archiveMap: ' + JSON.stringify(ldsf_archiveMap) + '\nurlToFile: ' + JSON.stringify(ldsf_urlToFile)); | ||
| 170 | }); | ||
| 171 | |||
| 172 | // Load index then bookmarks | ||
| 173 | fetch(LDSF_WEBDAV + 'index.json', { headers: { 'Authorization': LDSF_AUTH } }) | ||
| 174 | .then(function(r) { return r.ok ? r.json() : {}; }) | ||
| 175 | .then(function(idx) { | ||
| 176 | console.log('SingleFile index loaded:', idx); | ||
| 177 | Object.keys(idx).forEach(function(f) { ldsf_urlToFile[idx[f]] = f; }); | ||
| 178 | ldsfLoadBookmarks(); | ||
| 179 | }) | ||
| 180 | .catch(function(err) { console.log('SingleFile index FAILED:', err); ldsfLoadBookmarks(); }); | ||
| 181 | </script> | ||
| 182 | {{/html}} |