Last modified by XWikiGuest on 2026/03/11 21:04

From version 3.1
edited by XWikiGuest
on 2026/03/11 20:17
Change comment: There is no comment for this version
To version 6.1
edited by XWikiGuest
on 2026/03/11 20:30
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -90,115 +90,74 @@
90 90  </div>
91 91  
92 92  <script>
93 -(function() {
94 - var LINKDING_URL = 'https://bookmarks.rhebergen.org/api/bookmarks/';
95 - var LINKDING_TOKEN = '3b7443e0f84e2b2b269adebb96d7475e4a5e653e';
96 - var LINKDING_TAG = 'Nuclear-&-Energy';
97 - var LINKDING_COUNT = 20;
93 +var LDSF_LINKDING_URL = 'https://bookmarks.rhebergen.org/api/bookmarks/';
94 +var LDSF_TOKEN = '3b7443e0f84e2b2b269adebb96d7475e4a5e653e';
95 +var LDSF_TAG = 'Nuclear-&-Energy';
96 +var LDSF_COUNT = 20;
97 +var LDSF_SHARE = 'eT2X9ttBHK5GoEY';
98 +var LDSF_WEBDAV = 'https://cloud.rhebergen.org/public.php/webdav/';
99 +var LDSF_AUTH = 'Basic ' + btoa(LDSF_SHARE + ':');
100 +var ldsf_urlToFile = {};
101 +var ldsf_archiveMap = {};
98 98  
99 - var SHARE_TOKEN = 'eT2X9ttBHK5GoEY';
100 - var WEBDAV_BASE = 'https://cloud.rhebergen.org/public.php/webdav/';
101 - var INDEX_URL = WEBDAV_BASE + 'index.json';
102 - var NC_AUTH = 'Basic ' + btoa(SHARE_TOKEN + ':');
103 +function ldsfFindArchive(url) {
104 + var v = [url, url.replace(/\/$/, ''), url + '/', url.replace(/\?.*$/, '')];
105 + for (var i = 0; i < v.length; i++) { if (ldsf_urlToFile[v[i]]) return ldsf_urlToFile[v[i]]; }
106 + return null;
107 +}
103 103  
104 - var urlToFile = {}; // reverse map: URL -> filename
105 - var archiveMap = {}; // button index -> filename
109 +function ldsfOpen(idx) {
110 + var f = ldsf_archiveMap[idx];
111 + if (f) ldsfShowArchive(f);
112 +}
106 106  
107 - function findArchive(url) {
108 - // Try exact match, with/without trailing slash, and without query string
109 - var variants = [url, url.replace(/\/$/, ''), url + '/', url.replace(/\?.*$/, '')];
110 - for (var i = 0; i < variants.length; i++) {
111 - if (urlToFile[variants[i]]) return urlToFile[variants[i]];
112 - }
113 - return null;
114 - }
114 +function ldsfShowArchive(filename) {
115 + document.getElementById('ldsf-viewer-title').textContent = filename.replace(/\.html?$/i, '');
116 + document.getElementById('ldsf-viewer-container').style.display = 'block';
117 + var frame = document.getElementById('ldsf-viewer-frame');
118 + frame.srcdoc = '<p style="padding:20px;color:#666">Laden...</p>';
119 + fetch(LDSF_WEBDAV + encodeURIComponent(filename), { headers: { 'Authorization': LDSF_AUTH } })
120 + .then(function(r) { return r.text(); })
121 + .then(function(html) { frame.srcdoc = html; })
122 + .catch(function(err) { frame.srcdoc = '<p style="padding:20px;color:red">Fout: ' + err.message + '</p>'; });
123 +}
115 115  
116 - // Load SingleFile index, then load bookmarks
117 - fetch(INDEX_URL, { headers: { 'Authorization': NC_AUTH } })
118 - .then(function(r) { return r.ok ? r.json() : {}; })
119 - .then(function(index) {
120 - // Build reverse map: URL -> filename
121 - Object.keys(index).forEach(function(fname) {
122 - urlToFile[index[fname]] = fname;
125 +function ldsfCloseViewer() {
126 + document.getElementById('ldsf-viewer-container').style.display = 'none';
127 +}
128 +
129 +function ldsfLoadBookmarks() {
130 + var apiUrl = LDSF_LINKDING_URL + '?limit=' + LDSF_COUNT + '&q=%23' + encodeURIComponent(LDSF_TAG);
131 + fetch(apiUrl, { headers: { 'Authorization': 'Token ' + LDSF_TOKEN } })
132 + .then(function(r) { return r.json(); })
133 + .then(function(data) {
134 + var total = data.count || 0;
135 + var archiveCount = 0;
136 + var container = document.getElementById('ldsf-bookmarks');
137 + var html = '<ul>';
138 + (data.results || []).forEach(function(bm, idx) {
139 + var title = bm.title || bm.website_title || bm.url;
140 + var fname = ldsfFindArchive(bm.url);
141 + if (fname) { archiveCount++; ldsf_archiveMap[idx] = fname; }
142 + html += '<li>';
143 + if (fname) html += '<button class="sf-btn" onclick="ldsfOpen(' + idx + ')" title="Archief bekijken">&#128196;</button>';
144 + html += '<a href="' + bm.url + '" target="_blank">' + title + '</a></li>';
123 123   });
124 - loadBookmarks();
146 + html += '</ul>';
147 + container.innerHTML = html;
148 + document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief';
125 125   })
126 - .catch(function() {
127 - loadBookmarks(); // Continue without index
128 - });
150 + .catch(function(err) { document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message; });
151 +}
129 129  
130 - function loadBookmarks() {
131 - var apiUrl = LINKDING_URL + '?limit=' + LINKDING_COUNT + '&q=%23' + encodeURIComponent(LINKDING_TAG);
132 - fetch(apiUrl, { headers: { 'Authorization': 'Token ' + LINKDING_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 = findArchive(bm.url);
143 - if (fname) archiveCount++;
144 -
145 - html += '<li>';
146 - if (fname) {
147 - html += '<button class="sf-btn" data-idx="' + idx + '" title="Archief bekijken">&#128196;</button>';
148 - archiveMap[idx] = fname;
149 - }
150 - html += '<a href="' + bm.url + '" target="_blank">' + title + '</a>';
151 - html += '</li>';
152 - });
153 -
154 - html += '</ul>';
155 - container.innerHTML = html;
156 - document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief';
157 -
158 - // Event delegation for archive buttons
159 - container.addEventListener('click', function(e) {
160 - var btn = e.target.closest('.sf-btn');
161 - if (!btn) return;
162 - var idx = btn.getAttribute('data-idx');
163 - if (idx !== null && archiveMap[idx]) {
164 - ldsfShowArchive(archiveMap[idx], btn);
165 - }
166 - });
167 - })
168 - .catch(function(err) {
169 - document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message;
170 - });
171 - }
172 -
173 - // Show archive in viewer panel
174 - window.ldsfShowArchive = function(filename, btn) {
175 - var container = document.getElementById('ldsf-viewer-container');
176 - var frame = document.getElementById('ldsf-viewer-frame');
177 - var titleEl = document.getElementById('ldsf-viewer-title');
178 -
179 - // Toggle active button
180 - document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); });
181 - btn.classList.add('active');
182 -
183 - titleEl.textContent = filename.replace(/\.html?$/i, '');
184 - container.style.display = 'block';
185 - frame.srcdoc = '<p style="padding:20px;color:#666">Laden...</p>';
186 -
187 - fetch(WEBDAV_BASE + encodeURIComponent(filename), { headers: { 'Authorization': NC_AUTH } })
188 - .then(function(r) { return r.text(); })
189 - .then(function(html) {
190 - frame.srcdoc = html;
191 - })
192 - .catch(function(err) {
193 - frame.srcdoc = '<p style="padding:20px;color:red">Fout: ' + err.message + '</p>';
194 - });
195 - };
196 -
197 - window.ldsfCloseViewer = function() {
198 - document.getElementById('ldsf-viewer-container').style.display = 'none';
199 - document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); });
200 - };
201 -})();
153 +// Load index then bookmarks
154 +fetch(LDSF_WEBDAV + 'index.json', { headers: { 'Authorization': LDSF_AUTH } })
155 +.then(function(r) { return r.ok ? r.json() : {}; })
156 +.then(function(idx) {
157 + Object.keys(idx).forEach(function(f) { ldsf_urlToFile[idx[f]] = f; });
158 + ldsfLoadBookmarks();
159 +})
160 +.catch(function() { ldsfLoadBookmarks(); });
202 202  </script>
203 203  {{/html}}
204 204