User:TFOWR/easyDiff2.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:TFOWR/easyDiff2 and an accompanying .css page at User:TFOWR/easyDiff2.css. |
// Schedule it to run after the HTML page is rendered
$(fullUrlLinks);
// Define main function
function fullUrlLinks() {
importStylesheet("User:TFOWR/easyDiff2.css");
doDiffs();
if (mw.config.get('wgNamespaceNumber') === -1) {
doSpecialLog();
}
}
function doSpecialLog() {
var url = document.URL;
if ('Special:Log' == getTitle(url)) {
var span = getSpan();
span.setAttribute('style', 'float: right;');
var args = new Array('type', 'user', 'page');
span.innerHTML += '{{fullurl:Special:Log' + getKvPairsString(args, url) + '}}';
document.getElementById('siteSub').appendChild(span);
}
}
function doDiffs() {
if (document.URL.indexOf('diff=') != -1) {
var prev = document.getElementById('mw-diff-otitle4');
var current = document.getElementById('mw-diff-ntitle4');
var prevId = getRevId(document.getElementById('mw-diff-otitle1').firstChild.firstChild.href);
var currentId = getRevId(document.getElementById('mw-diff-ntitle1').firstChild.firstChild.href);
// Left : diff2
if ((prevId != null) && ('prev' != prevId) && ('next' != prevId)) {
var span = getSpan();
var br = getBr();
prev.appendChild(br);
span.innerHTML += '{{diff2|' + prevId + '|<i>label</i>}}';
prev.appendChild(span);
}
// Right : diff2
if ((currentId != null) && ('prev' != currentId)
&& ('next' != currentId)) {
var span = getSpan();
var br = getBr();
current.appendChild(br);
span.innerHTML += '{{diff2|' + currentId + '|<i>label</i>}}';
current.appendChild(span);
}
// Left-right : diff
if ((prevId != null) && (prevId != 'prev') && (prevId != 'current')
&& ((currentId != null) && currentId != 'prev')
&& (currentId != 'current')) {
var span = getSpan();
var br = getBr();
current.appendChild(br);
span.innerHTML += '{{diff|1=' + getTitle(document.URL) + '|2='
+ currentId + '|3=' + prevId + '|4=<i>label</i>}}';
current.appendChild(span);
}
}
}
function getSpan() {
var rv = document.createElement('span');
rv.setAttribute('class', 'tfowr-diff');
return rv;
}
function getBr() {
return document.createElement('br');
}
function getRevId(href) {
var rv = getSubstring(href, "oldid=", "&");
if (rv != null)
return rv;
return getSubstring(document.URL, "diff=", "&");
}
function getTitle(url) {
return unescape(getSubstring(url, "title=", "&"));
}
function getKvPairsString(args, url) {
var rv = '';
for ( var i = 0; i < args.length; i++) {
var key = args[i];
var value = getSubstring(url, key + "=", "&");
if (value != null && value != '') {
if (rv == '') {
rv += '|';
} else {
rv += '&';
}
rv += key + '=' + unescape(value);
}
}
return rv;
}
function getSubstring(stringIn, start, end) {
if (stringIn == null)
return null;
if (stringIn.indexOf(start) == -1) {
return null;
}
var startIdx = stringIn.indexOf(start) + start.length;
var endIdx = stringIn.indexOf(end, startIdx);
if (endIdx != -1) {
return stringIn.substring(startIdx, endIdx);
} else {
return stringIn.substring(startIdx);
}
}