cryptpad/customize.dist/pre-loading.js
2025-10-08 16:31:44 +02:00

67 lines
2.2 KiB
JavaScript

// SPDX-FileCopyrightText: 2023 XWiki CryptPad Team <contact@cryptpad.org> and contributors
//
// SPDX-License-Identifier: AGPL-3.0-or-later
(function () {
var logoPath = '/customize/CryptPad_logo_grey.svg';
var elem = document.createElement('div');
elem.setAttribute('id', 'placeholder');
elem.innerHTML = `
<div></div>
<div class="placeholder-message-container">
<p>Loading...</p>
</div>
<div id="placeholder-loading-footer">
<div class="placeholder-logo-container">
<img class="placeholder-logo" alt="" aria-hidden="true" src="${logoPath}"><span>CryptPad</span>
</div>
<div id="placeholder-loading-status">
<i data-lucide="lock" aria-hidden="true"></i>
<span>End-to-end encrypted</span>
</div>
</div>
`;
var key = 'CRYPTPAD_STORE|colortheme'; // handle outer
if (localStorage[key] && localStorage[key] === 'dark') {
elem.classList.add('dark-theme');
}
if (!localStorage[key] && localStorage[key+'_default'] && localStorage[key+'_default'] === 'dark') {
elem.classList.add('dark-theme');
}
var req;
try {
req = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
if ((req.theme || req.themeOS) === 'dark') { // handle inner
elem.classList.add('dark-theme');
}
} catch (e) {}
document.addEventListener('DOMContentLoaded', function() {
document.body.appendChild(elem);
window.CP_preloadingTime = +new Date();
// soft transition between inner and outer placeholders
if (req && req.time && (+new Date() - req.time > 2000)) {
try {
var logo = document.querySelector('.placeholder-logo-container');
var message = document.querySelector('.placeholder-message-container');
logo.style.opacity = 100;
message.style.opacity = 100;
logo.style.animation = 'none';
message.style.animation = 'none';
} catch (err) {}
}
// fallback if CSS animations not available
setTimeout(() => {
try {
document.querySelector('.placeholder-logo-container').style.opacity = 100;
document.querySelector('.placeholder-message-container').style.opacity = 100;
} catch (e) {}
}, 3000);
});
}());