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

From version 6.1
edited by XWikiGuest
on 2026/03/11 20:30
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
... ... @@ -90,74 +90,95 @@
90 90  </div>
91 91  
92 92  <script>
93 -var LDSF_LINKDING_URL = 'https://bookmarks.rhebergen.org/api/bookmarks/';
94 -var LDSF_TOKEN = '3b7443e0f84e2b2b269adebb96d7475e4a5e653e';
95 -var LDSF_TAG = 'Nuclear-&-Energy';
96 -var LDSF_COUNT = 20;
97 -var LDSF_SHARE = 'eT2X9ttBHK5GoEY';
98 -var LDSF_WEBDAV = 'https://cloud.rhebergen.org/public.php/webdav/';
99 -var LDSF_AUTH = 'Basic ' + btoa(LDSF_SHARE + ':');
100 -var ldsf_urlToFile = {};
101 -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;
102 102  
103 -function ldsfFindArchive(url) {
104 - var v = [url, url.replace(/\/$/, ''), url + '/', url.replace(/\?.*$/, '')];
105 - for (var i = 0; i < v.length; i++) { if (ldsf_urlToFile[v[i]]) return ldsf_urlToFile[v[i]]; }
106 - return null;
107 -}
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=';
108 108  
109 -function ldsfOpen(idx) {
110 - var f = ldsf_archiveMap[idx];
111 - if (f) ldsfShowArchive(f);
112 -}
103 + var urlToFile = {}; // reverse map: URL -> filename
113 113  
114 -function ldsfShowArchive(filename) {
115 - document.getElementById('ldsf-viewer-title').textContent = filename.replace(/\.html?$/i, '');
116 - document.getElementById('ldsf-viewer-container').style.display = 'block';
117 - var frame = document.getElementById('ldsf-viewer-frame');
118 - frame.srcdoc = '<p style="padding:20px;color:#666">Laden...</p>';
119 - fetch(LDSF_WEBDAV + encodeURIComponent(filename), { headers: { 'Authorization': LDSF_AUTH } })
120 - .then(function(r) { return r.text(); })
121 - .then(function(html) { frame.srcdoc = html; })
122 - .catch(function(err) { frame.srcdoc = '<p style="padding:20px;color:red">Fout: ' + err.message + '</p>'; });
123 -}
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 + });
124 124  
125 -function ldsfCloseViewer() {
126 - document.getElementById('ldsf-viewer-container').style.display = 'none';
127 -}
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>';
128 128  
129 -function ldsfLoadBookmarks() {
130 - var apiUrl = LDSF_LINKDING_URL + '?limit=' + LDSF_COUNT + '&q=%23' + encodeURIComponent(LDSF_TAG);
131 - fetch(apiUrl, { headers: { 'Authorization': 'Token ' + LDSF_TOKEN } })
132 - .then(function(r) { return r.json(); })
133 - .then(function(data) {
134 - var total = data.count || 0;
135 - var archiveCount = 0;
136 - var container = document.getElementById('ldsf-bookmarks');
137 - var html = '<ul>';
138 - (data.results || []).forEach(function(bm, idx) {
139 - var title = bm.title || bm.website_title || bm.url;
140 - var fname = ldsfFindArchive(bm.url);
141 - if (fname) { archiveCount++; ldsf_archiveMap[idx] = fname; }
142 - html += '<li>';
143 - if (fname) html += '<button class="sf-btn" onclick="ldsfOpen(' + idx + ')" title="Archief bekijken">&#128196;</button>';
144 - html += '<a href="' + bm.url + '" target="_blank">' + title + '</a></li>';
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++;
133 +
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 + });
142 +
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;
145 145   });
146 - html += '</ul>';
147 - container.innerHTML = html;
148 - document.getElementById('ldsf-status').textContent = total + ' bookmarks, ' + archiveCount + ' met archief';
149 - })
150 - .catch(function(err) { document.getElementById('ldsf-status').textContent = 'Fout: ' + err.message; });
151 -}
150 + }
152 152  
153 -// Load index then bookmarks
154 -fetch(LDSF_WEBDAV + 'index.json', { headers: { 'Authorization': LDSF_AUTH } })
155 -.then(function(r) { return r.ok ? r.json() : {}; })
156 -.then(function(idx) {
157 - Object.keys(idx).forEach(function(f) { ldsf_urlToFile[idx[f]] = f; });
158 - ldsfLoadBookmarks();
159 -})
160 -.catch(function() { ldsfLoadBookmarks(); });
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');
158 +
159 + // Toggle active button
160 + document.querySelectorAll('#ldsf-bookmarks .sf-btn').forEach(function(b) { b.classList.remove('active'); });
161 + btn.classList.add('active');
162 +
163 + titleEl.textContent = filename.replace(/\.html?$/i, '');
164 + container.style.display = 'block';
165 + frame.srcdoc = '<p style="padding:20px;color:#666">Laden...</p>';
166 +
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 + };
176 +
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 +})();
161 161  </script>
162 162  {{/html}}
163 163