Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,46 @@
|
||||
import { useEffect } from "react";
|
||||
|
||||
interface ScriptInjectorProps {
|
||||
scripts?: {
|
||||
head: string | null;
|
||||
body: string | null;
|
||||
};
|
||||
}
|
||||
|
||||
const ScriptInjector = ({ scripts }: ScriptInjectorProps) => {
|
||||
useEffect(() => {
|
||||
if (scripts?.head) {
|
||||
const headDiv = document.createElement("div");
|
||||
headDiv.innerHTML = scripts.head;
|
||||
Array.from(headDiv.childNodes).forEach((node) => {
|
||||
if (node.nodeType === Node.ELEMENT_NODE) {
|
||||
const script = document.createElement("script");
|
||||
Array.from((node as Element).attributes).forEach((attr) => {
|
||||
script.setAttribute(attr.name, attr.value);
|
||||
});
|
||||
script.innerHTML = (node as Element).innerHTML;
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (scripts?.body) {
|
||||
const bodyDiv = document.createElement("div");
|
||||
bodyDiv.innerHTML = scripts.body;
|
||||
Array.from(bodyDiv.childNodes).forEach((node) => {
|
||||
if (node.nodeType === Node.ELEMENT_NODE) {
|
||||
const script = document.createElement("script");
|
||||
Array.from((node as Element).attributes).forEach((attr) => {
|
||||
script.setAttribute(attr.name, attr.value);
|
||||
});
|
||||
script.innerHTML = (node as Element).innerHTML;
|
||||
document.body.appendChild(script);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, [scripts]);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export default ScriptInjector;
|
||||
Reference in new issue
Block a user