Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d7b3086

Browse files
committed
Make watermark button reappear if removed
1 parent 5822c4b commit d7b3086

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

packages/app/src/watermark-button.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ function isStandalone() {
5454
return !window.opener && window.parent === window;
5555
}
5656

57+
let interval;
5758
const createIframe = () => {
5859
if (!isStandalone()) {
5960
return;
6061
}
6162

6263
const iframe = document.createElement('iframe');
63-
iframe.setAttribute('id', 'open-sandbox');
64+
65+
const iframeId = `sb__open-sandbox${Math.floor(Math.random() * 100)}`;
66+
iframe.setAttribute('id', iframeId);
6467
const link = document.createElement('a');
6568
setIframeStyle(iframe);
6669

@@ -89,14 +92,24 @@ const createIframe = () => {
8992
childList: true,
9093
subtree: true,
9194
});
95+
96+
clearInterval(interval);
97+
interval = setInterval(() => {
98+
// Check every second whether the button is still there
99+
if (!document.getElementById(iframeId)) {
100+
createIframe();
101+
}
102+
}, 1000);
92103
};
93104

94105
document.body.appendChild(iframe);
95106
};
96-
window.addEventListener('load', () => {
97-
try {
107+
108+
try {
109+
setTimeout(() => {
98110
createIframe();
99-
} catch (e) {
100-
/* ignore */
101-
}
102-
});
111+
}, 250);
112+
} catch (e) {
113+
console.error(e);
114+
/* catch */
115+
}

0 commit comments

Comments
 (0)