Skip to content

Commit 3c5778b

Browse files
authored
Merge pull request #34 from prvashisht/fix-custom-companies-name
fix: Improved getCompanyName function and stored localStorage data on install
2 parents 6f1e78b + 0be2ce5 commit 3c5778b

File tree

3 files changed

+39
-16
lines changed

3 files changed

+39
-16
lines changed

content.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ const addSignatureToggle = async (messageActions) => {
8989
icon.src = chrome.runtime.getURL(`icons/${darkModePreference.matches ? 'dark' : 'light'}/icon32.png`);
9090
icon.alt = 'Toggle Signature';
9191
icon.style = 'width: 20px; height: 20px; margin: 0 0.5rem; transition: opacity 0.3s; position: relative; bottom: 0.2em;';
92-
const item = await chrome.storage.local.get(['linkedinsignature']);
93-
icon.style.opacity = item.linkedinsignature.messageSignEnabled ? 1 : 0.4;
92+
const { linkedinsignature } = await chrome.storage.local.get(['linkedinsignature']);
93+
if (!linkedinsignature) return;
94+
icon.style.opacity = linkedinsignature.messageSignEnabled ? 1 : 0.4;
9495
signatureToggle.appendChild(icon);
9596

9697
messageActions.appendChild(signatureToggle);
@@ -99,19 +100,21 @@ const addSignatureToggle = async (messageActions) => {
99100
const findCompanyName = (fullName) => {
100101
if (window.location.href.includes('linkedin.com/in/')) {
101102
const mainName = document.querySelector('main h1').textContent.trim();
102-
if (mainName === fullName) {
103-
const experiences = document.querySelector('section #experience').parentElement,
104-
latestCompany = experiences.querySelector('li'),
105-
latestCompanyName = latestCompany.querySelector('img').getAttribute('alt').split(' ').slice(0, -1).join(' ');
106-
107-
let latestTimeline = latestCompany.querySelector('.pvs-entity__caption-wrapper').textContent.trim();
108-
109-
const changedRoles = latestTimeline.indexOf(' - ') === -1; // displays "Full-time"
110-
if (changedRoles) latestTimeline = latestCompany.querySelector('.pvs-entity__sub-components li .pvs-entity__caption-wrapper').textContent.trim();
111-
112-
const isCurrentCompany = !latestTimeline.split(' - ')[1].split(' · ')[0].includes(' ');
113-
if (isCurrentCompany) return latestCompanyName;
114-
}
103+
if (mainName !== fullName) return;
104+
105+
const experienceTitleSelector = 'div.mr1 span[aria-hidden="true"]',
106+
experienceSubtitleSelector = 'span.t-14:not(.t-black--light):first-of-type span[aria-hidden="true"]',
107+
latestCompany = document.querySelector('section #experience').parentElement.querySelector('li'),
108+
changedRoles = latestCompany.querySelector('.pvs-entity__caption-wrapper').textContent.trim().indexOf(' · ') === -1,
109+
latestCompanyName = changedRoles ?
110+
latestCompany.querySelector(experienceTitleSelector).textContent.trim() :
111+
latestCompany.querySelector(experienceSubtitleSelector).textContent.trim().split(' · ')[0],
112+
latestTimeline = changedRoles ?
113+
latestCompany.querySelector('.pvs-entity__sub-components li .pvs-entity__caption-wrapper').textContent.trim() :
114+
latestCompany.querySelector('.pvs-entity__caption-wrapper').textContent.trim(),
115+
isCurrentCompany = !latestTimeline.split(' - ')[1].split(' · ')[0].includes(' ');
116+
117+
if (isCurrentCompany) return latestCompanyName;
115118
} else if (window.location.href.includes('linkedin.com/search/results/')) {
116119
let returnValue = null;
117120
document.querySelectorAll('div.mb1').forEach(result => {

popup/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ document.addEventListener('DOMContentLoaded', async () => {
1010
messagesTab = document.getElementById('messagesTab'),
1111
connectionsTab = document.getElementById('connectionsTab');
1212

13+
// TODO: move to a common file and import
1314
const defaultSignature = {
1415
messageSignEnabled: true,
1516
connectNoteSignEnabled: true,

service_worker.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
if (typeof browser === "undefined") {
2+
var browser = chrome;
3+
}
4+
15
chrome.runtime.onMessage.addListener((request) => {
26
if (request.type === "themeChange") {
37
let icon_paths = {
@@ -10,14 +14,27 @@ chrome.runtime.onMessage.addListener((request) => {
1014
}
1115
});
1216

17+
// TODO: move to a common file and import
18+
const defaultSignature = {
19+
messageSignEnabled: true,
20+
connectNoteSignEnabled: true,
21+
messageSignatures: [{
22+
name: "Default",
23+
text: "\nRegards"
24+
}],
25+
connectionSignatures: [{
26+
name: "Default",
27+
text: "\nRegards"
28+
}],
29+
};
1330
chrome.runtime.onInstalled.addListener(installInfo => {
1431
let installDate, updateDate;
1532
if (installInfo.reason === "install") {
1633
installDate = new Date();
1734
} else {
1835
updateDate = new Date().toISOString();
1936
}
20-
chrome.runtime.getPlatformInfo(platformInfo => {
37+
chrome.runtime.getPlatformInfo(async platformInfo => {
2138
let debugData = {
2239
...platformInfo,
2340
agent: navigator.userAgent,
@@ -34,5 +51,7 @@ chrome.runtime.onInstalled.addListener(installInfo => {
3451
.join("\n")
3552
);
3653
chrome.runtime.setUninstallURL(`https://pratyushvashisht.com/signaturesync/uninstall?utm_source=browser&utm_medium=extension&utm_campaign=uninstall&debugData=${encodedDebugData}`);
54+
55+
await browser.storage.local.set({ linkedinsignature: defaultSignature });
3756
});
3857
});

0 commit comments

Comments
 (0)