편집 요약 없음 태그: 수동 되돌리기 되돌려진 기여 |
편집 요약 없음 |
||
| (사용자 2명의 중간 판 10개는 보이지 않습니다) | |||
| 5번째 줄: | 5번째 줄: | ||
* @author Krinkle | * @author Krinkle | ||
* @version 2021-10-03 | * @version 2021-10-03 | ||
*/ | */ | ||
var toc = document.querySelector('#toc'); | var toc = document.querySelector('#toc'); | ||
if (toc) { | if (toc) { | ||
| 14번째 줄: | 11번째 줄: | ||
var num = toc.querySelector('a[href="#' + CSS.escape(headline.id) + '"] .tocnumber'); | var num = toc.querySelector('a[href="#' + CSS.escape(headline.id) + '"] .tocnumber'); | ||
if (num) { | if (num) { | ||
var link = document.createElement('a'); // 새로운 <a> 요소 생성 | |||
link.href = '#toc'; // 링크 URL 설정 | |||
link.textContent = num.textContent + '.'; // 링크 내용 설정 | |||
headline.prepend(link); // 헤딩 요소 내에 링크 요소 추가 | |||
} | |||
}); | }); | ||
} else { | } else { | ||
document.body.classList.add('tpl-autonum'); | document.body.classList.add('tpl-autonum'); | ||
} | } | ||
2024년 4월 2일 (화) 16:08 기준 최신판
/**
* Auto-number headings
*
* @source https://www.mediawiki.org/wiki/Snippets/Auto-number_headings
* @author Krinkle
* @version 2021-10-03
*/
var toc = document.querySelector('#toc');
if (toc) {
document.querySelectorAll('.mw-parser-output :is(h1,h2,h3,h4,h5,h6) .mw-headline').forEach(function (headline) {
var num = toc.querySelector('a[href="#' + CSS.escape(headline.id) + '"] .tocnumber');
if (num) {
var link = document.createElement('a'); // 새로운 <a> 요소 생성
link.href = '#toc'; // 링크 URL 설정
link.textContent = num.textContent + '.'; // 링크 내용 설정
headline.prepend(link); // 헤딩 요소 내에 링크 요소 추가
}
});
} else {
document.body.classList.add('tpl-autonum');
}