User:Writ Keeper/Scripts/liveWatchlist.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.
watchlistLastRetrieved;
apiProps = {"action":"query","list":"watchlist","wlprop":"ids|title|user|comment|timestamp|sizes","wlallrev":"true"}
watchlistUpdateClass= "watchlistUpdate";

function refreshWatchlist()
{
	
}
function populateWatchlist()
{
	if($("#mw-liveWatchlistUL").length > 0)
	{
		$.post("\w\api.php",apiProps, function(response)
		{
			
			watchlistLastRetrieved = new Date(Date.now()).toISOString();
		});
	}
}
function renderWatchlistEntry(var watchListJSON)
{
	var resultString = "";
	var editTime = new Date(watchlistJSON.timestamp);
	var editDelta = watchlistJSON.newlen - watchlistJSON.oldlen;
	if(watchlistJSON.type === "edit")
	{
		resultString = '<li class="mw-changeslist-liu ">(<a href="/w/index.php?title=' + watchlistJSON.title + '&curid=' + watchlistJSON.pageid + '&diff=' + watchlistJSON.revid + '&oldid=' + watchlistJSON.old_revid + '" class="mw-changeslist-diff nonimage userlink" title="' + watchlistJSON.title + '">diff</a> | <a href="/w/index.php?title=' + watchlistJSON.title + '&curid=' + watchlistJSON.pageid + '&action=history" class="mw-changeslist-history nonimage userlink" title="' + watchlistJSON.title + '">hist</a>) <span class="mw-changeslist-separator">. .</span><a href="#" id="' + watchlistJSON.revid + '" class=" nonimage" title="#"><b><span style="color:black;"> [</span><span style="color:#339900;">inspect diff</span><span style="color:black;">] </span></b></a><span class="mw-title"><a href="/wiki/' + watchlistJSON.title + '" class="mw-changeslist-title nonimage userlink" title="' + watchlistJSON.title + '">' + watchlistJSON.title + '; </a></span>‎; <span class="mw-changeslist-date">' + editTime.getHours() + ':' + editTime.getMinutes() + '</span><span class="mw-changeslist-separator">. .</span><span dir="ltr" class="mw-plusminus-' + (editDelta >= 0 ? 'pos' : 'neg') + '" title="' + watchlistJSON.newLen + '" bytes after change">(' + (editDelta >= 0 ? '+' : '' + editDelta) + ')</span>‎  <span class="mw-changeslist-separator">. .</span> ‎<a href="/wiki/User:' + watchlistJSON.user + '" class="mw-redirect mw-userlink nonimage userlink redirect" title="' + watchlistJSON.title + '"><bdi>' + watchlistJSON.user + '</bdi></a><span class="mw-usertoollinks">(<a href="/wiki/' + watchlistJSON.title + '" class="mw-usertoollinks-talk nonimage userlink" title="' + watchlistJSON.title + '">talk</a> | <a href="/wiki/Special:Contributions/' + watchlistJSON.user + '" class="mw-usertoollinks-contribs nonimage userlink" title="Special:Contributions/' + watchlistJSON.user + '">contribs</a> |<a href="/wiki/Special:Block/' + watchlistJSON.user + '" class="mw-usertoollinks-block nonimage" title="Special:Block/' + watchlistJSON.user + '">block</a>)</span>‎ <span class="comment">(' + watchlistJSON.comment + ')</span></li>';
	}
	else if (watchlistJSON.type === "new")
	{
		resultString = '<li class="mw-changeslist-liu mw-changeslist-src-mw-new">(diff&nbsp;| <a href="/w/index.php?title=' + watchlistJSON.title + '&curid=' + watchlistJSON.pageid + '&action=history" class="mw-changeslist-history nonimage" title="' + watchlistJSON.title + '">hist</a>) <span class="mw-changeslist-separator">. .</span><abbr class="newpage" title="This edit created a new page">N</abbr><span class="mw-title"><a href="/wiki/' + watchlistJSON.title + '" class="mw-changeslist-title nonimage" title="' + watchlistJSON.title + '">' + watchlistJSON.title + '; </a></span>‎; <span class="mw-changeslist-date">' + editTime.getHours() + ':' + editTime.getMinutes() + '</span><span class="mw-changeslist-separator">. .</span><span dir="ltr" class="mw-plusminus-pos" title="' + watchlistJSON.newlen + ' bytes after change">(+' + watchlistJSON.newlen + ')</span>‎  <span class="mw-changeslist-separator">. .</span> ‎<a href="/wiki/User:' + watchlistJSON.user + '" class="mw-userlink nonimage userlink protection-edit-sysop-indef protection-edit-sysop protection-move-sysop-indef protection-move-sysop" title="User:' + watchlistJSON.user + '"><bdi>' + watchlistJSON.user + '</bdi></a><span class="mw-usertoollinks">(<a href="/wiki/User_talk:' + watchlistJSON.user + '" class="mw-usertoollinks-talk nonimage userlink" title="User talk:' + watchlistJSON.user + '">talk</a>&nbsp;| <a href="/wiki/Special:Contributions/' + watchlistJSON.user + '" class="mw-usertoollinks-contribs nonimage userlink" title="Special:Contributions/' + watchlistJSON.user + '">contribs</a>&nbsp;| <a href="/wiki/Special:Block/' + watchlistJSON.user + '" class="mw-usertoollinks-block nonimage" title="Special:Block/' + watchlistJSON.user + '">block</a>)</span>‎ <span class="comment">(' + watchlistJSON.comment + ')</span></li>';
	}
	else if (watchlistJSON.type === "log")
	{
		resultString = '<li class="mw-changeslist-liu mw-changeslist-src-mw-log">(log); <span class="mw-changeslist-date">' + editTime.getHours() + ':' + editTime.getMinutes() + '</span><span class="mw-changeslist-separator">. .</span> <a href="/wiki/User:' + watchlistJSON.user + '" class="mw-userlink nonimage userlink protection-edit-sysop-indef protection-edit-sysop protection-move-sysop-indef protection-move-sysop" title="User:' + watchlistJSON.user + '"><bdi>' + watchlistJSON.user + '</bdi></a><span class="mw-usertoollinks">(<a href="/wiki/User_talk:' + watchlistJSON.user + '" class="mw-usertoollinks-talk nonimage userlink" title="User talk:' + watchlistJSON.user + '">talk</a>&nbsp;| <a href="/wiki/Special:Contributions/' + watchlistJSON.user + '" class="mw-usertoollinks-contribs nonimage userlink" title="Special:Contributions/' + watchlistJSON.user + '">contribs</a>&nbsp;| <a href="/wiki/Special:Block/' + watchlistJSON.user + '" class="mw-usertoollinks-block nonimage" title="Special:Block/' + watchlistJSON.user + '">block</a>)</span> did something to <a href="/wiki/' + watchlistJSON.title + '" class="mw-userlink nonimage userlink" ><bdi>' + watchlistJSON.title + '</bdi></a>with the comment: "‎<span class="comment">' + watchlistJSON.comment + '</span>"</li>';
	}
	return resultString;
}