-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from waic/waic_links.js
waic_link.jsの移植
- Loading branch information
Showing
2 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}) | ||
} | ||
}); |