This repository was archived by the owner on Jan 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptContentBody.js
More file actions
98 lines (89 loc) · 3.41 KB
/
ScriptContentBody.js
File metadata and controls
98 lines (89 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import React, { useEffect, useState } from "react"
const ScriptContentBody = props => {
const [addScript, setAddScript] = useState(
props.script_content_ie_type.condition === "all_option" ||
props.script_content_ie_type.condition === "exclude_option"
? true
: false
)
useEffect(() => {
// console.log("addScript", addScript, props.body_script)
}, [addScript])
useEffect(() => {
let tmpAddScript =
props.script_content_ie_type.condition === "all_option" ||
props.script_content_ie_type.condition === "exclude_option"
? true
: false
let pathToIncludeExcludeSliced = []
let currPathSliced = props.currentSlug.split("/").filter(ll => ll !== "")
props.script_content_ie_type[`${props.script_content_ie_type.condition}`] &&
props.script_content_ie_type[
`${props.script_content_ie_type.condition}`
].paths
.sort()
.forEach(oo => {
pathToIncludeExcludeSliced = oo.split("/").filter(ll => ll !== "")
if (props.script_content_ie_type.condition === "include_option") {
if (tmpAddScript !== true) {
if (currPathSliced.length > 0) {
for (let ii = 0; ii < currPathSliced.length; ii++) {
if (
pathToIncludeExcludeSliced[ii] === "*" &&
pathToIncludeExcludeSliced[ii - 1] ===
currPathSliced[ii - 1]
) {
tmpAddScript = true
break
} else if (
pathToIncludeExcludeSliced[ii] === currPathSliced[ii] &&
ii === pathToIncludeExcludeSliced.length - 1
) {
tmpAddScript = true
} else if (
pathToIncludeExcludeSliced[ii] !== currPathSliced[ii]
) {
tmpAddScript = false
}
}
}
setAddScript(tmpAddScript)
}
} else if (
props.script_content_ie_type.condition === "exclude_option"
) {
if (tmpAddScript !== false) {
if (currPathSliced.length > 0) {
for (let ii = 0; ii < currPathSliced.length; ii++) {
if (
pathToIncludeExcludeSliced[ii] === "*" &&
pathToIncludeExcludeSliced[ii - 1] ===
currPathSliced[ii - 1]
) {
tmpAddScript = false
break
} else if (
pathToIncludeExcludeSliced[ii] === currPathSliced[ii] &&
ii === pathToIncludeExcludeSliced.length - 1
) {
tmpAddScript = false
} else if (
pathToIncludeExcludeSliced[ii] !== currPathSliced[ii]
) {
tmpAddScript = true
}
}
}
setAddScript(tmpAddScript)
}
} else {
setAddScript(tmpAddScript)
}
})
}, [props.exclude_paths, props.currentSlug])
let myScript = props.body_script ? props.body_script : ""
myScript = myScript.replace("<noscript>", "")
myScript = myScript.replace("</noscript>", "")
return addScript ? <noscript> {props.body_script}</noscript> : null
}
export default ScriptContentBody