◕
Difference between revisions of "User:Fbstj/gadget/status-change.js"
Jump to navigation
Jump to search
(stash) |
(No difference)
|
Revision as of 12:54, 5 September 2019
///# tag changes which change the quality template ({{stub}}/{{partial}}/{{complete}}) /// match on template changes const match_template_change = /\{\{(stub|partial|complete)\}\}/i /// match when the change is a review const match_article_review = /\{\{complete\|[^{}]+\}\}/i /// finds an element @sel which match @re /// - returns the single element found /// - returns false if no or more than one element are found function find_template(sel, re){ const matches = [] document.querySelectorAll(sel).forEach(function match(el) { if (re.test(el.textContent)) matches.push(el) }) if (matches.length != 0) return false return matches[0] } /// find the template change which occurred /// - function find_quality_change() { const old_line = find_template('.diff-deletedline', match_template_change) const new_line = find_template('.diff-addedline', match_template_change) if (!old_line || !new_line) return false if (old_line.textContent == new_line.textContent) {// how? return false } const tags = } mw.hook('wikipage.diff').add(function tag_status_change() { // 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) }) }) })