User:Writ Keeper/Scripts/orangeBar.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:Writ Keeper/Scripts/orangeBar. |
$(document).ready(function()
{
var HTML_CHAR_MAP = {
'<': '<',
'>': '>',
'&': '&',
'"': '"',
"'": '''
};
function escapeHtml (s) {
return s.replace(/[<>&"']/g, function (ch) {
return HTML_CHAR_MAP[ch];
});
}
//the update of wgUserNewMsgRevId seems to be slow now; it's not updating until *after* the talk page is viewed. So, we exclude the user's talk page, since they won't need it there
if($(".mw-echo-alert").length > 0 && !(mw.config.get('wgNamespaceNumber') == 3 && mw.config.get('wgTitle') == mw.config.get('wgUserName')))
{
var orangeBarDiv = document.createElement("div");
orangeBarDiv.innerHTML = 'You have <a href="/wiki/User_talk:' + encodeURIComponent(mw.config.get("wgUserName")) + '" title="User talk:'+escapeHtml(mw.config.get("wgUserName"))+'">new messages</a> (<a href="/enwiki/w/index.php?title=User_talk:'+encodeURIComponent(mw.config.get("wgUserName"))+'&diff=cur&old=prev">last change</a>).';
orangeBarDiv.className = "usermessage";
if($("#contentSub").length == 0) //No #contentSub in CologneBlue, so handle it specially (possibly adding multiple orange bars but oh well)
{
$(".tagline").after(orangeBarDiv);
}
else //all other skins
{
$("#contentSub").after(orangeBarDiv);
}
//default styling, in case the CSS stylesheet fails to load (keeping the className the same allows for user customization)
$(orangeBarDiv).css({"background-color": "#ffce7b","border": "1px solid #ffa500","color": "black","font-weight": "bold","margin": "2em 0 1em","padding": ".5em 1em","vertical-align": "middle"})
}
});