MediaWiki:Gadget-edit-templates.js

De La Coppermind
Ir a la navegación Ir a la búsqueda

Nota: tras guardar, quizás necesites actualizar la caché de tu navegador para ver los cambios.

  • Firefox/Safari: Mantén presionada la tecla Mayús mientras pulsas el botón Actualizar, o presiona Ctrl+F5 o Ctrl+R (⌘+R en Mac)
  • Google Chrome: presiona Ctrl+Shift+R (⌘+Mayús+R en Mac)
  • Internet Explorer: mantén presionada Ctrl mientras pulsas Actualizar, o presiona Ctrl+F5
  • Opera: dirígete a Menú → Configuración (Opera → Preferencias en Mac) y luego a Privacidad y seguridad → Borrar datos de navegación → Imágenes y archivos en caché.

/// create a link that looks like .editsection
function make_editsection_link(url) {
 // generate an edit link
 const link = document.createElement('a')
 link.setAttribute('href', url)
 link.textContent = 'edit'
 // wrap the link in an '.editsection' link floated right
 const el = document.createElement('span')
 el.className = 'mw-editsection'
 el.style.float = 'right'
 // push [] around the A element into the span
 el.append( '[', link, ']')
 return el
}
/// add the link to the given box
function add_editsection_link(box) {
 if (!box.id) return;
 // FIXME: what does this do?
 const id = box.id.replace(/\.(\d+)/, '%$1')
 // generate an edit link
 const el = make_editsection_link('/edit/Template:'+ id)
 // get the title element
 const title = box.querySelector('.title')
 title.appendChild(el)
}

mw.hook('wikipage.content').add(function edit_templates(content) {
 const templates = Array.from(jQuery('.infobox,.navbar', content))
 if (!templates.length) return
 templates.forEach(add_editsection_link)
 console.debug('gadget:', 'edit-templates')
})