@xiee/utils
Version:
Miscellaneous tools and utilities to manipulate HTML pages
14 lines (13 loc) • 430 B
JavaScript
(d => {
const r = /^(https?:)?\/\//;
d.querySelectorAll('a').forEach(a => {
if (!a.title) a.title = decodeURI(a.href);
if (!r.test(a.getAttribute('href'))) return;
// add _blank target to external links
a.target = '_blank';
// shorten bare links
if (a.childElementCount === 0 && r.test(a.innerText)) {
a.innerText = a.innerText.replace(r, '').replace(/(.+)#.*$/, '$1');
}
});
})(document);