User:Awesome Aasim/rcwidget.js

if (!rcwidget) { var rcwidget = {}; rcwidget.onlyshowores = (typeof onlyshowores !== 'undefined') ? onlyshowores : false; rcwidget.orestolerance = (typeof orestolerance !== 'undefined') ? orestolerance : 0.70; rcwidget.fetchtime = (typeof rcfetchtime !== 'undefined') ? rcfetchtime : 0.5 rcwidget.addToSidebar = function(text) { if (mw.config.get("skin") == "timeless") { $(' ' + text + '  ').appendTo("#mw-related-navigation"); $("#catlinks-sidebar").appendTo("#mw-related-navigation"); $("#other-languages").appendTo("#mw-related-navigation"); }       $(' ' + text + ' ').prependTo("#mw-panel"); $(' ' + text + ' ').prependTo("#sidebar"); $(' ' + text + ' ').prependTo("#mw_portlets"); $("#p-navigation").prependTo("#mw-panel"); $("#p-search").prependTo("#quickbar"); $('#p-logo').prependTo("#mw-site-navigation"); $('#p-logo').prependTo("#mw-panel"); $('#p-logo').prependTo("#sidebar"); $('#p-logo').prependTo("#mw_portlets"); $('ul.hlist:first').appendTo('#mw-mf-page-left'); if (mw.config.get("skin") == "vector" || mw.config.get("skin") == "vector-2022" ) { $("#rcwidget").addClass("mw-portlet mw-portlet-navigation vector-menu vector-menu-portal"); }   };    rcwidget.fetch = function { if (!document.hasFocus) { window.setTimeout(rcwidget.fetch, rcwidget.fetchtime * 1000); } else { var returnHTML = ""; returnHTML += ""; $.get(mw.config.get("wgScriptPath") + "/api.php", {				"action": "query",				"format": "json",				"list": "recentchanges",				"rcnamespace": "0|3",				"rcprop": "title|timestamp|flags|loginfo|oresscores|parsedcomment|user|ids|tags",				"rcshow": "!bot" + (rcwidget.onlyshowores ? "|oresreview" : ""),				"rctoponly": true,				"rclimit": "50",				"rctype": "edit|new"			}).done(function(result) {				if (result.error) {					console.error(result.error.info);		   		window.setTimeout(rcwidget.fetch, rcwidget.fetchtime * 1000);				} else {					var currDate = new Date;					for (var change of result.query.recentchanges) {						var changeDate = new Date(change.timestamp);						var mildate = new Date(currDate - changeDate);						var seconds = mildate.getUTCSeconds;						var minutes = mildate.getUTCMinutes;						var hours = mildate.getUTCHours;						if (typeof change.oresscores != 'undefined') {							if (typeof change.oresscores.damaging != 'undefined') {								if (typeof change.oresscores.damaging.true != 'undefined') {									if (rcwidget.onlyshowores && change.oresscores.damaging.true < rcwidget.orestolerance) {										continue;									} else {										returnHTML += ""; if (change.type == "edit" && change.oresscores.damaging) { if (change.oresscores.damaging.true >= rcwidget.orestolerance) { returnHTML += ""; }										}										returnHTML += '' + change.user + ' '; switch (change.type) { case "edit": if (change.tags.includes("mw-undo")) { returnHTML += "undid an edit to " + change.title + ''; } else if (change.tags.includes("mw-rollback")) { returnHTML += "rolled back edits to edit to " + change.title + '</a>'; } else if (change.ns == 3) { returnHTML += 'left a message for <a href="/wiki/' + change.title + '">' + change.title.replace("User talk:", "") + "</a>"; } else { returnHTML += "made an <a href=\"/wiki/Special:Diff/" + change.revid + "\">edit</a> to <a href=\"/wiki/" + change.title + "\">" + change.title + '</a>'; }												break; case "new": if (change.ns == 3) { returnHTML += 'left a message for <a href="/wiki/' + change.title + '">' + change.title.replace("User talk:", "") + "</a>"; } else { returnHTML += "created the page <a href=\"/wiki/" + change.title + "\">" + change.title + '</a>'; }												break; }										if (change.type == "edit" && change.oresscores.damaging) { if (change.oresscores.damaging.true >= rcwidget.orestolerance) { returnHTML += "</b>"; }										}										returnHTML += " <small class=\"rcwidget-date\" data-revtimestamp=\"" + change.timestamp + "\">"; if (hours > 0) { returnHTML += " " + hours + ((hours == 1) ? " hour" : " hours") + " ago"; } else if (minutes > 0) { returnHTML += " " + minutes + ((minutes == 1) ? " minute" : " minutes") + " ago"; } else if (seconds > 0) { returnHTML += " " + seconds + ((seconds == 1) ? " second" : " seconds") + " ago"; }										returnHTML += " "; returnHTML += "</li>"; }								} else { returnHTML += "<li>"; returnHTML += '<a href="/wiki/User_talk:' + change.user + '">' + change.user + '</a> '; switch (change.type) { case "edit": if (change.tags.includes("mw-undo")) { returnHTML += "<a href=\"/wiki/Project:Undo\">undid</a> an <a href=\"/wiki/Special:Diff/" + change.revid + "\">edit</a> to <a href=\"/wiki/" + change.title + "\">" + change.title + '</a>'; } else if (change.tags.includes("mw-rollback")) { returnHTML += "<a href=\"/wiki/Project:Rollback\">rolled back</a> edits to <a href=\"/wiki/Special:Diff/" + change.revid + "\">edit</a> to <a href=\"/wiki/" + change.title + "\">" + change.title + '</a>'; } else if (change.ns == 3) { returnHTML += 'left a message for <a href="/wiki/' + change.title + '">' + change.title.replace("User talk:", "") + "</a>"; } else { returnHTML += "made an <a href=\"/wiki/Special:Diff/" + change.revid + "\">edit</a> to <a href=\"/wiki/" + change.title + "\">" + change.title + '</a>'; }											break; case "new": if (change.ns == 3) { returnHTML += 'left a message for <a href="/wiki/' + change.title + '">' + change.title.replace("User talk:", "") + "</a>"; } else { returnHTML += "created the page <a href=\"/wiki/" + change.title + "\">" + change.title + '</a>'; }											break; }									returnHTML += " <small class=\"rcwidget-date\" data-revtimestamp=\"" + change.timestamp + "\">"; if (hours > 0) { returnHTML += " " + hours + ((hours == 1) ? " hour" : " hours") + " ago"; } else if (minutes > 0) { returnHTML += " " + minutes + ((minutes == 1) ? " minute" : " minutes") + " ago"; } else if (seconds > 0) { returnHTML += " " + seconds + ((seconds == 1) ? " second" : " seconds") + " ago"; }									returnHTML += " "; returnHTML += "</li>"; }							} else { returnHTML += "<li>"; returnHTML += '<a href="/wiki/User_talk:' + change.user + '">' + change.user + '</a> '; switch (change.type) { case "edit": if (change.tags.includes("mw-undo")) { returnHTML += "<a href=\"/wiki/Project:Undo\">undid</a> an <a href=\"/wiki/Special:Diff/" + change.revid + "\">edit</a> to <a href=\"/wiki/" + change.title + "\">" + change.title + '</a>'; } else if (change.tags.includes("mw-rollback")) { returnHTML += "<a href=\"/wiki/Project:Rollback\">rolled back</a> edits to <a href=\"/wiki/Special:Diff/" + change.revid + "\">edit</a> to <a href=\"/wiki/" + change.title + "\">" + change.title + '</a>'; } else if (change.ns == 3) { returnHTML += 'left a message for <a href="/wiki/' + change.title + '">' + change.title.replace("User talk:", "") + "</a>"; } else { returnHTML += "made an <a href=\"/wiki/Special:Diff/" + change.revid + "\">edit</a> to <a href=\"/wiki/" + change.title + "\">" + change.title + '</a>'; }										break; case "new": if (change.ns == 3) { returnHTML += 'left a message for <a href="/wiki/' + change.title + '">' + change.title.replace("User talk:", "") + "</a>"; } else { returnHTML += "created the page <a href=\"/wiki/" + change.title + "\">" + change.title + '</a>'; }										break; }								returnHTML += " <small class=\"rcwidget-date\" data-revtimestamp=\"" + change.timestamp + "\">"; if (hours > 0) { returnHTML += " " + hours + ((hours == 1) ? " hour" : " hours") + " ago"; } else if (minutes > 0) { returnHTML += " " + minutes + ((minutes == 1) ? " minute" : " minutes") + " ago"; } else if (seconds > 0) { returnHTML += " " + seconds + ((seconds == 1) ? " second" : " seconds") + " ago"; }								returnHTML += " "; returnHTML += "</li>"; }						} else { returnHTML += "<li>"; returnHTML += '<a href="/wiki/User_talk:' + change.user + '">' + change.user + '</a> '; switch (change.type) { case "edit": if (change.tags.includes("mw-undo")) { returnHTML += "<a href=\"/wiki/Project:Undo\">undid</a> an <a href=\"/wiki/Special:Diff/" + change.revid + "\">edit</a> to <a href=\"/wiki/" + change.title + "\">" + change.title + '</a>'; } else if (change.tags.includes("mw-rollback")) { returnHTML += "<a href=\"/wiki/Project:Rollback\">rolled back</a> edits to <a href=\"/wiki/Special:Diff/" + change.revid + "\">edit</a> to <a href=\"/wiki/" + change.title + "\">" + change.title + '</a>'; } else if (change.ns == 3) { returnHTML += 'left a message for <a href="/wiki/' + change.title + '">' + change.title.replace("User talk:", "") + "</a>"; } else { returnHTML += "made an <a href=\"/wiki/Special:Diff/" + change.revid + "\">edit</a> to <a href=\"/wiki/" + change.title + "\">" + change.title + '</a>'; }									break; case "new": if (change.ns == 3) { returnHTML += 'left a message for <a href="/wiki/' + change.title + '">' + change.title.replace("User talk:", "") + "</a>"; } else { returnHTML += "created the page <a href=\"/wiki/" + change.title + "\">" + change.title + '</a>'; }									break; }							returnHTML += " <small class=\"rcwidget-date\" data-revtimestamp=\"" + change.timestamp + "\">"; if (hours > 0) { returnHTML += " " + hours + ((hours == 1) ? " hour" : " hours") + " ago"; } else if (minutes > 0) { returnHTML += " " + minutes + ((minutes == 1) ? " minute" : " minutes") + " ago"; } else if (seconds > 0) { returnHTML += " " + seconds + ((minutes == 1) ? " second" : " seconds") + " ago"; }							returnHTML += " "; returnHTML += "</li>"; }					}					returnHTML += "<li><a href=\"/wiki/Special:RecentChanges\">View all recent changes</a></li>" returnHTML += "</ul>"; $("#rcwidget-content").html(returnHTML); if ($("#rcwidget-content").text.toLowerCase == "View all recent changes".toLowerCase) { $("#rcwidget-content").html("<ul><li>No recent changes found.</li></ul>"); }				}		   	window.setTimeout(rcwidget.fetch, rcwidget.fetchtime * 1000); }).fail(function(result) { window.setTimeout(rcwidget.fetch, rcwidget.fetchtime * 1000); });   	}    };    $("#rcwidget-content").css("height", "auto");    $("#rcwidget-content").css("overflow", "auto");	$(document).ready(function { rcwidget.addToSidebar((mw.config.get('skin') == 'vector' || mw.config.get('skin') == 'vector-2022') ? ' <a href="/wiki/Special:RecentChanges">Recent changes</a> Loading... ' : '<h3 id="rcwidget-label" lang="en" dir="ltr"> <a href="/wiki/Special:RecentChanges">Recent changes</a> Loading... '); rcwidget.fetch; window.setInterval(function {			var currDate = new Date;   		$('.rcwidget-date').each(function { var changeDate = new Date($(this).data('revtimestamp')); var mildate = new Date(currDate - changeDate); var seconds = mildate.getUTCSeconds; var minutes = mildate.getUTCMinutes; var hours = mildate.getUTCHours; if (hours > 0) { $(this).html(hours + ((hours == 1) ? " hour" : " hours") + " ago"); } else if (minutes > 0) { $(this).html(minutes + ((minutes == 1) ? " minute" : " minutes") + " ago"); } else if (seconds > 0) { $(this).html(seconds + ((seconds == 1) ? " second" : " seconds") + " ago"); }   		})    	}, rcwidget.fetchtime); }); }