Skip to content

Commit 02a87d6

Browse files
committed
add little icons ⧉ after link text to indicate external links (thanks for the feedback from @pyltime)
1 parent c38fe8f commit 02a87d6

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

js/external-links.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
(function() {
2-
var links = document.getElementsByTagName('a');
2+
var links = document.getElementsByTagName('a'), link, n, child;
33
for (var i = 0; i < links.length; i++) {
4-
if (/^(https?:)?\/\//.test(links[i].getAttribute('href'))) links[i].target = '_blank';
4+
link = links[i];
5+
if (/^(https?:)?\/\//.test(link.getAttribute('href'))) {
6+
link.target = '_blank';
7+
n = link.childElementCount;
8+
if (n === 0 && link.innerText) {
9+
link.innerHTML += ' &boxbox;'; // pure text
10+
} else if (n === 2) {
11+
// the page /formats.html
12+
child = link.firstElementChild;
13+
if (child.className === 'formatName') child.innerHTML += ' &boxbox;';
14+
}
15+
}
516
}
617
})();

0 commit comments

Comments
 (0)