-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
147 lines (129 loc) · 4.35 KB
/
main.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const loopSite = setInterval(() => {
const { pathname: path, href: url, hostname } = window.location;
// Clean up notification count in title
document.title = document.title.replace(/\s*\(\d+\)/g, "");
navigation();
// Handle different pages
if (path === "/feed/") handleFeed();
else if (path.includes("mynetwork")) handleMyNetwork();
else if (
url.match(
/^https:\/\/www\.linkedin\.com\/in\/[a-zA-Z0-9-%]+-?[a-zA-Z0-9]*\/?$/
)
) {
profile();
} else if (path === "/groups/") handleGroups();
else if (path === "/events/") handleEvents();
else if (
hostname === "www.linkedin.com" &&
path.startsWith("/notifications")
) {
window.location.href = "https://www.linkedin.com/";
} else if (
path.match(
/^\/in\/[a-zA-Z0-9-%]+-?[a-zA-Z0-9]*\/(details\/(interests|languages|skills|projects|certifications)|recent-activity\/all)\/?(\?.*)?$/
)
) {
// If the URL matches any of the listed patterns
console.log("Matched LinkedIn details page");
const adsWidget = document.querySelector(
"aside[aria-label='Ads and widget recommendations']"
);
if (adsWidget) {
adsWidget.style.display = "none";
}
// People you may know or want to follow
const interested = document.querySelector("aside[aria-label='Interests']");
if (interested) {
interested.style.display = "none";
}
} else if (
path.match(
/^\/in\/[a-zA-Z0-9-%]+-?[a-zA-Z0-9]*\/recent-activity\/(comments|images|reactions)\/?$/
)
) {
console.log("Matched LinkedIn recent activity page");
// People you may know or want to follow
const interested = document.querySelector("aside[aria-label='Interests']");
if (interested) {
interested.style.display = "none";
}
}
// Check toggle state and handle additional cases
chrome.storage.local.get(["toggleState"], ({ toggleState = false }) => {
const toggleActive = toggleState;
// Company posts
if (/\/company\/.*?\/posts\//.test(path)) {
if (toggleActive) handleCompanyPosts();
else window.location.href = "https://linkedin.com";
}
// Company page
if (/\/company\//.test(path))
hideElement(".scaffold-layout__aside[aria-label='Advertisement']");
// Recent activity
if (
/^\/in\/[a-zA-Z0-9-]+\/recent-activity\/(comments|reactions|all)\/$/.test(
path
)
) {
if (toggleActive) handleRecentActivity();
else window.location.href = "https://linkedin.com";
}
// Search results
if (/^\/search\/results\/all/.test(path)) {
hideElement(".scaffold-layout__aside[aria-label='Search suggestions']");
}
});
}, 1000);
function handleEvents() {
const main = document.querySelector("main");
if (main) {
// Get the third child (index 2)
const thirdChild = main.children[2];
if (thirdChild) {
// Remove the third child element
main.removeChild(thirdChild);
}
}
}
function handleFeed() {
const mainElement = document.querySelector("main[aria-label='Main Feed']");
if (mainElement?.children[1])
mainElement.children[1].style.visibility = "hidden";
const element = document.querySelector(
"aside[aria-label='Add to your feed']"
);
if (element) element.style.display = "none";
const sidePromo = document.querySelector(
"div[role='region'][aria-label='Side Bar']"
);
if (sidePromo?.children[2]) sidePromo.children[2].style.display = "none";
const ul = document.querySelector("ul[aria-label='Account']");
const firstChild = ul.firstElementChild;
if (firstChild) {
firstChild.style.visibility="hidden";
}
handleHomeFeed();
}
function handleCompanyPosts() {
const targetNode = document.querySelector(".feed-container-theme");
if (targetNode) {
console.log("Company part posts found");
if (!isStopwatchRunning) startStopwatch();
hideElement(".scaffold-layout__aside[aria-label='Advertisement']");
}
}
function handleRecentActivity() {
const targetNode = document.querySelector(".scaffold-layout__sidebar");
if (targetNode) {
console.log("Target node found");
if (!isStopwatchRunning) startStopwatch();
}
}
function handleGroups() {
console.log("Your inside of groups");
const recommendedGroups = document.querySelector(
'aside.scaffold-layout__aside[aria-label="Groups you might be interested in"]'
);
if (recommendedGroups) recommendedGroups.style.display = "none";
}