1
1
2
- First, we need to find all external references .
2
+ Primeiro, precisamos encontrar todas as referências externas .
3
3
4
- There are two ways .
4
+ Há duas maneiras .
5
5
6
- The first is to find all links using ` document.querySelectorAll('a') ` and then filter out what we need :
6
+ A primeira é encontrar todos os links usando ` document.querySelectorAll('a') ` e então filtrar o que precisamos :
7
7
8
8
``` js
9
9
let links = document .querySelectorAll (' a' );
@@ -12,23 +12,23 @@ for (let link of links) {
12
12
* ! *
13
13
let href = link .getAttribute (' href' );
14
14
*/ ! *
15
- if (! href) continue ; // no attribute
15
+ if (! href) continue ; // sem atributo
16
16
17
- if (! href .includes (' ://' )) continue ; // no protocol
17
+ if (! href .includes (' ://' )) continue ; // sem protocolo
18
18
19
19
if (href .startsWith (' http://internal.com' )) continue ; // internal
20
20
21
21
link .style .color = ' orange' ;
22
22
}
23
23
```
24
24
25
- Please note: we use ` link.getAttribute('href') ` . Not ` link.href ` , because we need the value from HTML.
25
+ Observe: usamos ` link.getAttribute('href') ` . Não ` link.href ` , porque precisamos do valor do HTML.
26
26
27
- ...Another, simpler way would be to add the checks to CSS selector:
27
+ ...Outra forma mais simples seria apenas adicionar as verificações ao seletor CSS
28
28
29
29
``` js
30
- // look for all links that have :// in href
31
- // but href doesn't start with http://internal.com
30
+ // procura por todos os links que tem :// em href
31
+ // mas href não começa com http://internal.com
32
32
let selector = ' a[href*="://"]:not([href^="http://internal.com"])' ;
33
33
let links = document .querySelectorAll (selector);
34
34
0 commit comments