Fix token issue when saving scratchpad

This commit is contained in:
2026-01-09 09:44:08 +01:00
parent 6328523624
commit a704640ebc
2 changed files with 24 additions and 2 deletions

View File

@@ -294,10 +294,26 @@
el.textContent = msg || '';
}
function getSectok() {
function getSectok(root) {
// Prefer a token embedded with the rendered scratchpad.
try {
if (root && root.getAttribute) {
var t = String(root.getAttribute('data-sectok') || '').trim();
if (t) return t;
}
} catch (e) {}
// Fall back to DokuWiki's global JSINFO.
try {
if (window.JSINFO && window.JSINFO.sectok) return String(window.JSINFO.sectok);
} catch (e) {}
// Last resort: find any security token input on the page.
try {
var inp = document.querySelector('input[name="sectok"], input[name="securitytoken"]');
if (inp && inp.value) return String(inp.value);
} catch (e2) {}
return '';
}
@@ -333,7 +349,7 @@
params.set('pad', pad);
params.set('id', pageId);
params.set('text', text || '');
params.set('sectok', getSectok());
params.set('sectok', getSectok(root));
return window.fetch(endpoint, {
method: 'POST',