User:Mojtabakd/scripts/HistoryHighlight.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:Mojtabakd/scripts/HistoryHighlight. |
// Significantly Modified from [[User:Guywan/Scripts/HistoryHighlight.js]]
// I copied the original version from https://fa.wikipedia.org/wiki/کاربر:Jeeputer/historyHighlight.js
// This script is under test, it's not usable yet.
$(function()
{
if(mw.config.get("wgCanonicalSpecialPageName") == "Contributions")
{
// Set the username in local storage.
mw.cookie.set("hh-username", mw.config.get("wgRelevantUserName"));
}
else if(mw.config.get("wgAction") == "history")
{
var userlist = "";
$("#pagehistory li").each(function()
{
if (userlist == "")
{
userlist = $(".history-user a bdi", this).html();
}
else
{
userlist += "|" + $(".history-user a bdi", this).html();
}
});
var url = "https://en.wikipedia.org/w/api.php";
var params =
{
action: "query",
list: "users",
ususers: userlist,
usprop: "groups",
format: "json"
};
url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
fetch(url)
.then(function(response){return response.json();})
.then(function(response)
{
var users = response.query.users;
var myusername = mw.cookie.get("hh-username");
$("#pagehistory li").each(function()
{
var colour = "lightblue";
for (u in users)
{
var captured_user = $(".history-user a bdi", this).html();
if ((users[u].name.includes(captured_user)==true)&&(myusername!=captured_user))
{
if (users[u].hasOwnProperty("groups")==true)
{
if (users[u].groups.includes("sysop")==true)
{
colour = "#ffff4d";
}
else if (users[u].groups.includes("bot")==true)
{
colour = "#66ff66";
}
$(this).css("background-color", colour);
}
else
{
colour = "#ff80ff";
$(this).css("background-color", colour);
}
}
else if ((users[u].name.includes(captured_user)==true)&&(myusername==captured_user))
{
colour = "#ff9933";
$(this).css("background-color", colour);
}
}
});
})
.catch(function(error){console.log(error);});
}
});