Skip to content

Commit 58dc6cf

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

1 file changed

Lines changed: 23 additions & 24 deletions

File tree

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

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

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

12-
if (links.length > 1) {
13-
const uniqueLinks = new Set();
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+
}
1424

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-
});
25+
found = true;
2526
}
26-
}
27+
});
2728
};
28-
29-
TargetSearchProjectsLinksFeature.targetAndRemoveDuplicates();
30-
29+
window.addEventListener('load', updateProjectDescription);

0 commit comments

Comments
 (0)