wallet-notice: MutationObserver so it lands on async-injected connect buttons
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+21
-11
@@ -7,16 +7,26 @@
|
|||||||
fetch('/api/public/config').then(function (r) { return r.json(); }).then(function (c) {
|
fetch('/api/public/config').then(function (r) { return r.json(); }).then(function (c) {
|
||||||
var msg = (c && c.walletNotice || '').trim();
|
var msg = (c && c.walletNotice || '').trim();
|
||||||
if (!msg) return;
|
if (!msg) return;
|
||||||
var btns = [].slice.call(document.querySelectorAll('button, a.btn'));
|
function attach() {
|
||||||
var targets = btns.filter(function (b) { return /connect|unlock/i.test(b.textContent || ''); });
|
var btns = [].slice.call(document.querySelectorAll('button, a.btn'));
|
||||||
if (!targets.length) return;
|
btns.filter(function (b) { return /connect|unlock/i.test(b.textContent || ''); }).forEach(function (btn) {
|
||||||
targets.forEach(function (btn) {
|
if (btn.dataset.wnDone) return; btn.dataset.wnDone = '1';
|
||||||
if (btn.dataset.wnDone) return; btn.dataset.wnDone = '1';
|
var n = document.createElement('div');
|
||||||
var n = document.createElement('div');
|
n.className = 'callout';
|
||||||
n.className = 'callout';
|
n.style.cssText = 'margin:0 0 12px;font-size:13px;line-height:1.5;border-color:rgba(243,190,67,.5)';
|
||||||
n.style.cssText = 'margin:0 0 12px;font-size:13px;line-height:1.5;border-color:rgba(243,190,67,.5)';
|
n.innerHTML = 'ℹ️ ' + msg; // admin-authored, same trust level as other config-injected copy
|
||||||
n.innerHTML = 'ℹ️ ' + msg; // admin-authored, same trust level as other config-injected copy
|
btn.parentNode.insertBefore(n, btn);
|
||||||
btn.parentNode.insertBefore(n, btn);
|
});
|
||||||
});
|
}
|
||||||
|
attach();
|
||||||
|
// Connect/unlock buttons on /my and /training are injected AFTER async
|
||||||
|
// data loads — watch the DOM so the notice still lands on them.
|
||||||
|
if (window.MutationObserver) {
|
||||||
|
var mo = new MutationObserver(function () { attach(); });
|
||||||
|
mo.observe(document.body, { childList: true, subtree: true });
|
||||||
|
setTimeout(function () { mo.disconnect(); }, 12000);
|
||||||
|
} else {
|
||||||
|
var t = 0, iv = setInterval(function () { attach(); if (++t > 12) clearInterval(iv); }, 800);
|
||||||
|
}
|
||||||
}).catch(function () {});
|
}).catch(function () {});
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user