User:Xaradnam/monobook.js: Difference between revisions
Appearance
Content deleted Content added
m + |
m → ← |
||
Line 1: | Line 1: | ||
importScript('User:Shubinator/DYKcheck.js'); |
importScript('User:Shubinator/DYKcheck.js'); |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
//================================================== |
//================================================== |
||
Line 186: | Line 198: | ||
} |
} |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ |
Revision as of 06:35, 20 October 2021
importScript('User:Shubinator/DYKcheck.js');
//==================================================
function printValue(txt, val) {
$('body').append("<center><h4><tt>" + txt + ": " + val + " </tt></h4></center>");
}
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);
printValue("CurPg", CurPg);
//==================================================
// 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>';
});
});
//==================================================
CurPg=mw.config.get('wgPageName'); // Current page name
// ======== 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
}