Changes for page Linkding + SingleFile Archief
Last modified by XWikiGuest on 2026/03/11 21:04
Summary
-
Page properties (1 modified, 0 added, 0 removed)
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"> ... ... @@ -134,49 +134,49 @@ 134 134 var total = data.count || 0; 135 135 var archiveCount = 0; 136 136 var container = document.getElementById('ldsf-bookmarks'); 137 - var ul =document.createElement('ul');138 + var html = '<ul>'; 138 138 139 - (data.results || []).forEach(function(bm) { 140 + (data.results || []).forEach(function(bm, idx) { 140 140 var title = bm.title || bm.website_title || bm.url; 141 141 var fname = ldsfFindArchive(bm.url); 142 - if (fname) archiveCount++; 143 - 144 - var li = document.createElement('li'); 145 - 146 - if (fname) { 147 - var btn = document.createElement('button'); 148 - btn.className = 'sf-btn'; 149 - btn.title = 'Archief bekijken'; 150 - btn.textContent = '\uD83D\uDCC4'; 151 - btn.addEventListener('click', (function(f) { 152 - return function() { ldsfShowArchive(f); }; 153 - })(fname)); 154 - li.appendChild(btn); 155 - } 156 - 157 - var a = document.createElement('a'); 158 - a.href = bm.url; 159 - a.target = '_blank'; 160 - a.textContent = title; 161 - li.appendChild(a); 162 - ul.appendChild(li); 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>'; 163 163 }); 164 164 165 - container.innerHTML= '';166 - container. appendChild(ul);150 + html += '</ul>'; 151 + container.innerHTML = html; 167 167 document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief'; 168 168 }) 169 169 .catch(function(err) { document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message; }); 170 170 } 171 171 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 172 // Load index then bookmarks 173 173 fetch(LDSF_WEBDAV + 'index.json', { headers: { 'Authorization': LDSF_AUTH } }) 174 174 .then(function(r) { return r.ok ? r.json() : {}; }) 175 175 .then(function(idx) { 176 + console.log('SingleFile index loaded:', idx); 176 176 Object.keys(idx).forEach(function(f) { ldsf_urlToFile[idx[f]] = f; }); 177 177 ldsfLoadBookmarks(); 178 178 }) 179 -.catch(function() { ldsfLoadBookmarks(); }); 180 +.catch(function(err) { console.log('SingleFile index FAILED:', err); ldsfLoadBookmarks(); }); 180 180 </script> 181 181 {{/html}} 182 182