User:Magnus Manske/autodesc.js

/* To add this to ANY Wikipedia, add mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Magnus Manske/autodesc.js&action=raw&ctype=text/javascript"); to your common.js user page, or to your global.js page (for all Wikis): https://meta.wikimedia.org/wiki/Special:MyPage/global.js

To enable it on Wikidata as well, add var autodesc_on_wikidata = true ; BEFORE the mw.loader.load line.

$(document).ready ( function {	if ( mw.config.get('wgNamespaceNumber') != 0 ) return ; // Article namespace only	if ( mw.config.get('wgDBname') == 'wikidatawiki' && typeof autodesc_on_wikidata == 'undefined' ) return ; // Not on Wikidata, duh!	var q = mw.config.get('wgWikibaseItemId') ;	if ( q === null && mw.config.get('wgDBname') == 'wikidatawiki' ) q = mw.config.get('wgTitle') ;	if ( typeof q == 'undefined' || q === '' || q === null ) return ;	$.getJSON ( 'https://tools.wmflabs.org/autodesc/?callback=?', { q:q, lang:mw.config.get('wgUserLanguage'), mode:'short', links:'wikipedia', format:'json' }, function ( d ) { $('#siteSub').show.append ( ': '+d.result+' ['+q+'] ') }) }) ;