fix: minor painterro integration fixes

This commit is contained in:
_nderscore 2022-08-30 15:56:20 -04:00 committed by hlky
parent 3a376392b3
commit b647ecaa92

View File

@ -56,21 +56,35 @@ window.SD = (() => {
static fallback (image) { return [image, image]; }
static load () {
return new Promise((resolve, reject) => {
/* Ensure Painterro window is always on top */
const style = document.createElement('style');
style.setAttribute('type', 'text/css');
style.appendChild(document.createTextNode(`
.ptro-holder-wrapper {
z-index: 100;
}
`));
document.head.appendChild(style);
const scriptId = '__painterro-script';
if (document.getElementById(scriptId)) {
reject(new Error('Tried to load painterro script, but script tag already exists.'));
return;
}
const styleId = '__painterro-css-override';
if (!document.getElementById(styleId)) {
/* Ensure Painterro window is always on top */
const style = document.createElement('style');
style.id = styleId;
style.setAttribute('type', 'text/css');
style.appendChild(document.createTextNode(`
.ptro-holder-wrapper {
z-index: 100;
}
`));
document.head.appendChild(style);
}
const script = document.createElement('script');
script.id = '__painterro-script';
script.id = scriptId;
script.src = 'https://unpkg.com/painterro@1.2.78/build/painterro.min.js';
script.onload = () => resolve(true);
script.onerror = () => reject(false);
script.onerror = (e) => {
// remove self on error to enable reattempting load
document.head.removeChild(script);
reject(e);
};
document.head.appendChild(script);
});
}