|
1 | | -const updateProjectDescription = () => { |
2 | | - const projectDescriptions = document.querySelectorAll('.project-description'); |
3 | | - let found = false; |
4 | 1 |
|
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 | + }, |
7 | 8 |
|
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="]')); |
11 | 11 |
|
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(); |
24 | 14 |
|
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 | + }); |
26 | 25 | } |
27 | | - }); |
| 26 | + } |
28 | 27 | }; |
29 | | -window.addEventListener('load', updateProjectDescription); |
| 28 | + |
| 29 | +TargetSearchProjectsLinksFeature.targetAndRemoveDuplicates(); |
| 30 | + |
0 commit comments