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