Skip to content

Commit 19e423c

Browse files
authored
Update consolidate.js
1 parent c3399c5 commit 19e423c

1 file changed

Lines changed: 24 additions & 23 deletions

File tree

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
const updateProjectDescription = () => {
2-
const projectDescriptions = document.querySelectorAll('.project-description');
3-
let found = false;
41

5-
projectDescriptions.forEach((projectDescription) => {
6-
const descriptionText = projectDescription.innerHTML;
2+
const TargetSearchProjectsLinksFeature = {
3+
targetAndRemoveDuplicates: async () => {
4+
const projectDescriptions = await ScratchTools.waitForElements('.project-description', function (element) {
5+
TargetSearchProjectsLinksFeature.handleProjectDescription(element);
6+
});
7+
},
78

8-
if (descriptionText.trim() !== '') {
9-
const tagRegex = /<a\s+href="[^"]*"[^>]*>[^<]*<\/a>/g;
10-
const tags = descriptionText.match(tagRegex);
9+
handleProjectDescription: (projectDescription) => {
10+
const links = Array.from(projectDescription.querySelectorAll('a[href*="/search/projects?q="]'));
1111

12-
if (tags) {
13-
const uniqueTags = new Set();
14-
const updatedDescription = descriptionText.replace(tagRegex, (match) => {
15-
if (!uniqueTags.has(match)) {
16-
uniqueTags.add(match);
17-
return match;
18-
} else {
19-
return '';
20-
}
21-
});
22-
projectDescription.innerHTML = updatedDescription;
23-
}
12+
if (links.length > 1) {
13+
const uniqueLinks = new Set();
2414

25-
found = true;
15+
links.forEach(link => {
16+
const linkHref = link.getAttribute('href');
17+
18+
if (!uniqueLinks.has(linkHref)) {
19+
uniqueLinks.add(linkHref);
20+
} else {
21+
22+
link.style.display = 'none';
23+
}
24+
});
2625
}
27-
});
26+
}
2827
};
29-
window.addEventListener('load', updateProjectDescription);
28+
29+
TargetSearchProjectsLinksFeature.targetAndRemoveDuplicates();
30+

0 commit comments

Comments
 (0)