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

From version 2.1
edited by XWikiGuest
on 2026/03/11 20:04
Change comment: There is no comment for this version
To version 1.1
edited by XWikiGuest
on 2026/03/11 19:55
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -101,17 +101,7 @@
101 101   var NC_AUTH = 'Basic amFuX3JoZWJlcmdlbjpAWnMzUUwkJmZ4TVE=';
102 102  
103 103   var urlToFile = {}; // reverse map: URL -> filename
104 - var archiveMap = {}; // button index -> filename
105 105  
106 - function findArchive(url) {
107 - // Try exact match, with/without trailing slash, and without query string
108 - var variants = [url, url.replace(/\/$/, ''), url + '/', url.replace(/\?.*$/, '')];
109 - for (var i = 0; i < variants.length; i++) {
110 - if (urlToFile[variants[i]]) return urlToFile[variants[i]];
111 - }
112 - return null;
113 - }
114 -
115 115   // Load SingleFile index, then load bookmarks
116 116   fetch(INDEX_URL, { headers: { 'Authorization': NC_AUTH } })
117 117   .then(function(r) { return r.ok ? r.json() : {}; })
... ... @@ -136,15 +136,15 @@
136 136   var container = document.getElementById('ldsf-bookmarks');
137 137   var html = '<ul>';
138 138  
139 - (data.results || []).forEach(function(bm, idx) {
129 + (data.results || []).forEach(function(bm) {
140 140   var title = bm.title || bm.website_title || bm.url;
141 - var fname = findArchive(bm.url);
142 - if (fname) archiveCount++;
131 + var hasArchive = urlToFile[bm.url] || urlToFile[bm.url.replace(/\/$/, '')] || urlToFile[bm.url + '/'];
132 + if (hasArchive) archiveCount++;
143 143  
144 144   html += '<li>';
145 - if (fname) {
146 - html += '<button class="sf-btn" data-idx="' + idx + '" title="Archief bekijken">&#128196;</button>';
147 - archiveMap[idx] = fname;
135 + if (hasArchive) {
136 + var fname = urlToFile[bm.url] || urlToFile[bm.url.replace(/\/$/, '')] || urlToFile[bm.url + '/'];
137 + html += '<button class="sf-btn" onclick="ldsfShowArchive(\'' + encodeURIComponent(fname).replace(/'/g, "\\'") + '\', this)" title="Archief bekijken">&#128196;</button>';
148 148   }
149 149   html += '<a href="' + bm.url + '" target="_blank">' + title + '</a>';
150 150   html += '</li>';
... ... @@ -153,16 +153,6 @@
153 153   html += '</ul>';
154 154   container.innerHTML = html;
155 155   document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief';
156 -
157 - // Event delegation for archive buttons
158 - container.addEventListener('click', function(e) {
159 - var btn = e.target.closest('.sf-btn');
160 - if (!btn) return;
161 - var idx = btn.getAttribute('data-idx');
162 - if (idx !== null && archiveMap[idx]) {
163 - ldsfShowArchive(archiveMap[idx], btn);
164 - }
165 - });
166 166   })
167 167   .catch(function(err) {
168 168   document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message;
... ... @@ -170,7 +170,8 @@
170 170   }
171 171  
172 172   // Show archive in viewer panel
173 - window.ldsfShowArchive = function(filename, btn) {
153 + window.ldsfShowArchive = function(encodedFilename, btn) {
154 + var filename = decodeURIComponent(encodedFilename);
174 174   var container = document.getElementById('ldsf-viewer-container');
175 175   var frame = document.getElementById('ldsf-viewer-frame');
176 176   var titleEl = document.getElementById('ldsf-viewer-title');