미디어위키:Gadget-autonum.js
참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.
- 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
- 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
- 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
/**
* Auto-number headings (fixed for no-TOC pages)
*/
var toc = document.querySelector('#toc');
var headings = document.querySelectorAll(
'.mw-parser-output :is(h1,h2,h3,h4,h5,h6) .mw-headline[id], ' +
'.mw-parser-output .mw-heading [id]:is(h1,h2,h3,h4,h5,h6)'
);
if (toc) {
document.body.classList.add('tpl-autonum-attr');
headings.forEach(function (headline) {
var num = toc.querySelector(
'a[href="#' + CSS.escape(headline.id) + '"] .tocnumber'
);
if (num) {
headline.setAttribute('data-autonum', num.textContent);
}
});
} else {
document.body.classList.add('tpl-autonum-attr');
let counters = [0, 0, 0, 0, 0, 0];
headings.forEach(function (headline) {
var level = parseInt(headline.closest('h1,h2,h3,h4,h5,h6').tagName[1], 10) - 1;
counters[level]++;
for (let i = level + 1; i < counters.length; i++) {
counters[i] = 0;
}
let number = counters
.slice(0, level + 1)
.filter(n => n > 0)
.join('.');
headline.setAttribute('data-autonum', number);
});
}