User:Xaradnam/monobook.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. |
The accompanying .css page for this skin is at User:Xaradnam/monobook.css. |
importScript('User:Shubinator/DYKcheck.js');
//==================================================
CurPg=mw.config.get('wgPageName'); // Current page name
//==================================================
function printValue(txt, val) {
$('body').append("<center><h4><tt>" + txt + ": " + val + " </tt></h4></center>");
}
if (mw.config.get('wgRevisionId')) {
printValue("old time", document.getElementById('mw-diff-otitle1').firstChild.firstChild.firstChild.nodeValue);
printValue("old user", document.getElementById('mw-diff-otitle2').firstChild.firstChild.firstChild.nodeValue);
printValue("new time", document.getElementById('mw-diff-ntitle1').firstChild.firstChild.firstChild.nodeValue);
printValue("new user", document.getElementById('mw-diff-ntitle2').firstChild.firstChild.firstChild.nodeValue);
}
var time = new Date();
printValue("CurPg", CurPg);
printValue("30+4", 30+4);
//printValue("UTC", time.UTC());
printValue("TimeOffset", time.getTimezoneOffset()/60);
text1="Revision as of 11:19, 13 April 1998";
text2="Latest revision as of 19:29, 23 May 1998";
printValue('text1', text1);
printValue('text1 replaced', text1.replace(/(Latest )?Revision as of /i, ""));
printValue('text2', text2);
printValue('text2 replaced', text2.replace(/(Latest )?Revision as of /i, ""));
//==================================================
// Section subscribe
CurNSnum=mw.config.get('wgNamespaceNumber');
if (CurNSnum%2==1||CurNSnum==4)
{mw.util.addPortletLink(
'p-tb',
mw.config.get('wgScript')+'?title='+mw.config.get('wgPageName')+'&dtenable=1',
'Section subscribe'
);}
//==================================================
// Add unredirected link next to redirects; from [[User:BrandonXLF/NoRedirect.js]]
$(function() {
$('#mw-content-text .mw-redirect').after(function() {
return this.href.indexOf('redirect=no') !== -1 || this.href.indexOf('action=') !== -1 || this.href.indexOf('diff=') !== -1 ? ''
: '<a href="' +
this.href +
(this.href.includes('?') ? '&' : '?') +
'redirect=no" title="' +
(this.title || this.href) +
' (redirect pg)"><span style="color:#534e8a"><sup> Я</sup></span></a>';
});
});
// ======== ADD DIFF INFO TO BOTTOM OF PAGE WHEN APPLICABLE =========
$.when( $.ready, mw.loader.using(["mediawiki.util"]) ).then( function () {
var suffix = mw.config.get("wgDiffNewId");
if (suffix) {
if (document.getElementsByClassName("diff-multi").length ||
CurPg === "Special:ComparePages") {
suffix = mw.config.get("wgDiffOldId") + "/" + suffix;
}
$('body').append("<center><h4><tt>[[Special:Diff/" + suffix + "|diff]]</tt></h4></center>");
} else {
var oldidMatch = mw.util.getParamValue("oldid");
if(oldidMatch) {
$('body').append("<center><h4><tt>[[Special:Permalink/" + oldidMatch + "|permalink]]</tt></h4></center>");
}
}
} );
//==================================================
//Adds time between diffs and time since each revision
// User:Dudemanfellabra/diffs.js
function DateSub(Date1,Date2) {
var timeDifference = Date2 - Date1;
var minutesAgo = Math.round(timeDifference / 1000 / 60);
var hoursAgo = 0
var daysAgo = 0
var hoursText = 'hour'
var daysText = 'day'
while (minutesAgo >= 60) {
minutesAgo = minutesAgo-60;
hoursAgo++;
}
while (hoursAgo >= 24) {
hoursAgo = hoursAgo-24;
daysAgo++;
}
if (hoursAgo!=1)
hoursText = hoursText + 's';
if (daysAgo!=1)
daysText = daysText + 's';
if (daysAgo > 0) {
if (hoursAgo > 0) {
if (minutesAgo <=1 ) {
minutesAgo = daysAgo + ' ' + daysText + ', ' + hoursAgo + ' ' + hoursText;
}
else {
minutesAgo = daysAgo + ' ' + daysText + ', ' + hoursAgo + ' ' + hoursText + ', ' + minutesAgo + ' minutes';
}
}
else {
if (minutesAgo <=1 ) {
minutesAgo = daysAgo + ' ' + daysText;
}
else {
minutesAgo = daysAgo + ' ' + daysText + ', ' + minutesAgo + ' minutes';
}
}
}
else {
if (hoursAgo > 0) {
if (minutesAgo <=1 ) {
minutesAgo = hoursAgo + ' ' + hoursText;
}
else {
minutesAgo = hoursAgo + ' ' + hoursText + ', ' + minutesAgo + ' minutes';
}
}
else {
if (minutesAgo <=1 ) {
minutesAgo = 'Less than a minute';
}
else {
minutesAgo = minutesAgo + ' minutes';
}
}
}
return minutesAgo;
}
if (document.getElementById('mw-diff-otitle1') || document.getElementById('mw-diff-ntitle1')) {
function convertTimestampStringToDate(id) {
var timestamp = document.getElementById(id).firstChild.firstChild.firstChild.nodeValue;
var str = /evision as of /g
str.lastIndex = 0;
str.test(timestamp)
var date = timestamp.substring(str.lastIndex)
/*
Safari doesn't recognize Wikipedia's date format.
Every other browser can just use the date string
object above.
*/
var str1 = /[A-z]+/
var str2 = /\d+/g
var monthtext = date.match(str1);
var testdate = date.match(str2);
var hours = testdate[0];
var minutes = testdate[1];
var day = testdate[2];
var year = testdate[3];
var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
for (i in months) {
if (monthtext==months[i]) {
var month = i;
break;
}
i++
}
/*
End Safari madness
*/
date = new Date(year,month,day,hours,minutes);
return date;
}
var leftNode = document.getElementById('mw-diff-otitle1');
var rightNode = document.getElementById('mw-diff-ntitle1');
var firstDate = convertTimestampStringToDate('mw-diff-otitle1');
var secondDate = convertTimestampStringToDate('mw-diff-ntitle1');
function TimeBetweenDiffs() {
var minutesAgo = DateSub(firstDate,secondDate);
var newNode = document.createElement('span');
newNode.setAttribute('style', 'font-weight:bold; color:red;')
newNode.appendChild(document.createTextNode('(' + minutesAgo + ' later)'));
newNode.appendChild(document.createElement('br'));
rightNode.insertBefore(newNode, rightNode.firstChild);
}
function TimeSinceDiff() {
var DateNow = new Date();
var minutesAgo1 = DateSub(firstDate,DateNow);
var minutesAgo2 = DateSub(secondDate,DateNow);
document.getElementById('mw-diff-otitle1').title=minutesAgo1 + ' ago';
document.getElementById('mw-diff-ntitle1').title=minutesAgo2 + ' ago';
var t = setTimeout("TimeSinceDiff()",60000);
}
$(window).load(TimeSinceDiff); // Adds time since displayed diffs as tooltip
$(window).load(TimeBetweenDiffs); // Adds time between diffs
}