User:Iritscen/vector-2022.js: Difference between revisions
mNo edit summary Tag: Reverted |
mNo edit summary Tag: Reverted |
||
Line 50: | Line 50: | ||
root.style.setProperty('--month-order', '2'); | root.style.setProperty('--month-order', '2'); | ||
root.style.setProperty('--day-order', '1'); | root.style.setProperty('--day-order', '1'); | ||
changeDateSeparator('month', '/'); | //changeDateSeparator('month', '/'); | ||
changeDateSeparator('day', ''); | changeDateSeparator('day', ''); | ||
} | } |
Revision as of 20:43, 5 May 2025
function getLang() { if (navigator.languages !== undefined) return navigator.languages[0]; return navigator.language; } function changeDateSeparator(component, separator) { const styleSheets = document.styleSheets; var ruleIndex = 0; console.log('Changing component '+component+' to use separator "'+separator+'".'); for (var i = 0; i < styleSheets.length; i++) { const rules = styleSheets[i].cssRules || styleSheets[i].rules; console.log('Looking for date rule ".date-'+component+'::before".'); for (var j = 0; j < rules.length; j++) { if (rules[j].selectorText === '.date-day::before') { console.log('Found desired date rule.'); ruleIndex = j; break; } } if (ruleIndex !== undefined) { // Update the content of the existing rule styleSheets[i].deleteRule(ruleIndex); if (component == 'day') styleSheets[i].insertRule('.date-day::before{content:"'+separator+'";}', ruleIndex); else if (component == 'month') styleSheets[i].insertRule('.date-month::before{content:"'+separator+'";}', ruleIndex); break; } } } mw.hook('wikipage.content').add(function($localizeDates) { const lang = getLang(); const root = document.querySelector(':root'); if (root == undefined || lang == undefined) return; if (lang != "en-US") // LocaleDate prints dates in U.S.-style by default { root.style.setProperty('--month-order', '2'); root.style.setProperty('--day-order', '1'); //changeDateSeparator('month', '/'); changeDateSeparator('day', ''); } }); mw.hook('wikiEditor.toolbarReady').add(function($textarea) { $textarea.wikiEditor('addToToolbar', {section:'secondary', group:'default', tools: { smile: { label:'Smile!', // or use mw.message(key).escaped() for a localized label, see above type:'button', icon:'//upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Gnome-face-smile.svg/22px-Gnome-face-smile.svg.png', action: { type:'encapsulate', options: { pre:":)" // text to be inserted } } } } }); });