fix: inject js/css

This commit is contained in:
Gabe Yuan
2024-03-15 10:35:30 +08:00
parent 83e9c1dd97
commit 45127646e8
4 changed files with 28 additions and 11 deletions

View File

@@ -4,7 +4,7 @@ export const injectInlineJs = (code) => {
el.setAttribute("data-source", "KISS-Calendar injectInlineJs");
el.setAttribute("type", "text/javascript");
el.textContent = code;
document.body.appendChild(el);
document.body?.appendChild(el);
};
// Function to inject external JavaScript file
@@ -13,7 +13,7 @@ export const injectExternalJs = (src) => {
el.setAttribute("data-source", "KISS-Calendar injectExternalJs");
el.setAttribute("type", "text/javascript");
el.setAttribute("src", src);
document.body.appendChild(el);
document.body?.appendChild(el);
};
// Function to inject internal CSS code
@@ -21,7 +21,7 @@ export const injectInternalCss = (styles) => {
const el = document.createElement("style");
el.setAttribute("data-source", "KISS-Calendar injectInternalCss");
el.textContent = styles;
document.head.appendChild(el);
document.head?.appendChild(el);
};
// Function to inject external CSS file
@@ -31,5 +31,5 @@ export const injectExternalCss = (href) => {
el.setAttribute("rel", "stylesheet");
el.setAttribute("type", "text/css");
el.setAttribute("href", href);
document.head.appendChild(el);
document.head?.appendChild(el);
};