Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
// This script reimpliments the last edit banner used on mobile// See [[User:Opencooper/lastEdit]]// TODO: standardize on either single or double quotesfunctionrequestRevision(){// If we're not reading an article, do nothingif(!(mw.config.get('wgAction')==='view'&&mw.config.get('wgIsArticle')&&mw.config.get("wgPageName")!=="Main_Page")){return;}// API docs: https://www.mediawiki.org/wiki/API:Revisions$.ajax({url:"https://commons.wikimedia.org/w/api.php?action=query&prop=revisions&format=json&titles="+mw.config.get('wgPageName')+"&rvprop=timestamp%7Cuser%7Ccomment%7Ctags%7Cids",success:displayEdit});}// Display the last edit info to the right of the site subheadfunctiondisplayEdit(response){varpageId=mw.config.get('wgArticleId');try{varpageInfo=response.query.pages[pageId].revisions[0];// Relies on moment.js. See script history for an inline implementationmw.loader.using(['moment']).then(function(){displayEditWithMoment(pageInfo);})}catch(e){return;}}functiondisplayEditWithMoment(pageInfo){varrelativeTimestamp=moment(pageInfo.timestamp).fromNow();vareditComment=pageInfo.comment;if(!editComment){editComment="[No edit summary]";}editComment=editComment.replace(/'/g,"'");// HTML encode quotesvarlastEdit="<a href='/wiki/Special:Diff/"+pageInfo.revid+"' title='"+editComment+"'> Last edited "+relativeTimestamp+"</a>";varlastEditor="<a href='/wiki/Special:Contributions/"+pageInfo.user+"'>"+pageInfo.user+"</a>";// Can be filtered if neededvarpageTags="";if(pageInfo.tags.length>0){pageTags="<span class='mw-tag-markers'> ("+pageInfo.tags+")</span>";}varnotice=lastEdit+" by "+lastEditor+pageTags;// [[MediaWiki:Gadget-metadata.js]] replaces the siteSub element so wait for it// to run first// Check if script is enabled and if it hasn't ran alreadyif($("script").text().search("ext.gadget.metadata")!=-1&&!$(".assess-article-rating").length){vartarget=document.querySelector('#siteSub');varobserver=newMutationObserver(function(mutations){// IE 11+$('#siteSub').append("<div style='float: right;'>"+notice+"</div>");observer.disconnect();});observer.observe(target,{childList:true});}else{$('#siteSub').append("<div style='float: right;'>"+notice+"</div>");}// Unfortunately [[Template:Coords]] absolutely positions itself so we have// to move it down so we don't get obscuredvarsheet=window.document.styleSheets[0];sheet.insertRule('#coordinates { top: 2em !important; }',sheet.cssRules.length);}$(requestRevision);