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

From version 5.1
edited by XWikiGuest
on 2026/03/11 20:26
Change comment: There is no comment for this version
To version 11.1
edited by XWikiGuest
on 2026/03/11 20:49
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -78,6 +78,7 @@
78 78  </style>
79 79  
80 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>
81 81   <div id="ldsf-status">Laden...</div>
82 82   <div id="ldsf-bookmarks"></div>
83 83   <div id="ldsf-viewer-container">
... ... @@ -90,108 +90,93 @@
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;
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 = {};
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 + ':');
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 +}
103 103  
104 - var urlToFile = {}; // reverse map: URL -> filename
105 - var archiveMap = {}; // button index -> filename
110 +function ldsfOpen(idx) {
111 + var f = ldsf_archiveMap[idx];
112 + if (f) ldsfShowArchive(f);
113 +}
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 - }
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 +}
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;
123 - });
124 - loadBookmarks();
125 - })
126 - .catch(function() {
127 - loadBookmarks(); // Continue without index
128 - });
126 +function ldsfCloseViewer() {
127 + document.getElementById('ldsf-viewer-container').style.display = 'none';
128 +}
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>';
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 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++;
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">&#128196;</span>';
147 + html += '<a href="' + bm.url + '" target="_blank">' + title + '</a></li>';
148 + });
144 144  
145 - html += '<li>';
146 - if (fname) {
147 - archiveMap[idx] = fname;
148 - html += '<button class="sf-btn" onclick="ldsfOpen(' + idx + ')" title="Archief bekijken">&#128196;</button>';
149 - }
150 - html += '<a href="' + bm.url + '" target="_blank">' + title + '</a>';
151 - html += '</li>';
152 - });
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 +}
153 153  
154 - html += '</ul>';
155 - container.innerHTML = html;
156 - document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief';
157 - })
158 - .catch(function(err) {
159 - document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message;
160 - });
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]);
161 161   }
165 +}, true);
162 162  
163 - // Open archive by index
164 - window.ldsfOpen = function(idx) {
165 - var filename = archiveMap[idx];
166 - if (!filename) return;
167 - ldsfShowArchive(filename);
168 - };
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 +});
169 169  
170 - // Show archive in viewer panel
171 - window.ldsfShowArchive = function(filename) {
172 - var container = document.getElementById('ldsf-viewer-container');
173 - var frame = document.getElementById('ldsf-viewer-frame');
174 - var titleEl = document.getElementById('ldsf-viewer-title');
175 -
176 - titleEl.textContent = filename.replace(/\.html?$/i, '');
177 - container.style.display = 'block';
178 - frame.srcdoc = '<p style="padding:20px;color:#666">Laden...</p>';
179 -
180 - fetch(WEBDAV_BASE + encodeURIComponent(filename), { headers: { 'Authorization': NC_AUTH } })
181 - .then(function(r) { return r.text(); })
182 - .then(function(html) {
183 - frame.srcdoc = html;
184 - })
185 - .catch(function(err) {
186 - frame.srcdoc = '<p style="padding:20px;color:red">Fout: ' + err.message + '</p>';
187 - });
188 - };
189 -
190 - window.ldsfCloseViewer = function() {
191 - document.getElementById('ldsf-viewer-container').style.display = 'none';
192 - document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); });
193 - };
194 -})();
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(); });
195 195  </script>
196 196  {{/html}}
197 197