const getNewWindowNotice = () => { let notice; switch (document.documentElement.lang) { case "pl": notice = "Uwaga, link zostanie otwarty w nowym oknie"; break; case "fr": notice = "Attention, le lien s'ouvrira dans une nouvelle fenêtre"; break; case "es": notice = "Tenga en cuenta que el enlace se abrirá en una nueva ventana."; break; case "de": notice = "Beachten Sie, dass der Link in einem neuen Fenster geöffnet wird"; break; case "ru": notice = "Обратите внимание, ссылка откроется в новом окне"; break; default: notice = "Note, the link will open in a new window"; break; } return notice; } /** * Add SR label for _blank window links */ const addSrLabel = (el: HTMLElement, notice: string) => { // el.title = notice; const srBlank = el.querySelector(".sr-b"); if (!srBlank) { el.insertAdjacentHTML('beforeend', '' + notice + ''); } } export const updateLinks = () => { // add no-as class const list = [...document.querySelectorAll('.body a[href*="#"], .info-attr a[href*="#"], .content-attr a[href*="#"], a[href*="mailto:"]')]; list.forEach((el) => { el.classList.add("no-as"); }) // add visually-hidden label for target _blank links const notice = getNewWindowNotice(); const list2 = [...document.querySelectorAll('a[target="_blank"]')] list2.forEach((el) => addSrLabel(el, notice)); }