italia2024
Version:
Italia 2024 assets
50 lines (45 loc) • 1.44 kB
JavaScript
(function () {
document.addEventListener('DOMContentLoaded', function () {
const currentDomain = window.location.hostname;
const allLinks = document.querySelectorAll('a');
//外部リンクに属性を追加
allLinks.forEach(link => {
const href = link.getAttribute('href');
if (href && !href.includes(currentDomain) && href.startsWith('http')) {
link.setAttribute('target', '_blank');
link.setAttribute('rel', 'noopener noreferrer');
}
});
//特定のリンクに属性を追加する関数
function setAttributesForLinks(selectors, attributes) {
const links = selectors.flatMap(selector => Array.from(document.querySelectorAll(selector)));
links.forEach(link => {
Object.entries(attributes).forEach(([key, value]) => {
link.setAttribute(key, value);
});
});
}
//_blank属性を追加するリンク
setAttributesForLinks(
[
'a[href*="_blank"]',
'a._blank',
'a[href*="_external"]',
'a._external',
'a[href*=".pdf"]',
'a[href*="_pdf"]',
'a._pdf',
'#pt-cv-view-8c04461wx5 a'
],
{ 'target': '_blank', 'rel': 'noopener noreferrer' }
);
//_disabled属性を追加するリンク
setAttributesForLinks(
[
'a[href*="_disabled"]',
'a._disabled'
],
{ 'tabindex': '-1', 'style': 'cursor: none; pointer-events: none;' }
);
});
})();