미디어위키:Gadget-autonum.js: 두 판 사이의 차이

(새 문서: →* * Auto-number headings * * @source https://www.mediawiki.org/wiki/Snippets/Auto-number_headings * @author Krinkle * @version 2021-10-03 * * Sch edited a bit.: 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) { span = document.createElemen...)
 
편집 요약 없음
태그: 되돌려진 기여
5번째 줄: 5번째 줄:
  * @author Krinkle
  * @author Krinkle
  * @version 2021-10-03
  * @version 2021-10-03
*
* Sch edited a bit.
  */
  */
var toc = document.querySelector('#toc');
var toc = document.querySelector('#toc');
if (toc) {
if (toc) {
   document.querySelectorAll('.mw-parser-output :is(h1,h2,h3,h4,h5,h6) .mw-headline').forEach(function (headline) {
   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');
     var num = toc.querySelector('a[href="#' + CSS.escape(headline.id) + '"] .tocnumber');
     if (num) {
     if (num) headline.prepend(num.textContent + ' ');
      span = document.createElement("span");
      span.classList.add('mw-headline-number');
      span.textContent = num.textContent + '. ';
      headline.prepend(span);
    }
   });
   });
} else {
} else {
   document.body.classList.add('tpl-autonum');
   document.body.classList.add('tpl-autonum');
}
}

2022년 10월 28일 (금) 20:26 판

/**
 * 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) headline.prepend(num.textContent + ' ');
  });
} else {
  document.body.classList.add('tpl-autonum');
}