User:Xaradnam/monobook.js: Difference between revisions
Appearance
Content deleted Content added
m + |
m mv to common.js |
||
(36 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
// <nowiki> |
|||
importScript('User:Shubinator/DYKcheck.js'); |
|||
//================================================== |
|||
CurPg=mw.config.get('wgPageName'); // Current page name |
CurPg=mw.config.get('wgPageName'); // Current page name |
||
CurNSnum=mw.config.get('wgNamespaceNumber'); |
|||
//================================================== |
//================================================== |
||
function printValue(txt, val) |
|||
{$('body').append('<center><h4><tt>' + txt + ': ' + val + ' </tt></h4></center>');} |
|||
// ========= DISPLAY AT BOTTOM (OR TOP) OF PAGE ========== |
|||
function showTxt(txt,top) |
|||
{ |
|||
line='<h4 style="text-align:center;"><tt>'+txt+'</tt></h4>'; |
|||
if (top) $('body').prepend(line); |
|||
else $('body').append(line); |
|||
} |
|||
// a convenient way to display test values |
|||
function printValue(txt, val) { |
|||
if (CurPg=="User:Xaradnam/monobook.js") |
|||
$('body').append("<center><h4><tt>" + txt + ": " + val + " </tt></h4></center>"); |
|||
{ |
|||
} |
|||
showTxt("This is "+CurPg, 1); |
|||
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); |
|||
} |
|||
printValue("CurPg", CurPg); |
|||
//================================================== |
//================================================== |
||
if (CurPg=="User:Xaradnam/monobook.js") printValue("CurPg", CurPg); |
|||
DiffOnly = { |
|||
// Section subscribe |
|||
watchlist: true, |
|||
CurNSnum=mw.config.get('wgNamespaceNumber'); |
|||
diff: false |
|||
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; |
|||
} |
} |
||
importScript('User:Mr. Stradivarius/gadgets/DiffOnly.js'); |
|||
importScript('User:Theleekycauldron/DYKViews.js'); |
|||
// ======== SHOW {{Unsigned}} AT BOTTOM OF DIFF TALK+ PAGES ========= |
|||
if (document.getElementById('mw-diff-otitle1') || document.getElementById('mw-diff-ntitle1')) { |
|||
// For potential unsigned comments on talk, WP, template (for DYK noms) |
|||
// Works with any of the four Wiki date formats available in Prefs |
|||
if (mw.config.get('wgDiffNewId') && (CurNSnum%2==1||CurNSnum==4||CurNSnum==10)) |
|||
{ |
|||
const month=[]; |
|||
month["Jan"]="January"; month["Feb"]="February"; month["Mar"]="March"; |
|||
month["Apr"]="April"; month["May"]="May"; month["Jun"]="June"; |
|||
month["Jul"]="July"; month["Aug"]="August"; month["Sep"]="September"; |
|||
month["Oct"]="October"; month["Nov"]="November"; month["Dec"]="December"; |
|||
usr=document.getElementById('mw-diff-ntitle2').firstChild.firstChild.firstChild.nodeValue; |
|||
function convertTimestampStringToDate(id) { |
|||
rev=document.getElementById('mw-diff-ntitle1').firstChild.firstChild.firstChild.nodeValue; |
|||
showTxt("rev=" + rev); |
|||
var str = /evision as of /g |
|||
//Change 09:31, October 25, 2021 to format Apple accepts: October 25, 2021 09:31 |
|||
str.lastIndex = 0; |
|||
badrev=rev.replace(/(Latest )?Revision as of (..:..), (.*)/i, "$2, $3"); |
|||
str.test(timestamp) |
|||
showTxt("badrev=" + badrev); |
|||
var date = timestamp.substring(str.lastIndex) |
|||
var badts = new Date(badrev); |
|||
/* |
|||
showTxt("badts=" + badts); |
|||
Safari doesn't recognize Wikipedia's date format. |
|||
goodrev=rev.replace(/(Latest )?Revision as of (..:..), (.*)/i, "$3 $2"); |
|||
Every other browser can just use the date string |
|||
showTxt("goodrev=" + goodrev); |
|||
object above. |
|||
var ts = new Date(goodrev); |
|||
*/ |
|||
showTxt("ts=" + ts); |
|||
var str1 = /[A-z]+/ |
|||
ts=ts.toUTCString(); |
|||
var str2 = /\d+/g |
|||
showTxt("ts2=" + ts); |
|||
var monthtext = date.match(str1); |
|||
badts=badts.toUTCString(); |
|||
var testdate = date.match(str2); |
|||
showTxt("badts2=" + badts); |
|||
var hours = testdate[0]; |
|||
mth=ts.substr(8, 3); |
|||
var minutes = testdate[1]; |
|||
//UTCtime: Sat, 06 Feb 2021 17 : 42 :00 GMT → 09:42, 6 February 2021 (UTC) |
|||
var day = testdate[2]; |
|||
ts=ts.replace(/..., (\d+) (...) (\d+) (\d+):(\d+).*/, "$4:$5, $1 $2 $3 (UTC)"); |
|||
var year = testdate[3]; |
|||
ts=ts.replace(mth, month[mth]).replace(", 0", ", "); |
|||
var months = ['January','February','March','April','May','June','July','August','September','October','November','December']; |
|||
showTxt("{{subst:Unsigned|" + usr + "|" + ts + "}}"); |
|||
for (i in months) { |
|||
} |
|||
if (monthtext==months[i]) { |
|||
var month = i; |
|||
var ts1= new Date("13:01 October 25, 2021"); //debugging for iPad |
|||
break; |
|||
showTxt("ts1=" + ts1); //debugging for iPad |
|||
} |
|||
i++ |
|||
var ts2= new Date("October 25, 2021 13:01"); //debugging for iPad |
|||
} |
|||
showTxt("ts2=" + ts2); //debugging for iPad |
|||
/* |
|||
var ts3= new Date("Oct 25, 2021 13:01"); //debugging for iPad |
|||
showTxt("ts3=" + ts3); //debugging for iPad |
|||
var ts4= new Date("Oct 25 2021 13:01"); //debugging for iPad |
|||
showTxt("ts4=" + ts4); //debugging for iPad |
|||
var ts5= new Date("13:01 10-25-2021"); //debugging for iPad |
|||
End Safari madness |
|||
showTxt("ts5=" + ts5); //debugging for iPad |
|||
importScript('User:Shubinator/DYKcheck.js'); |
|||
importScript('user:theleekycauldron/DYK promoter.js'); |
|||
*/ |
|||
date = new Date(year,month,day,hours,minutes); |
|||
return date; |
|||
} |
|||
var leftNode = document.getElementById('mw-diff-otitle1'); |
|||
// </nowiki> |
|||
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 |
|||
} |
Latest revision as of 23:21, 31 August 2022
// <nowiki>
CurPg=mw.config.get('wgPageName'); // Current page name
CurNSnum=mw.config.get('wgNamespaceNumber');
//==================================================
function printValue(txt, val)
{$('body').append('<center><h4><tt>' + txt + ': ' + val + ' </tt></h4></center>');}
// ========= DISPLAY AT BOTTOM (OR TOP) OF PAGE ==========
function showTxt(txt,top)
{
line='<h4 style="text-align:center;"><tt>'+txt+'</tt></h4>';
if (top) $('body').prepend(line);
else $('body').append(line);
}
// a convenient way to display test values
if (CurPg=="User:Xaradnam/monobook.js")
{
showTxt("This is "+CurPg, 1);
}
//==================================================
if (CurPg=="User:Xaradnam/monobook.js") printValue("CurPg", CurPg);
DiffOnly = {
watchlist: true,
diff: false
}
importScript('User:Mr. Stradivarius/gadgets/DiffOnly.js');
importScript('User:Theleekycauldron/DYKViews.js');
// ======== SHOW {{Unsigned}} AT BOTTOM OF DIFF TALK+ PAGES =========
// For potential unsigned comments on talk, WP, template (for DYK noms)
// Works with any of the four Wiki date formats available in Prefs
if (mw.config.get('wgDiffNewId') && (CurNSnum%2==1||CurNSnum==4||CurNSnum==10))
{
const month=[];
month["Jan"]="January"; month["Feb"]="February"; month["Mar"]="March";
month["Apr"]="April"; month["May"]="May"; month["Jun"]="June";
month["Jul"]="July"; month["Aug"]="August"; month["Sep"]="September";
month["Oct"]="October"; month["Nov"]="November"; month["Dec"]="December";
usr=document.getElementById('mw-diff-ntitle2').firstChild.firstChild.firstChild.nodeValue;
rev=document.getElementById('mw-diff-ntitle1').firstChild.firstChild.firstChild.nodeValue;
showTxt("rev=" + rev);
//Change 09:31, October 25, 2021 to format Apple accepts: October 25, 2021 09:31
badrev=rev.replace(/(Latest )?Revision as of (..:..), (.*)/i, "$2, $3");
showTxt("badrev=" + badrev);
var badts = new Date(badrev);
showTxt("badts=" + badts);
goodrev=rev.replace(/(Latest )?Revision as of (..:..), (.*)/i, "$3 $2");
showTxt("goodrev=" + goodrev);
var ts = new Date(goodrev);
showTxt("ts=" + ts);
ts=ts.toUTCString();
showTxt("ts2=" + ts);
badts=badts.toUTCString();
showTxt("badts2=" + badts);
mth=ts.substr(8, 3);
//UTCtime: Sat, 06 Feb 2021 17 : 42 :00 GMT → 09:42, 6 February 2021 (UTC)
ts=ts.replace(/..., (\d+) (...) (\d+) (\d+):(\d+).*/, "$4:$5, $1 $2 $3 (UTC)");
ts=ts.replace(mth, month[mth]).replace(", 0", ", ");
showTxt("{{subst:Unsigned|" + usr + "|" + ts + "}}");
}
var ts1= new Date("13:01 October 25, 2021"); //debugging for iPad
showTxt("ts1=" + ts1); //debugging for iPad
var ts2= new Date("October 25, 2021 13:01"); //debugging for iPad
showTxt("ts2=" + ts2); //debugging for iPad
var ts3= new Date("Oct 25, 2021 13:01"); //debugging for iPad
showTxt("ts3=" + ts3); //debugging for iPad
var ts4= new Date("Oct 25 2021 13:01"); //debugging for iPad
showTxt("ts4=" + ts4); //debugging for iPad
var ts5= new Date("13:01 10-25-2021"); //debugging for iPad
showTxt("ts5=" + ts5); //debugging for iPad
importScript('User:Shubinator/DYKcheck.js');
importScript('user:theleekycauldron/DYK promoter.js');
// </nowiki>