mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 14:36:13 +00:00
36 lines
852 B
JavaScript
36 lines
852 B
JavaScript
/**
|
|
*
|
|
* This script search for span.counter elements like
|
|
* <span class="counter">Il y a 4 notifications</span>
|
|
* and return
|
|
* <span class="counter">Il y a <span>4</span> notifications</span>
|
|
*
|
|
*/
|
|
const isNum = (v) => !isNaN(v);
|
|
|
|
const parseCounter = () => {
|
|
document.querySelectorAll('span.counter')
|
|
.forEach(el => {
|
|
let r = [];
|
|
el.innerText
|
|
.trim()
|
|
.split(' ')
|
|
.forEach(w => {
|
|
if (isNum(w)) {
|
|
r.push(`<span>${w}</span>`);
|
|
} else {
|
|
r.push(w);
|
|
}
|
|
})
|
|
;
|
|
el.innerHTML = r.join(' ');
|
|
})
|
|
;
|
|
};
|
|
|
|
window.addEventListener('DOMContentLoaded', function (e) {
|
|
parseCounter();
|
|
});
|
|
|
|
export { parseCounter };
|