Skip to content

Commit

Permalink
Merge pull request #336 from waic/waic_links.js
Browse files Browse the repository at this point in the history
waic_link.jsの移植
  • Loading branch information
bakera authored Nov 4, 2024
2 parents 561bbb0 + 29b2ca6 commit fffd5b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion guidelines/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4351,4 +4351,4 @@ <h1 id="title" class="title">Web Content Accessibility Guidelines (WCAG) 2.2</h1
panel.hidden = true;
panel.classList.remove("docked");
}
})()</script><script src="https://www.w3.org/scripts/TR/2021/fixup.js"></script></body></html>
})()</script><script src="https://www.w3.org/scripts/TR/2021/fixup.js"></script><script src="waic_link.js"></script></body></html>
27 changes: 27 additions & 0 deletions guidelines/waic_link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const trNote = "この文書内にあるリンクのうち、「Understanding WCAG 2.2」へのリンクについては、WAIC の公開する日本語版にリンク先を追加しています。WAIC の日本語訳は、 W3C の公開する英語版より内容が古い可能性がありますのでご注意ください。";
const jaLinkText = '[日本語訳]';
const jaLinkTitleSuffix = 'の日本語訳';
const taregtUrlString = ['Understanding'];

document.addEventListener('DOMContentLoaded', function(){
const lastTrNote = document.querySelector("aside.trnote>p:last-child");
if(lastTrNote) lastTrNote.textContent = trNote;

const w3cDocumentAnchors = document.querySelectorAll("a[href*=https\\:\\/\\/www\\.w3\\.org\\/WAI\\/WCAG22]");
for(let i = 0; i < w3cDocumentAnchors.length; i++){
const anchor = w3cDocumentAnchors[i];
const href = anchor.getAttribute('href');
taregtUrlString.forEach(taregtString => {
if(href.indexOf(taregtString)!=-1 ){
const jaLinkUrl = href.replace('\/\/www.w3.org\/WAI\/WCAG22\/', '//waic.jp/translations/WCAG22/');
const jaLinkTitle = '"' + anchor.textContent + '"' + jaLinkTitleSuffix;
const jaAnchor = document.createElement('a');
jaAnchor.setAttribute('href', jaLinkUrl);
jaAnchor.setAttribute('title', jaLinkTitle);
jaAnchor.textContent = jaLinkText;
anchor.parentNode.insertBefore(jaAnchor, anchor.nextSibling);
jaAnchor.parentNode.insertBefore(document.createTextNode(" "), jaAnchor);
}
})
}
});

0 comments on commit fffd5b9

Please sign in to comment.