Skip to content

Commit fffd5b9

Browse files
authored
Merge pull request #336 from waic/waic_links.js
waic_link.jsの移植
2 parents 561bbb0 + 29b2ca6 commit fffd5b9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

guidelines/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4351,4 +4351,4 @@ <h1 id="title" class="title">Web Content Accessibility Guidelines (WCAG) 2.2</h1
43514351
panel.hidden = true;
43524352
panel.classList.remove("docked");
43534353
}
4354-
})()</script><script src="https://www.w3.org/scripts/TR/2021/fixup.js"></script></body></html>
4354+
})()</script><script src="https://www.w3.org/scripts/TR/2021/fixup.js"></script><script src="waic_link.js"></script></body></html>

guidelines/waic_link.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const trNote = "この文書内にあるリンクのうち、「Understanding WCAG 2.2」へのリンクについては、WAIC の公開する日本語版にリンク先を追加しています。WAIC の日本語訳は、 W3C の公開する英語版より内容が古い可能性がありますのでご注意ください。";
2+
const jaLinkText = '[日本語訳]';
3+
const jaLinkTitleSuffix = 'の日本語訳';
4+
const taregtUrlString = ['Understanding'];
5+
6+
document.addEventListener('DOMContentLoaded', function(){
7+
const lastTrNote = document.querySelector("aside.trnote>p:last-child");
8+
if(lastTrNote) lastTrNote.textContent = trNote;
9+
10+
const w3cDocumentAnchors = document.querySelectorAll("a[href*=https\\:\\/\\/www\\.w3\\.org\\/WAI\\/WCAG22]");
11+
for(let i = 0; i < w3cDocumentAnchors.length; i++){
12+
const anchor = w3cDocumentAnchors[i];
13+
const href = anchor.getAttribute('href');
14+
taregtUrlString.forEach(taregtString => {
15+
if(href.indexOf(taregtString)!=-1 ){
16+
const jaLinkUrl = href.replace('\/\/www.w3.org\/WAI\/WCAG22\/', '//waic.jp/translations/WCAG22/');
17+
const jaLinkTitle = '"' + anchor.textContent + '"' + jaLinkTitleSuffix;
18+
const jaAnchor = document.createElement('a');
19+
jaAnchor.setAttribute('href', jaLinkUrl);
20+
jaAnchor.setAttribute('title', jaLinkTitle);
21+
jaAnchor.textContent = jaLinkText;
22+
anchor.parentNode.insertBefore(jaAnchor, anchor.nextSibling);
23+
jaAnchor.parentNode.insertBefore(document.createTextNode(" "), jaAnchor);
24+
}
25+
})
26+
}
27+
});

0 commit comments

Comments
 (0)