Skip to content

Commit f834de1

Browse files
author
Jacek Gębal
committed
Update cookie settings to use a shared cookie across pages.
1 parent 46afb53 commit f834de1

1 file changed

Lines changed: 15 additions & 22 deletions

File tree

docs/assets/topbar.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -293,28 +293,21 @@
293293
rewriteFeedbackLink();
294294
}
295295

296-
/* Re-set the mkdocs-material consent cookie at path=/ so it is shared across
297-
all versioned subdirectories. Without this the browser scopes it to the
298-
current version path (e.g. /v3.1.14/) and the banner reappears on every
299-
other version. Runs immediately so it beats Material's consent check. */
300-
/* Propagate mkdocs-material consent across versioned subdirectories.
301-
Each version stores consent in localStorage under its own base-path key
302-
(e.g. /utPLSQL/develop/.__consent). Copy a non-empty consent from any
303-
other version into the current version's key before Material checks it. */
304-
var CONSENT_SUFFIX = '.__consent';
305-
var currentConsentKey = location.pathname + CONSENT_SUFFIX;
306-
if (!localStorage.getItem(currentConsentKey)) {
307-
for (var i = 0; i < localStorage.length; i++) {
308-
var k = localStorage.key(i);
309-
if (k && k !== currentConsentKey && k.endsWith(CONSENT_SUFFIX)) {
310-
var val = localStorage.getItem(k);
311-
if (val && val !== '{}') {
312-
localStorage.setItem(currentConsentKey, val);
313-
break;
314-
}
315-
}
316-
}
317-
}
296+
/*This intercepts every localStorage.getItem/setItem call — no matter which version path Material constructs as the key,
297+
it always reads and writes /__consent. One consent covers all versions. */
298+
var _get = Storage.prototype.getItem;
299+
var _set = Storage.prototype.setItem;
300+
var SHARED_KEY = '/__consent';
301+
302+
Storage.prototype.getItem = function (key) {
303+
if (key && key.endsWith('.__consent')) return _get.call(this, SHARED_KEY);
304+
return _get.call(this, key);
305+
};
306+
307+
Storage.prototype.setItem = function (key, value) {
308+
if (key && key.endsWith('.__consent')) { _set.call(this, SHARED_KEY, value); return; }
309+
_set.call(this, key, value);
310+
};
318311

319312
/* Hide Material's built-in header controls immediately to prevent a flash
320313
where logo/palette appear before the topbar is painted. */

0 commit comments

Comments
 (0)