User:Euphoria/common.js: Difference between revisions
From Test Wiki
Content deleted Content added
fix |
fix |
||
| Line 8: | Line 8: | ||
const api = new mw.Api(); |
const api = new mw.Api(); |
||
// |
// API helper functions |
||
const apiHelper = { |
const apiHelper = { |
||
edit(title, content, summary, callback) { |
edit(title, content, summary, callback) { |
||
| Line 31: | Line 31: | ||
}; |
}; |
||
// |
// Handle VfD action for a target page |
||
function handleAction(targetPage, actionName) { |
function handleAction(targetPage, actionName) { |
||
apiHelper.fetch(currentPage, discussionContent => { |
apiHelper.fetch(currentPage, discussionContent => { |
||
// Prompt user for an optional comment |
|||
const newDiscussion = `{{subst:vt|${actionName}. --~~~~}}\n${discussionContent}\n{{subst:vb}}`; |
|||
const userComment = prompt('Add an additional comment (optional):', ''); |
|||
const commentText = userComment ? ` ${userComment}` : ''; |
|||
const newDiscussion = `{{subst:vt|${actionName}.${commentText} --~~~~}}\n${discussionContent}\n{{subst:vb}}`; |
|||
apiHelper.edit(currentPage, newDiscussion, `Closed as ${actionName} ([[User:Euphoria/VfDcloser|VfDcloser]])`, () => { |
|||
if (actionName === 'delete') { |
if (actionName === 'delete') { |
||
deletePageAndTalk(targetPage); |
deletePageAndTalk(targetPage); |
||
| Line 43: | Line 46: | ||
keepOrNoConsensus(targetPage, actionName); |
keepOrNoConsensus(targetPage, actionName); |
||
} |
} |
||
}); |
}); |
||
}); |
}); |
||
| Line 49: | Line 51: | ||
function deletePageAndTalk(title) { |
function deletePageAndTalk(title) { |
||
apiHelper.delete(title, `[[${currentPage}]]`, () => { |
apiHelper.delete(title, `[[${currentPage}]] ([[User:Euphoria/VfDcloser|VfDcloser]])`, () => { |
||
apiHelper.fetch('Talk:' + title, talkContent => { |
apiHelper.fetch('Talk:' + title, talkContent => { |
||
if (talkContent) { |
if (talkContent) { |
||
apiHelper.delete('Talk:' + title, 'Parent page deleted via VfD', () => { |
apiHelper.delete('Talk:' + title, 'Parent page deleted via VfD ([[User:Euphoria/VfDcloser|VfDcloser]])', () => { |
||
notifyAndReload('Discussion closed. Page and talk page deleted.'); |
notifyAndReload('Discussion closed. Page and talk page deleted.'); |
||
}); |
}); |
||
| Line 65: | Line 67: | ||
apiHelper.fetch(title, content => { |
apiHelper.fetch(title, content => { |
||
const updatedContent = content.replace(/\{\{vfd-new\}\}/gi, '').trim(); |
const updatedContent = content.replace(/\{\{vfd-new\}\}/gi, '').trim(); |
||
apiHelper.edit(title, updatedContent, `VFD closed as ${actionName}`, () => { |
apiHelper.edit(title, updatedContent, `VFD closed as ${actionName} ([[User:Euphoria/VfDcloser|VfDcloser]])`, () => { |
||
updateTalkPage(title, actionName); |
updateTalkPage(title, actionName); |
||
}); |
}); |
||
| Line 75: | Line 77: | ||
apiHelper.fetch('Talk:' + title, talkContent => { |
apiHelper.fetch('Talk:' + title, talkContent => { |
||
const updatedTalk = talkContent ? `${talkTemplate}\n${talkContent}` : talkTemplate; |
const updatedTalk = talkContent ? `${talkTemplate}\n${talkContent}` : talkTemplate; |
||
apiHelper.edit('Talk:' + title, updatedTalk, `VFD closed as ${actionName}`, () => { |
apiHelper.edit('Talk:' + title, updatedTalk, `VFD closed as ${actionName} ([[User:Euphoria/VfDcloser|VfDcloser]])`, () => { |
||
notifyAndReload('Discussion closed. Page and talk page updated.'); |
notifyAndReload('Discussion closed. Page and talk page updated.'); |
||
}); |
}); |
||
| Line 86: | Line 88: | ||
} |
} |
||
// |
// Create UI buttons for each heading |
||
function createButtonsForHeading(heading, targetPage) { |
function createButtonsForHeading(heading, targetPage) { |
||
const container = document.createElement('span'); |
const container = document.createElement('span'); |
||
| Line 157: | Line 159: | ||
} |
} |
||
// |
// Initialize buttons on page load |
||
$(function () { |
$(function () { |
||
const categories = mw.config.get('wgCategories') || []; |
const categories = mw.config.get('wgCategories') || []; |
||