Diferencia entre revisiones de «MediaWiki:Gadget-artist-portal.js»

De La Coppermind
Ir a la navegación Ir a la búsqueda
m (maybe?)
(Cambiar Coppermind:Artists por Coppermind:Artistas)
 
(No se muestran 2 ediciones intermedias de otro usuario)
Línea 1: Línea 1:
mw.hook('Coppermind:Artists').add(function artist_portal() {
mw.hook('Coppermind:Artistas').add(function artist_portal(content) {


console.debug('artist-portal:')
console.debug('artist-portal:', content)


document.querySelectorAll('a[title^="Coppermind:Artists/"]').forEach(function each_artist(el) {
Array.from(jQuery('a[title^="Coppermind:Artistas/"]',content)).forEach(function each_artist(el) {
// replace text with artist name
// replace text with artist name
el.innerText = el.innerText.replace('Coppermind:Artists/','')
el.innerText = el.innerText.replace('Coppermind:Artistas/','')
})
})


Array.from(jQuery('a[title^="Coppermind:Artists/"]').closest('ul')).forEach(function sort_list(ul) {
Array.from(jQuery('a[title^="Coppermind:Artistas/"]',content).closest('ul')).forEach(function sort_list(ul) {
const kids = Array.from(ul.children)
const kids = Array.from(ul.children)
console.debug('sorting:', kids.length, 'elements from', ul)
kids.sort(function sort_kids(a,b) { return a.innerText < b.innerText ? -1 : +1 })
kids.sort(function sort_kids(a,b) { return a.innerText < b.innerText ? -1 : +1 })
kids.forEach(function reinsert(li) { ul.append(li) })
kids.forEach(function reinsert(li) { ul.append(li) })

Revisión actual - 08:05 11 jun 2022

mw.hook('Coppermind:Artistas').add(function artist_portal(content) {

console.debug('artist-portal:', content)

Array.from(jQuery('a[title^="Coppermind:Artistas/"]',content)).forEach(function each_artist(el) {
 // replace text with artist name
 el.innerText = el.innerText.replace('Coppermind:Artistas/','')
})

Array.from(jQuery('a[title^="Coppermind:Artistas/"]',content).closest('ul')).forEach(function sort_list(ul) {
 const kids = Array.from(ul.children)
 console.debug('sorting:', kids.length, 'elements from', ul)
 kids.sort(function sort_kids(a,b) { return a.innerText < b.innerText ? -1 : +1 })
 kids.forEach(function reinsert(li) { ul.append(li) })
})

// END
})