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.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// vim: ts=4 sw=4 et ai$(function(){varapi;// Copied from https://stackoverflow.com/a/3177838/1757964functiontimeSince(date){varseconds=Math.floor((newDate()-date)/1000);varinterval=Math.floor(seconds/31536000);if(interval>1){returninterval+" years";}interval=Math.floor(seconds/2592000);if(interval>1){returninterval+" months";}interval=Math.floor(seconds/86400);if(interval>1){returninterval+" days";}interval=Math.floor(seconds/3600);if(interval>1){returninterval+" hours";}interval=Math.floor(seconds/60);if(interval>1){returninterval+" minutes";}returnMath.floor(seconds)+" seconds";}functionwikilink(title){return"<a href='"+mw.util.getUrl(title)+"'>"+title+"</a>";}functionnotifToElement(notif){vartimestamp=timeSince(newDate(notif.timestamp.utciso8601))+" ago";varuserLink="<a href='"+mw.util.getUrl("User:"+notif.agent.name)+"' "+((notif.agent.name.length)>20?" style='font-size: 90%'":"")+">"+notif.agent.name+"</a>";vardiffLink=function(text){return"<a href='"+mw.util.getUrl("Special:Diff/"+notif.revid)+"'>"+(text||"this edit")+"</a>";};varnewNotifDiv=$("<div class='notif'>");if(!notif.read)newNotifDiv.append("*");if(notif.type==="mention"&¬if.category==="mention"){newNotifDiv.append("Mentioned "+timestamp+" by "+userLink+" on ").append(wikilink(notif.title.full)).append(" in "+diffLink());}elseif(notif.type==="emailuser"&¬if.category==="emailuser"){newNotifDiv.append("Emailed "+timestamp+" by "+userLink)}elseif(notif.type==="edit-thank"&¬if.category==="edit-thank"){newNotifDiv.append("Thanked "+timestamp+" by "+userLink+" for ").append(diffLink()).append(" to ").append(wikilink(notif.title.full));}elseif(notif.type==="edit-user-talk"&¬if.category==="edit-user-talk"){newNotifDiv.append("Your user talk page changed "+timestamp+" by "+userLink).append(" in "+diffLink());}elseif(notif.type==="mention-success"&¬if.category==="mention-success"){newNotifDiv.append("Successfully mentioned someone "+timestamp+" on ").append(wikilink(notif.title.full)).append(" with "+diffLink());}elseif(notif.type==="mention-summary"&¬if.category==="mention"){newNotifDiv.append("Mentioned "+timestamp+" by "+userLink+" in the summary of "+diffLink());}elseif(notif.type==="login-fail-known"&¬if.category==="login-fail"){newNotifDiv.append("There have been 1 or more unsuccessful attempts to log in to your account since the last time you logged in. If it wasn't you, please make sure your account has a strong password.");}elseif(notif.type==="reverted"&¬if.category==="reverted"){newNotifDiv.append("Your edit to "+wikilink(notif.title.full)+" was "+diffLink("reverted")).append(timestamp+" by "+userLink);}elseif(notif.type==="pagetriage-mark-as-reviewed"&¬if.category==="page-review"){newNotifDiv.append("Your new page "+wikilink(notif.title.full)+" was reviewed by "+userLink+" "+timestamp);}elseif(notif.type==="page-linked"&¬if.category==="article-linked"){newNotifDiv.append("The page "+wikilink(notif.title.full)+" was "+diffLink("linked from")).append(" another page by "+userLink+" "+timestamp);}elseif(notif.type==="dt-subscribed-new-comment"&¬if.category==="dt-subscription"){newNotifDiv.append("A discussion at "+wikilink(notif.title.full)+" was "+diffLink("responded to")+timestamp+" by "+userLink);}elseif(notif.type==="user-rights"&¬if.category==="user-rights"){newNotifDiv.append("Your user rights were updated at "+timestamp+" by "+userLink);}elseif(notif.type==="page-connection"&¬if.category==="wikibase-action"){newNotifDiv.append("The page "+wikilink(notif.title.full)+" was linked to Wikidata by ").append(userLink+" "+timestamp);}elseif(notif.type==="dt-removed-topic"&¬if.category==="dt-subscription-archiving"){newNotifDiv.append("A discussion at "+wikilink(notif.title.full)+" has been "+diffLink("archived or removed")+" by "+userLink+" "+timestamp);}else{newNotifDiv.text(JSON.stringify(notif));}if(!notif.read){newNotifDiv.append($("<span class='simple-notifs-done'>").append("(").append($("<a>").text("done").click(function(){api.postWithToken("csrf",{action:"echomarkread",list:notif.id}).then(function(){refresh();});})).append(")"))}returnnewNotifDiv;}functionrefresh(){api.get({format:"json",action:"query",meta:"notifications",notunreadfirst:"true",// not is the notifications module, not the word "not"notlimit:50,formatversion:2,}).then(function(data){if(!data||!data.query||!data.query.notifications||!data.query.notifications.list){console.error("simple-notifs died ",data);}varnotifsList=data.query.notifications.list;varnumUnread=notifsList.filter(function(x){return!x.read;}).length;$("#pt-simple-notifs").text(numUnread);$("#simple-notifs-panel").empty();notifsList.reverse();if(window.simpleNotifsOnlyUnread){notifsList=notifsList.filter(function(notif){return!notif.read;});}notifsList.map(notifToElement).forEach(function(e){$("#simple-notifs-panel").append(e);});});}$.when($.ready,mw.loader.using(["mediawiki.api","mediawiki.util"])).then(function(results){api=newmw.Api("User:Enterprisey/simple-notifs.js");$("<li>").insertAfter("#pt-userpage").append("?").attr("id","pt-simple-notifs").on("click",function(){$("#simple-notifs-panel").toggle();})varptOffset=$("#pt-simple-notifs").offset();varpanel=$("<div>").attr("id","simple-notifs-panel").css("top",ptOffset.top+30+"px").css("left",ptOffset.left+"px").toggle().appendTo("body");refresh();mw.loader.addStyleTag("ul li#pt-simple-notifs { cursor: pointer; background-color: gray; margin-top: .3em; padding: .3em; padding-top: .3em; background-color: #ccc }"+" #simple-notifs-panel { position: fixed; background-color: white; width: 30em; height: 50%; overflow-y: scroll; border: thin solid black; border-radius: 2px; padding: 0.5em; font-size: 0.875em; z-index: 500; }"+"#simple-notifs-panel .notif { margin-bottom: 0.3em; }"+".simple-notifs-done { font-size: 95%; margin-left: 0.35em; }");});});