MediaWiki:Gadget-tag-status-change.js

De La Coppermind
Revisión del 12:12 28 jul 2019 de Fbstj (discusión | contribs.) (guard combo diffs from tagging wrong revision)
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é.
mw.hook('wikipage.diff').add(function () {

// 2018-11-06 add status-change tags to pages with diffs that change the status
const diff = document.querySelector('.diff')
if (!diff) return;

diff.querySelectorAll('.diff-addedline').forEach(function (el) {
  if (!/\{\{(stub|partial|complete)\}\}/.test(el.innerText)) return
  const row = el.parentElement
  const rem = row.querySelector('.diff-deletedline')
  const add = row.querySelector('.diff-addedline')
  const msg = rem.innerText.trim() +' => '+ add.innerText.trim()

// guard against tagging latest revision in multi-change diffs
if (diff.querySelector('.diff-multi')) {
 // TODO: determine which of the revisions to tag?
 console.warn('gadget:', 'tag-status-change', 'ignored on combination diff')
 mw.notify('theses revisions contain a potential status-change ('+ msg +') which has been ignored')
 return; 
}

console.warn('gadget:', 'tag-status-change')

// send the notification 
;(new mw.Api).postWithToken('csrf', { action: 'tag', revid: mw.config.get('wgRevisionId'), add: 'status-change', reason: msg, }).then(function () {
     mw.notify('revision tagged with '+ msg)
})


})

})