Jump to content

User:Firefly/checkuseragenthelper.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.
$( function($) {
	if (mw.config.get("wgPageName") == "Special:CheckUser")
	{
	    $(".mw-checkuser-agent").each(function(){
	        var el = $(this);
	        var ua = el.text();
	        $.ajax({
	            type: "GET",
	            url: "https://www.whatsmyua.info/api/v1/ua?ua="+encodeURIComponent(ua),
	            success: function(d) { 
	                var tooltip = "";
	                try{
	                    tooltip = d[3]["device"]["description"];
	                }
	                catch (e){
	                    console.log("Unable to get friendly name from API for ( " + ua + " ), falling back to components.");
	                }

	                try{
	                    tooltip += d[0]['ua']['family'];
	                    tooltip += " ";
	                    tooltip += d[0]['ua']['major'];
	                    tooltip += " ";
	                    tooltip += d[0]['ua']['minor'];
	                    tooltip += " ";
	                    tooltip += d[0]['ua']['patch'];
	                    tooltip += " ";
	                    tooltip += d[0]['os']['family'];
	                    tooltip += " ";
	                    tooltip += d[0]['os']['major'];
	                    tooltip += " ";
	                    tooltip += d[0]['os']['minor'];
	                    tooltip += " ";
	                    tooltip += d[0]['os']['patch'];
	                } catch (e)
	                {
	                    console.log("Unable to get anything from API for ( " +ua+" ).");
	                }
	                tooltip = el.attr("title", tooltip);
	            }
	        });
	    });
	}
});