미디어위키:Gadget-autonum.js: 두 판 사이의 차이
편집 요약 없음 태그: 되돌려진 기여 |
편집 요약 없음 |
||
| (같은 사용자의 중간 판 8개는 보이지 않습니다) | |||
| 1번째 줄: | 1번째 줄: | ||
var toc = document.querySelector('#toc'); | 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) { | if (toc) { | ||
document.body.classList.add('tpl-autonum-attr'); | document.body.classList.add('tpl-autonum-attr'); | ||
headings.forEach(function (headline) { | |||
var num = toc.querySelector( | |||
var num = toc.querySelector('a[href="#' + CSS.escape(headline.id) + '"] .tocnumber'); | 'a[href="#' + CSS.escape(headline.id) + '"] .tocnumber' | ||
if (num) headline.setAttribute('data-autonum', num.textContent); | ); | ||
if (num) { | |||
headline.setAttribute('data-autonum', num.textContent); | |||
} | |||
}); | }); | ||
} else { | } else { | ||
document.body.classList.add('tpl-autonum'); | 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); | |||
}); | |||
} | |||
2026년 2월 24일 (화) 14:35 기준 최신판
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);
});
}