2
0

🐛 (settings) Fix custom head code with noscript injection

This commit is contained in:
Baptiste Arnaud
2022-12-23 16:49:27 +01:00
parent 64cd31cf13
commit 2cdc2b43f5
3 changed files with 34 additions and 8 deletions

View File

@ -283,3 +283,23 @@ export const getViewerUrl = (props?: {
export const parseNumberWithCommas = (num: number) =>
num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
export const injectCustomHeadCode = (customHeadCode: string) => {
const headCodes = customHeadCode.split('</noscript>')
headCodes.forEach((headCode) => {
const [codeToInject, noScriptContentToInject] = headCode.split('<noscript>')
const fragment = document
.createRange()
.createContextualFragment(codeToInject)
document.head.append(fragment)
if (isNotDefined(noScriptContentToInject)) return
const noScriptElement = document.createElement('noscript')
const noScriptContentFragment = document
.createRange()
.createContextualFragment(noScriptContentToInject)
noScriptElement.append(noScriptContentFragment)
document.head.append(noScriptElement)
})
}