MediaWiki:Gadget-PatrolLinks.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
// Consistently places the patrol link on file pages
// by Espyo
$(function() {
'use strict';
if(!mw || mw.config.get('wgCanonicalNamespace') != 'File') return;
var patrolLinkDiv = document.getElementsByClassName('patrollink');
if(patrolLinkDiv.length == 0) {
return;
}
patrolLinkDiv = patrolLinkDiv[0];
var fileTocDiv = document.getElementById('filetoc');
if(fileTocDiv == null) {
return;
}
fileTocDiv.after(patrolLinkDiv);
});
// Consistently places the patrol link on diff pages
// by Espyo
$(function() {
'use strict';
if(!mw.config.get('wgDiffOldId') || !mw.config.get('wgDiffNewId')) return;
// Move the div in the "new" side of the diff.
var nTitle4El = document.getElementById('mw-diff-ntitle4');
if(nTitle4El) {
var nTitleParentEl = nTitle4El.parentNode;
var nTitle1El = document.getElementById('mw-diff-ntitle1');
nTitleParentEl.insertBefore(nTitle4El, nTitle1El);
}
// Move the div in the "old" side of the diff.
var oTitle4El = document.getElementById('mw-diff-otitle4');
if(oTitle4El) {
var oTitleParentEl = oTitle4El.parentNode;
var oTitle1El = document.getElementById('mw-diff-otitle1');
oTitleParentEl.insertBefore(oTitle4El, oTitle1El);
}
// Arrange the next and patrol buttons to be fixed.
if(nTitle4El) {
var nextDiv = document.createElement('div');
var patrolDiv = document.createElement('div');
nextDiv.style.width = '50%';
patrolDiv.style.width = '50%';
nextDiv.style.display = 'inline-block';
patrolDiv.style.display = 'inline-block';
patrolDiv.style.whiteSpace = 'nowrap';
patrolDiv.style.overflow = 'clip';
var nextA = null;
var patrolSpan = null;
var space = null;
for(var i = 0; i < nTitle4El.childNodes.length; i++) {
if(nTitle4El.childNodes[i].nodeType == Node.TEXT_NODE) {
space = nTitle4El.childNodes[i];
} else {
if(nTitle4El.childNodes[i].tagName == 'A') {
nextA = nTitle4El.childNodes[i];
} else {
patrolSpan = nTitle4El.childNodes[i];
}
}
}
if(nextA) {
nextDiv.appendChild(nextA);
}
if(patrolSpan) {
patrolDiv.appendChild(patrolSpan);
}
if(space) {
space.remove();
}
nTitle4El.appendChild(patrolDiv);
nTitle4El.appendChild(nextDiv);
}
// Arrange the previous button to match.
if(oTitle4El) {
var oldDiv = document.createElement('div');
oldDiv.style.width = '50%';
oldDiv.style.display = 'inline-block';
var oldA = document.getElementById('differences-oldlink');
if(oldA) {
oldDiv.appendChild(oldA);
}
oTitle4El.appendChild(oldDiv);
}
});