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

From version 9.1
edited by XWikiGuest
on 2026/03/11 20:36
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
... ... @@ -78,7 +78,6 @@
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>
82 82   <div id="ldsf-status">Laden...</div>
83 83   <div id="ldsf-bookmarks"></div>
84 84   <div id="ldsf-viewer-container">
... ... @@ -91,99 +91,95 @@
91 91  </div>
92 92  
93 93  <script>
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 = {};
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;
103 103  
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 -}
99 + var WEBDAV_BASE = 'https://cloud.rhebergen.org/remote.php/dav/files/jan_rhebergen/SingleFile-Archives/';
100 + var INDEX_URL = WEBDAV_BASE + 'index.json';
101 + var NC_AUTH = 'Basic amFuX3JoZWJlcmdlbjpAWnMzUUwkJmZ4TVE=';
109 109  
110 -function ldsfOpen(idx) {
111 - var f = ldsf_archiveMap[idx];
112 - if (f) ldsfShowArchive(f);
113 -}
103 + var urlToFile = {}; // reverse map: URL -> filename
114 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 -}
105 + // Load SingleFile index, then load bookmarks
106 + fetch(INDEX_URL, { headers: { 'Authorization': NC_AUTH } })
107 + .then(function(r) { return r.ok ? r.json() : {}; })
108 + .then(function(index) {
109 + // Build reverse map: URL -> filename
110 + Object.keys(index).forEach(function(fname) {
111 + urlToFile[index[fname]] = fname;
112 + });
113 + loadBookmarks();
114 + })
115 + .catch(function() {
116 + loadBookmarks(); // Continue without index
117 + });
125 125  
126 -function ldsfCloseViewer() {
127 - document.getElementById('ldsf-viewer-container').style.display = 'none';
128 -}
119 + function loadBookmarks() {
120 + var apiUrl = LINKDING_URL + '?limit=' + LINKDING_COUNT + '&q=%23' + encodeURIComponent(LINKDING_TAG);
121 + fetch(apiUrl, { headers: { 'Authorization': 'Token ' + LINKDING_TOKEN } })
122 + .then(function(r) { return r.json(); })
123 + .then(function(data) {
124 + var total = data.count || 0;
125 + var archiveCount = 0;
126 + var container = document.getElementById('ldsf-bookmarks');
127 + var html = '<ul>';
129 129  
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 ul = document.createElement('ul');
129 + (data.results || []).forEach(function(bm) {
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++;
139 139  
140 - (data.results || []).forEach(function(bm) {
141 - var title = bm.title || bm.website_title || bm.url;
142 - var fname = ldsfFindArchive(bm.url);
143 - if (fname) archiveCount++;
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>';
138 + }
139 + html += '<a href="' + bm.url + '" target="_blank">' + title + '</a>';
140 + html += '</li>';
141 + });
144 144  
145 - var li = document.createElement('li');
143 + html += '</ul>';
144 + container.innerHTML = html;
145 + document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief';
146 + })
147 + .catch(function(err) {
148 + document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message;
149 + });
150 + }
146 146  
147 - if (fname) {
148 - var btn = document.createElement('button');
149 - btn.className = 'sf-btn';
150 - btn.title = 'Archief bekijken';
151 - btn.textContent = '\uD83D\uDCC4';
152 - btn.addEventListener('click', (function(f) {
153 - return function() { ldsfShowArchive(f); };
154 - })(fname));
155 - li.appendChild(btn);
156 - }
152 + // Show archive in viewer panel
153 + window.ldsfShowArchive = function(encodedFilename, btn) {
154 + var filename = decodeURIComponent(encodedFilename);
155 + var container = document.getElementById('ldsf-viewer-container');
156 + var frame = document.getElementById('ldsf-viewer-frame');
157 + var titleEl = document.getElementById('ldsf-viewer-title');
157 157  
158 - var a = document.createElement('a');
159 - a.href = bm.url;
160 - a.target = '_blank';
161 - a.textContent = title;
162 - li.appendChild(a);
163 - ul.appendChild(li);
164 - });
159 + // Toggle active button
160 + document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); });
161 + btn.classList.add('active');
165 165  
166 - container.innerHTML = '';
167 - container.appendChild(ul);
168 - document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief';
169 - })
170 - .catch(function(err) { document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message; });
171 -}
163 + titleEl.textContent = filename.replace(/\.html?$/i, '');
164 + container.style.display = 'block';
165 + frame.srcdoc = '<p style="padding:20px;color:#666">Laden...</p>';
172 172  
173 -// Debug test button
174 -document.getElementById('ldsf-test-btn').addEventListener('click', function() {
175 - alert('archiveMap: ' + JSON.stringify(ldsf_archiveMap) + '\nurlToFile: ' + JSON.stringify(ldsf_urlToFile));
176 -});
167 + fetch(WEBDAV_BASE + encodeURIComponent(filename), { headers: { 'Authorization': NC_AUTH } })
168 + .then(function(r) { return r.text(); })
169 + .then(function(html) {
170 + frame.srcdoc = html;
171 + })
172 + .catch(function(err) {
173 + frame.srcdoc = '<p style="padding:20px;color:red">Fout: ' + err.message + '</p>';
174 + });
175 + };
177 177  
178 -// Load index then bookmarks
179 -fetch(LDSF_WEBDAV + 'index.json', { headers: { 'Authorization': LDSF_AUTH } })
180 -.then(function(r) { return r.ok ? r.json() : {}; })
181 -.then(function(idx) {
182 - console.log('SingleFile index loaded:', idx);
183 - Object.keys(idx).forEach(function(f) { ldsf_urlToFile[idx[f]] = f; });
184 - ldsfLoadBookmarks();
185 -})
186 -.catch(function(err) { console.log('SingleFile index FAILED:', err); ldsfLoadBookmarks(); });
177 + window.ldsfCloseViewer = function() {
178 + document.getElementById('ldsf-viewer-container').style.display = 'none';
179 + document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); });
180 + };
181 +})();
187 187  </script>
188 188  {{/html}}
189 189