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

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

Summary

Details

Page properties
Content
... ... @@ -101,7 +101,17 @@
101 101   var NC_AUTH = 'Basic amFuX3JoZWJlcmdlbjpAWnMzUUwkJmZ4TVE=';
102 102  
103 103   var urlToFile = {}; // reverse map: URL -> filename
104 + var archiveMap = {}; // button index -> filename
104 104  
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 +
105 105   // Load SingleFile index, then load bookmarks
106 106   fetch(INDEX_URL, { headers: { 'Authorization': NC_AUTH } })
107 107   .then(function(r) { return r.ok ? r.json() : {}; })
... ... @@ -126,15 +126,15 @@
126 126   var container = document.getElementById('ldsf-bookmarks');
127 127   var html = '<ul>';
128 128  
129 - (data.results || []).forEach(function(bm) {
139 + (data.results || []).forEach(function(bm, idx) {
130 130   var title = bm.title || bm.website_title || bm.url;
131 - var hasArchive = urlToFile[bm.url] || urlToFile[bm.url.replace(/\/$/, '')] || urlToFile[bm.url + '/'];
132 - if (hasArchive) archiveCount++;
141 + var fname = findArchive(bm.url);
142 + if (fname) archiveCount++;
133 133  
134 134   html += '<li>';
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>';
145 + if (fname) {
146 + html += '<button class="sf-btn" data-idx="' + idx + '" title="Archief bekijken">&#128196;</button>';
147 + archiveMap[idx] = fname;
138 138   }
139 139   html += '<a href="' + bm.url + '" target="_blank">' + title + '</a>';
140 140   html += '</li>';
... ... @@ -143,6 +143,16 @@
143 143   html += '</ul>';
144 144   container.innerHTML = html;
145 145   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 + });
146 146   })
147 147   .catch(function(err) {
148 148   document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message;
... ... @@ -150,8 +150,7 @@
150 150   }
151 151  
152 152   // Show archive in viewer panel
153 - window.ldsfShowArchive = function(encodedFilename, btn) {
154 - var filename = decodeURIComponent(encodedFilename);
173 + window.ldsfShowArchive = function(filename, btn) {
155 155   var container = document.getElementById('ldsf-viewer-container');
156 156   var frame = document.getElementById('ldsf-viewer-frame');
157 157   var titleEl = document.getElementById('ldsf-viewer-title');