MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
added code for auto numbering heading Tag: Reverted |
add comment for custom JS cookie disable code |
||
| (14 intermediate revisions by the same user not shown) | |||
| Line 20: | Line 20: | ||
document.body.classList.add('tpl-autonum'); | document.body.classList.add('tpl-autonum'); | ||
} | } | ||
/* deactivate cookies VEE and VEECid when preference cookies are not ticked */ | |||
(function () { | |||
'use strict'; | |||
var originalSet = mw.cookie.set; | |||
mw.cookie.set = function (name, value, options) { | |||
if ( | |||
(name === 'VEE' || name === 'VEECid') && | |||
!window.cookieConsent.isConsentGiven('preference') | |||
) { | |||
return; | |||
} | |||
return originalSet.apply(this, arguments); | |||
}; | |||
}()); | |||
Latest revision as of 20:44, 18 August 2026
/* Any JavaScript here will be loaded for all users on every page load. */
/**
* Auto-number headings
*
* @source https://www.mediawiki.org/wiki/Snippets/Auto-number_headings
* @author Krinkle
* @version 2024-07-28
*/
var toc = document.querySelector('#toc');
if (toc) {
document.body.classList.add('tpl-autonum-attr');
// Support legacy Parser: <h2><span class=mw-headline id=…>
// Support Parsoid: <section><div class=mw-heading><h2 id…>
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)').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');
}
/* deactivate cookies VEE and VEECid when preference cookies are not ticked */
(function () {
'use strict';
var originalSet = mw.cookie.set;
mw.cookie.set = function (name, value, options) {
if (
(name === 'VEE' || name === 'VEECid') &&
!window.cookieConsent.isConsentGiven('preference')
) {
return;
}
return originalSet.apply(this, arguments);
};
}());