MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 113: | Line 113: | ||
if (mw.config.get('wgPageName') !== 'Main_Page') return; | if (mw.config.get('wgPageName') !== 'Main_Page') return; | ||
var groups = mw.config.get('wgUserGroups') || []; | |||
var | var isAdmin = groups.indexOf('sysop') !== -1; | ||
if (!isAdmin) return; | |||
var container = document.querySelector('.vector-header-end'); | |||
if (!container) return; | |||
var btn = document.createElement('button'); | |||
btn.className = 'grantha-new-btn'; | |||
btn.innerText = '+ New'; | |||
btn.onclick = openCreateDialog; | |||
container.prepend(btn); | |||
}); | |||
function openCreateDialog() { | |||
var overlay = document.createElement('div'); | |||
var | overlay.className = 'grantha-modal'; | ||
overlay.innerHTML = ` | |||
<div class="grantha-modal-box"> | |||
<div class="gm-title">Create New Document</div> | |||
<input type="text" id="gm-input" placeholder="Enter page name"/> | |||
<div class="gm-actions"> | |||
<button id="gm-cancel">Cancel</button> | |||
<button id="gm-create">Create</button> | |||
</div> | |||
</div> | |||
`; | |||
document.body.appendChild(overlay); | |||
document.getElementById('gm-cancel').onclick = function () { | |||
overlay.remove(); | |||
}; | |||
document.getElementById('gm-create').onclick = function () { | |||
var name = document.getElementById('gm-input').value.trim(); | |||
if (!name) return; | |||
name = name.replace(/\s+/g, '_'); | |||
}); | window.location.href = mw.util.getUrl(name, { action: 'edit' }); | ||
}; | |||
} | |||