User:Euphoria/common.js: Difference between revisions
From Test Wiki
Content deleted Content added
fix |
fix |
||
| Line 3: | Line 3: | ||
const pagePrefix = 'User:Euphoria/TestVfD/'; |
const pagePrefix = 'User:Euphoria/TestVfD/'; |
||
// Only run on relevant pages |
|||
if (mw.config.get('wgPageName').startsWith(pagePrefix)) { |
if (mw.config.get('wgPageName').startsWith(pagePrefix)) { |
||
// |
// Page view buttons |
||
if (mw.config.get('wgAction') === 'view') { |
if (mw.config.get('wgAction') === 'view') { |
||
| Line 19: | Line 18: | ||
e.preventDefault(); |
e.preventDefault(); |
||
const topText = '{{subst:vt|' + action + '. --~~~~}}\n'; |
|||
const |
const bottomText = '\n{{subst:vb}}'; |
||
const bottomText = '\n\n{{subst:vb}}'; |
|||
const summary = 'Closed as ' + action; |
const summary = 'Closed as ' + action; |
||
localStorage.setItem('vfdPrefillContent', topText |
localStorage.setItem('vfdPrefillContent', JSON.stringify({ top: topText, bottom: bottomText })); |
||
localStorage.setItem('vfdPrefillSummary', summary); |
localStorage.setItem('vfdPrefillSummary', summary); |
||
// Redirect to edit page |
|||
window.location.href = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit' }); |
window.location.href = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit' }); |
||
}); |
}); |
||
| Line 38: | Line 35: | ||
} |
} |
||
// |
// Edit page prefill |
||
if (mw.config.get('wgAction') === 'edit') { |
if (mw.config.get('wgAction') === 'edit') { |
||
const textbox = document.getElementById('wpTextbox1'); |
const textbox = document.getElementById('wpTextbox1'); |
||
| Line 44: | Line 41: | ||
if (textbox) { |
if (textbox) { |
||
const |
const stored = localStorage.getItem('vfdPrefillContent'); |
||
const storedSummary = localStorage.getItem('vfdPrefillSummary'); |
const storedSummary = localStorage.getItem('vfdPrefillSummary'); |
||
if ( |
if (stored) { |
||
const { top, bottom } = JSON.parse(stored); |
|||
// Remove leading/trailing blank lines from existing content |
|||
const content = textbox.value.replace(/^\s+/, '').replace(/\s+$/, ''); |
|||
// Insert top + content + bottom with proper spacing |
|||
textbox.value = top + content + bottom; |
|||
if (summaryBox && storedSummary) { |
if (summaryBox && storedSummary) { |
||
summaryBox.value = storedSummary; |
summaryBox.value = storedSummary; |
||
} |
} |
||
// Clear storage |
// Clear storage |
||
localStorage.removeItem('vfdPrefillContent'); |
localStorage.removeItem('vfdPrefillContent'); |
||
localStorage.removeItem('vfdPrefillSummary'); |
localStorage.removeItem('vfdPrefillSummary'); |
||