User:Euphoria/common.js: Difference between revisions
From Test Wiki
Content deleted Content added
fix |
fix |
||
Line 13:
// Skip headings already inside a .vfd container or without links
if ($(heading).closest('.vfd').length) return;
// Extract full page name from link href
const href = link.attr('href');
const targetPage = decodeURIComponent(href.replace('/wiki/', '').replace(/_/g, ' '));
const container = document.createElement('span');
Line 42 ⟶ 48:
btn.style.verticalAlign = 'middle';
btn.style.transition = '0.15s';
btn.addEventListener('mouseenter', () => btn.style.filter='brightness(1.3)');
btn.addEventListener('mouseleave', () => btn.style.filter='brightness(1)');
Line 53 ⟶ 58:
const api = new mw.Api();
// Fetch discussion page content of the target page
api.get({
action: 'query',
prop: 'revisions',
titles:
rvslots: 'main',
rvprop: 'content',
Line 64 ⟶ 69:
const pages = data.query.pages;
const pageId = Object.keys(pages)[0];
let content = pages[pageId].revisions[0].slots.main['*'] || '';
const discussionNewContent = '{{subst:vt|' + actionObj.name + '. --~~~~}}\n' + content.trim() + '\n{{subst:vb}}';
Line 71 ⟶ 76:
api.postWithToken('csrf', {
action: 'edit',
title:
text: discussionNewContent,
summary: 'Closed as ' + actionObj.name,
minor: true
}).done(function() {
const link = $(heading).find('a').first();▼
▲ if (!link.length) {
mw.notify('Cannot find target page link!', {title: 'VfDcloser', type: 'error', timeout: 1500});▼
setTimeout(() => location.reload(), 1500);▼
▲ return;
}▼
setTimeout(() => location.reload(), 1500);▼
return;▼
if (actionObj.name === 'delete') {
// Delete target page
api.postWithToken('csrf', {
reason: '[[' + targetPage
const talkPage = 'Talk:' +
api.get({action: 'query', titles: talkPage, format: 'json'}).done(data => {
action:
reason: 'Parent page deleted via
setTimeout(() => location.reload(), 1500);
}).fail(err => mw.notify('Error deleting talk page: ' + JSON.stringify(err), {title: 'VfDcloser', type: 'error', timeout: 1500}));
}
▲ setTimeout(() => location.reload(), 1500);
▲ }
▲ }).fail(err => mw.notify('
} else {
// Keep / No consensus: update page and talk page
Line 124 ⟶ 121:
const articlePages = articleData.query.pages;
const articleId = Object.keys(articlePages)[0];
let articleContent = articlePages[articleId].revisions[0].slots.main['*'] || '';
articleContent = articleContent.replace(/\{\{vfd-new\}\}/gi, '').trim();
| |||