User:Awesome Aasim/rcwidget.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:Awesome Aasim/rcwidget. |
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") {
$('<div class="sidebar-chunk" id="rcwidget"><div class="sidebar-inner">' + text + '</div></div>').appendTo("#mw-related-navigation");
$("#catlinks-sidebar").appendTo("#mw-related-navigation");
$("#other-languages").appendTo("#mw-related-navigation");
}
$('<div class="portal" role="navigation" id="rcwidget" aria-labelledby="p-rcwidget-label">' + text + '</div>').prependTo("#mw-panel");
$('<div role="navigation" class="portlet generated-sidebar" id="rcwidget" aria-labelledby="p-rcwidget-label">' + text + '</div>').prependTo("#sidebar");
$('<div class="portlet" id="rcwidget">' + text + '</div>').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 += "<ul>";
$.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 += "<li>";
if (change.type == "edit" && change.oresscores.damaging) {
if (change.oresscores.damaging.true >= rcwidget.orestolerance) {
returnHTML += "<b>";
}
}
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;
}
if (change.type == "edit" && change.oresscores.damaging) {
if (change.oresscores.damaging.true >= rcwidget.orestolerance) {
returnHTML += "</b>";
}
}
returnHTML += "<br><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 += "</small>";
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 += "<br><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 += "</small>";
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 += "<br><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 += "</small>";
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 += "<br><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 += "</small>";
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') ? '<div id="rcwidget-label" lang="en" dir="ltr"><span><a href="/wiki/Special:RecentChanges">Recent changes</a></span></div><div class="mw-portlet-body body pBody" id="rcwidget-content" style="height:250px;overflow:hidden;">Loading...</div>' : '<h3 id="rcwidget-label" lang="en" dir="ltr"><span><a href="/wiki/Special:RecentChanges">Recent changes</a></span></h3><div class="mw-portlet-body body pBody" id="rcwidget-content" style="height:250px;overflow:hidden;">Loading...</div>');
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);
});
}