User:Euphoria/common.js: Difference between revisions

From Test Wiki
Jump to navigation Jump to search
Content deleted Content added
fix
fix
Line 3: Line 3:
const pagePrefix = 'User:Euphoria/TestVfD/';
const pagePrefix = 'User:Euphoria/TestVfD/';


if (mw.config.get('wgPageName').startsWith(pagePrefix) && mw.config.get('wgAction') === 'view') {
if (!mw.config.get('wgPageName').startsWith(pagePrefix) || mw.config.get('wgAction') !== 'view') {
return;
}


// Wait until DOM is fully loaded
// Wait until MediaWiki content is ready
document.addEventListener('DOMContentLoaded', function () {
mw.hook('wikipage.content').add(function ($content) {
$content.find('.mw-headline').each(function () {
const headline = this;
const sectionName = headline.textContent.trim();
if (!sectionName) return;


document.querySelectorAll('.mw-headline').forEach(function (headline) {
const container = document.createElement('span');
const sectionName = headline.textContent.trim();
container.style.marginLeft = '10px';
if (!sectionName) return;


['delete', 'keep', 'no consensus'].forEach(function (action) {
const container = document.createElement('span');
container.style.marginLeft = '10px';
const btn = document.createElement('a');
btn.href = '#';
btn.textContent = action.charAt(0).toUpperCase() + action.slice(1);
btn.style.marginRight = '5px';
btn.style.fontSize = '90%';
btn.addEventListener('click', function (e) {
e.preventDefault();


const topText = '{{subst:vt|' + action + '. --~~~~}}\n==' + sectionName + '==\n';
['delete', 'keep', 'no consensus'].forEach(function (action) {
const btn = document.createElement('a');
const bottomText = '\n{{subst:vb}}';
btn.href = '#';
const summary = 'Closed section "' + sectionName + '" as ' + action;
btn.textContent = action.charAt(0).toUpperCase() + action.slice(1);
btn.style.marginRight = '5px';
btn.style.fontSize = '90%';
btn.addEventListener('click', function (e) {
e.preventDefault();


const topText = '{{subst:vt|' + action + '. --~~~~}}\n==' + sectionName + '==\n';
localStorage.setItem('vfdPrefillContent', JSON.stringify({ top: topText, bottom: bottomText }));
const bottomText = '\n{{subst:vb}}';
localStorage.setItem('vfdPrefillSummary', summary);
const summary = 'Closed section "' + sectionName + '" as ' + action;


localStorage.setItem('vfdPrefillContent', JSON.stringify({ top: topText, bottom: bottomText }));
window.location.href = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit' });
localStorage.setItem('vfdPrefillSummary', summary);

window.location.href = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit' });
});
container.appendChild(btn);
});
});
container.appendChild(btn);

headline.parentNode.appendChild(container);
});
});


headline.parentNode.appendChild(container);
});
});
});

}

// Edit page prefill (unchanged)
if (mw.config.get('wgAction') === 'edit') {
const textbox = document.getElementById('wpTextbox1');
const summaryBox = document.getElementById('wpSummary');

if (textbox) {
const stored = localStorage.getItem('vfdPrefillContent');
const storedSummary = localStorage.getItem('vfdPrefillSummary');

if (stored) {
const { top, bottom } = JSON.parse(stored);
const content = textbox.value.replace(/^\s+/, '').replace(/\s+$/, '');
textbox.value = top + content + bottom;

if (summaryBox && storedSummary) {
summaryBox.value = storedSummary;
}

localStorage.removeItem('vfdPrefillContent');
localStorage.removeItem('vfdPrefillSummary');
}
}
}

});
});
//</nowiki>
//</nowiki>

Revision as of 08:24, 25 September 2025

//<nowiki>
mw.loader.using('mediawiki.util', function () {
    const pagePrefix = 'User:Euphoria/TestVfD/';

    if (!mw.config.get('wgPageName').startsWith(pagePrefix) || mw.config.get('wgAction') !== 'view') {
        return;
    }

    // Wait until MediaWiki content is ready
    mw.hook('wikipage.content').add(function ($content) {
        $content.find('.mw-headline').each(function () {
            const headline = this;
            const sectionName = headline.textContent.trim();
            if (!sectionName) return;

            const container = document.createElement('span');
            container.style.marginLeft = '10px';

            ['delete', 'keep', 'no consensus'].forEach(function (action) {
                const btn = document.createElement('a');
                btn.href = '#';
                btn.textContent = action.charAt(0).toUpperCase() + action.slice(1);
                btn.style.marginRight = '5px';
                btn.style.fontSize = '90%';
                btn.addEventListener('click', function (e) {
                    e.preventDefault();

                    const topText = '{{subst:vt|' + action + '. --~~~~}}\n==' + sectionName + '==\n';
                    const bottomText = '\n{{subst:vb}}';
                    const summary = 'Closed section "' + sectionName + '" as ' + action;

                    localStorage.setItem('vfdPrefillContent', JSON.stringify({ top: topText, bottom: bottomText }));
                    localStorage.setItem('vfdPrefillSummary', summary);

                    window.location.href = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit' });
                });
                container.appendChild(btn);
            });

            headline.parentNode.appendChild(container);
        });
    });
});
//</nowiki>