User:Euphoria/common.js: Difference between revisions
From Test Wiki
Content deleted Content added
fix |
fix |
||
| Line 1: | Line 1: | ||
//<nowiki> |
//<nowiki> |
||
mw.loader.using('mediawiki.util', function () { |
mw.loader.using('mediawiki.util', function () { |
||
const pagePrefix = 'User:Euphoria/TestVfD/'; |
|||
// Only run on relevant pages |
|||
if (mw.config.get('wgPageName').startsWith(pagePrefix)) { |
|||
// Buttons on page view |
|||
if (mw.config.get('wgAction') === 'view') { |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
// Store the content in localStorage |
|||
const topText = '{{subst:vt|' + action + '. --~~~~}}\n\n'; |
|||
| ⚫ | |||
| ⚫ | |||
localStorage.setItem('vfdPrefillContent', topText + bottomText); |
|||
localStorage.setItem('vfdPrefillSummary', summary); |
|||
// Redirect to edit page |
|||
window.location.href = mw.util.getUrl(mw.config.get('wgPageName'), { action: 'edit' }); |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
addClosureButton('Close as no consensus', 'no consensus'); |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
redirectToEdit(action); |
|||
| ⚫ | |||
} |
} |
||
// |
// On edit page: insert stored content |
||
if (mw.config.get('wgAction') === 'edit') { |
|||
const textbox = document.getElementById('wpTextbox1'); |
|||
| ⚫ | |||
const summaryBox = document.getElementById('wpSummary'); |
|||
| ⚫ | |||
if (textbox) { |
|||
const storedContent = localStorage.getItem('vfdPrefillContent'); |
|||
const storedSummary = localStorage.getItem('vfdPrefillSummary'); |
|||
| ⚫ | |||
| ⚫ | |||
if (storedContent) { |
|||
textbox.value = storedContent + textbox.value; |
|||
var editUrl = mw.util.getUrl(page, { |
|||
if (summaryBox && storedSummary) { |
|||
summaryBox.value = storedSummary; |
|||
} |
|||
| ⚫ | |||
// |
// Clear storage after use |
||
localStorage.removeItem('vfdPrefillContent'); |
|||
window.location.href = editUrl; |
|||
localStorage.removeItem('vfdPrefillSummary'); |
|||
| ⚫ | |||
} |
|||
} |
} |
||