Jump to content

User:Joshua Scott/Scripts/pageage.js

From Wikipedia, the free encyclopedia
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.
$(document).ready(pageage_init());
function pageage_init() {
	var site_sub = document.getElementById('siteSub');
	if (!site_sub) return; // Bail out if this is not a normal page view.
  	var apiUrl = "/w/api.php?action=query&format=json&prop=revisions&titles="+wgPageName+"&rvlimit=1&rvprop=timestamp|user&rvdir=newer";
  	$.ajax({
  		url: apiUrl,
    	success: function(data) {
    		var page_id = Object.keys(data.query.pages)[0];
    		if (page_id === "-1") { // New page, e.g.
    			return;
    		} else {
	    		var revision = data.query.pages[page_id].revisions[0];
    			var site_sub = document.getElementById('siteSub');
        		site_sub.innerHTML += "<br/>Created on " + revision.timestamp + " by <a href='/wiki/User:" + revision.user + "'>" + revision.user + "</a> (<a href='/wiki/User_talk:" + revision.user + "'>talk</a> • <a href='/wiki/Special:Contributions/" + revision.user + "'>contribs</a>)";
    		}
    	}
  	});
}