User:Euphoria/common.js: Difference between revisions
From Test Wiki
Content deleted Content added
fix |
fix |
||
| Line 5: | Line 5: | ||
if (mw.config.get('wgPageName').startsWith(pagePrefix)) { |
if (mw.config.get('wgPageName').startsWith(pagePrefix)) { |
||
// |
// Only on page view |
||
if (mw.config.get('wgAction') === 'view') { |
if (mw.config.get('wgAction') === 'view') { |
||
// Find all section headings (h2) |
|||
document.querySelectorAll('h2 .mw-headline').forEach(function (headline) { |
|||
| ⚫ | |||
const sectionName = headline.textContent.trim(); |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
// Only add buttons to sections that match your criteria (optional) |
|||
if (sectionName) { |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
const container = document.createElement('span'); |
|||
container.style.marginLeft = '10px'; |
|||
// Add buttons |
|||
['delete', 'keep', 'no consensus'].forEach(function (action) { |
|||
const btn = document.createElement('a'); |
|||
| ⚫ | |||
| ⚫ | |||
btn.textContent = action.charAt(0).toUpperCase() + action.slice(1); |
|||
btn.style.marginRight = '5px'; |
|||
btn.style.fontSize = '90%'; |
|||
| ⚫ | |||
| ⚫ | |||
const topText = '{{subst:vt|' + action + '. --~~~~}}\n==' + sectionName + '==\n'; |
|||
addClosureButton('Close as delete', 'delete'); |
|||
const bottomText = '\n{{subst:vb}}'; |
|||
addClosureButton('Close as keep', 'keep'); |
|||
| ⚫ | |||
addClosureButton('Close as no consensus', 'no consensus'); |
|||
| ⚫ | |||
localStorage.setItem('vfdPrefillSummary', summary); |
|||
window.location.href = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit' }); |
|||
| ⚫ | |||
container.appendChild(btn); |
|||
| ⚫ | |||
| ⚫ | |||
headline.parentNode.appendChild(container); |
|||
| ⚫ | |||
| ⚫ | |||
} |
} |
||
// Edit page prefill |
// Edit page prefill (same as before) |
||
if (mw.config.get('wgAction') === 'edit') { |
if (mw.config.get('wgAction') === 'edit') { |
||
const textbox = document.getElementById('wpTextbox1'); |
const textbox = document.getElementById('wpTextbox1'); |
||
| Line 46: | Line 58: | ||
if (stored) { |
if (stored) { |
||
const { top, bottom } = JSON.parse(stored); |
const { top, bottom } = JSON.parse(stored); |
||
// Remove leading/trailing blank lines from existing content |
|||
const content = textbox.value.replace(/^\s+/, '').replace(/\s+$/, ''); |
const content = textbox.value.replace(/^\s+/, '').replace(/\s+$/, ''); |
||
| ⚫ | |||
textbox.value = top + content + bottom; |
textbox.value = top + content + bottom; |
||
| Line 57: | Line 65: | ||
} |
} |
||
// Clear storage |
|||
localStorage.removeItem('vfdPrefillContent'); |
localStorage.removeItem('vfdPrefillContent'); |
||
localStorage.removeItem('vfdPrefillSummary'); |
localStorage.removeItem('vfdPrefillSummary'); |
||