-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
70 lines (61 loc) · 2.4 KB
/
content.js
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
// Extension code that runs on top level pages. Separate Javascript is used for handling iframes (Page Layout Editor)
var hasPardotReplaced=true; // makes sure that the iFrame code doesn't run at the top level layer
function replaceLightningTabText(node, replacementText) {
if (node.nodeType === Node.TEXT_NODE) {
if (node.textContent.includes("Account Engagement")) {
node.textContent = node.textContent.replace(/Account Engagement/g, replacementText);
}
else if(!node.textContent.includes(replacementText)) {
node.textContent = replacementText +' ' + node.textContent;
}
}
else {
for (let child of node.childNodes) {
replaceLightningTabText(child, replacementText);
}
}
}
function replaceFieldName(node, replacementText) {
if (node.nodeType === Node.TEXT_NODE) {
if (node.textContent.includes("Account Engagement")) {
node.textContent = node.textContent.replace(/Account Engagement/g, replacementText);
}
}
else {
for (let child of node.childNodes) {
replaceFieldName(child, replacementText);
}
}
}
function applyReplacements(replacementText) {
const targetTabs = document.querySelectorAll('.slds-context-bar .navItem a[href*="/pardot/"');
targetTabs.forEach((tab) => {
replaceLightningTabText(tab, replacementText);
});
const targetFields = document.querySelectorAll('.slds-form .slds-form-element__label');
targetFields.forEach((field) => {
replaceFieldName(field, replacementText);
});
const targetFieldsInPageLayoutEditor = document.querySelectorAll('#fieldTrough .item');
targetFieldsInPageLayoutEditor.forEach((field) => {
replaceFieldName(field, replacementText);
});
}
chrome.storage.local.get('replacementText', (data) => {
const replacementText = data.replacementText || 'Pardot';
applyReplacements(replacementText);
// Listen for any DOM updates
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.addedNodes && mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach((node) => {
applyReplacements(replacementText);
});
}
});
});
observer.observe(document.body, {
childList: true,
subtree: true,
});
});