User:Euphoria/common.js: Difference between revisions
From Test Wiki
Content deleted Content added
No edit summary Tag: Manual revert |
fix |
||
| Line 4: | Line 4: | ||
const currentPage = mw.config.get('wgPageName').replace(/_/g, ' '); |
const currentPage = mw.config.get('wgPageName').replace(/_/g, ' '); |
||
if (!currentPage.startsWith(pagePrefix + '/') || mw.config.get('wgAction') !== 'view') return; |
if ((!currentPage.startsWith(pagePrefix + '/') && currentPage !== pagePrefix) || mw.config.get('wgAction') !== 'view') return; |
||
const api = new mw.Api(); |
const api = new mw.Api(); |
||
| Line 33: | Line 33: | ||
// Handle VfD action for a target page |
// Handle VfD action for a target page |
||
function handleAction(targetPage, actionName) { |
function handleAction(targetPage, actionName) { |
||
// 🔹 if we are on the main VfD page, close the subpage instead |
|||
| ⚫ | |||
const pageToEdit = (currentPage === pagePrefix) ? pagePrefix + '/' + targetPage : currentPage; |
|||
// Prompt user for an optional comment |
|||
| ⚫ | |||
const userComment = prompt('Add an additional comment (optional):', ''); |
const userComment = prompt('Add an additional comment (optional):', ''); |
||
const commentText = userComment ? ` ${userComment}` : ''; |
const commentText = userComment ? ` ${userComment}` : ''; |
||
| Line 40: | Line 42: | ||
const newDiscussion = `{{subst:vt|${actionName}.${commentText} --~~~~}}\n${discussionContent}\n{{subst:vb}}`; |
const newDiscussion = `{{subst:vt|${actionName}.${commentText} --~~~~}}\n${discussionContent}\n{{subst:vb}}`; |
||
apiHelper.edit( |
apiHelper.edit(pageToEdit, newDiscussion, `Closed as ${actionName} ([[User:Euphoria/VfDcloser|VfDcloser]])`, () => { |
||
if (actionName === 'delete') { |
if (actionName === 'delete') { |
||
deletePageAndTalk(targetPage); |
deletePageAndTalk(targetPage); |
||
| Line 164: | Line 166: | ||
if (categories.includes('VfD archive entries')) return; |
if (categories.includes('VfD archive entries')) return; |
||
if (currentPage === pagePrefix) { |
|||
| ⚫ | |||
// 🔹 Main page: attach buttons to transcluded discussions |
|||
| ⚫ | |||
$('#mw-content-text').find('.mw-transclusion').each(function () { |
|||
| ⚫ | |||
const link = $(this).find('a').first().attr('title'); |
|||
if (link && link.startsWith(pagePrefix + '/')) { |
|||
| ⚫ | |||
const targetPage = link.replace(pagePrefix + '/', ''); |
|||
const heading = $(this).find('h2').first()[0]; |
|||
if (heading) { |
|||
createButtonsForHeading(heading, targetPage); |
|||
} |
|||
} |
|||
}); |
|||
} else { |
|||
// 🔹 Subpages: original behavior |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
createButtonsForHeading(this, headingText); |
|||
}); |
|||
| ⚫ | |||
}); |
}); |
||
}); |
}); |
||