User:Euphoria/common.js: Difference between revisions

From Test Wiki
Content deleted Content added
fix
Tag: Reverted
No edit summary
Tag: Manual revert
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;
// Allow main VfD page AND subpages, block everything else
if (!(currentPage === pagePrefix || currentPage.startsWith(pagePrefix + '/'))
|| mw.config.get('wgAction') !== 'view') return;


const api = new mw.Api();
const api = new mw.Api();
Line 36: Line 34:
function handleAction(targetPage, actionName) {
function handleAction(targetPage, actionName) {
apiHelper.fetch(currentPage, discussionContent => {
apiHelper.fetch(currentPage, discussionContent => {
// 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}` : '';

const newDiscussion = `{{subst:vt|${actionName}.${commentText} --~~~~}}\n${discussionContent}\n{{subst:vb}}`;
const newDiscussion = `{{subst:vt|${actionName}.${commentText} --~~~~}}\n${discussionContent}\n{{subst:vb}}`;


Line 89: Line 89:


// Create UI buttons for each heading
// Create UI buttons for each heading
function createButtonsForHeading(heading, defaultTargetPage) {
function createButtonsForHeading(heading, targetPage) {
let targetPage = null;

if (currentPage === pagePrefix) {
// On main page: extract the subpage from transclusion text
const headingText = $(heading).text().trim();
const match = headingText.match(/Wikiquote:Votes for deletion\/.+/);
if (match) {
targetPage = match[0]; // close this subpage
}
} else {
// On subpage: close itself
targetPage = defaultTargetPage;
}

if (!targetPage) return;

const container = document.createElement('span');
const container = document.createElement('span');
container.style.marginLeft = '6px';
container.style.marginLeft = '6px';
Line 157: Line 141:
if (!confirm(`Are you sure you want to close as ${actionObj.name}?`)) return;
if (!confirm(`Are you sure you want to close as ${actionObj.name}?`)) return;


// Disable all buttons under this heading
$(heading).find('.vfd-action-link').each((i, b) => {
$(heading).find('.vfd-action-link').each((i, b) => {
b.style.opacity = '0.5';
b.style.opacity = '0.5';