Skip to content

Commit

Permalink
ability to rename lightning tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
adamerstelle committed Apr 1, 2023
0 parents commit 527e61e
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 0 deletions.
42 changes: 42 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function replaceText(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) {
replaceText(child, replacementText);
}
}
}

function applyReplacement(replacementText) {
const targetTabs = document.querySelectorAll('.slds-context-bar .navItem a[href*="/pardot/"');
targetTabs.forEach((tab) => {
replaceText(tab, replacementText);
});
}

chrome.storage.sync.get('replacementText', (data) => {
const replacementText = data.replacementText || 'Pardot';
applyReplacement(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) => {
applyReplacement(replacementText);
});
}
});
});

observer.observe(document.body, {
childList: true,
subtree: true,
});
});
Binary file added images/icon-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"manifest_version": 3,
"name": "Pardot Replacer",
"version": "1.0",
"description": "Replace occurrences of 'Account Engagement' with 'Pardot'",
"permissions": ["activeTab", "storage"],
"icons": {
"16": "images/icon-16.png",
"32": "images/icon-32.png",
"48": "images/icon-48.png",
"128":"images/icon-128.png"
},
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/icon-16.png",
"32": "images/icon-32.png",
"48": "images/icon-48.png",
"128":"images/icon-128.png"
}
},
"content_scripts": [
{
"matches": ["*://*.lightning.force.com/*", "*://*.my.salesforce.com/*"],
"js": ["content.js"]
}
],
"options_page": "options.html"
}

81 changes: 81 additions & 0 deletions options.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 0;
}

.container {
max-width: 600px;
margin: 20px auto;
padding: 20px;
background-color: #ffffff;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}

h1 {
margin-top: 0;
margin-bottom: 20px;
font-size: 24px;
font-weight: 600;
color: #333333;
}

.form-group {
margin-bottom: 20px;
}

label {
display: block;
font-size: 14px;
font-weight: 600;
color: #666666;
margin-bottom: 5px;
}

input[type='text'] {
display: block;
width: 80%;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
}

input[type='text']:focus {
border-color: #66afe9;
outline: 0;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6);
}

.save-button {
display: inline-block;
padding: 6px 12px;
font-size: 14px;
font-weight: 400;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
color: #fff;
background-color: #5cb85c;
border-color: #4cae4c;
text-decoration: none;
}


.save-button:hover,
.save-button:focus,
.save-button:active {
background-color: #0056b3;
}
17 changes: 17 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="options.css">
<script src="options.js"></script>
</head>
<body>
<div class="container">
<h1>Pardot Replacer Options</h1>
<div class="form-group">
<label for="replacementText">Replacement Text:</label>
<input type="text" id="replacementText" />
</div>
<button id="saveButton" class="save-button">Save</button>
</div>
</body>
</html>
17 changes: 17 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
document.addEventListener('DOMContentLoaded', () => {
const replacementTextInput = document.getElementById('replacementText');
const saveButton = document.getElementById('saveButton');

// Load the saved replacement text
chrome.storage.sync.get('replacementText', (data) => {
replacementTextInput.value = data.replacementText || 'Pardot';
});

// Save the replacement text
saveButton.addEventListener('click', () => {
chrome.storage.sync.set({ replacementText: replacementTextInput.value }, () => {
alert('Replacement text saved to ' + replacementTextInput.value);
});
});
});

15 changes: 15 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
margin: 10px;
}
</style>
</head>
<body>
<h1>Pardot Replacer</h1>
<p>This extension replaces occurrences of "Account Engagement" with "Pardot" on the current webpage.</p>
</body>
</html>

0 comments on commit 527e61e

Please sign in to comment.