MediaWiki

Common.js

Revision as of 07:15, 6 April 2018 by 0x010C (talk | contribs)

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
// Replace Wikidata IDs with their [label, description]
$( '.wb-external-id' ).each( function() {
    if ( $( this ).attr( 'href' ).lastIndexOf( 'https://www.wikidata.org', 0 ) === 0 ) {
        var wikidataApi = new mw.ForeignApi( 'https://www.wikidata.org/w/api.php', {
                anonymous: true,
                parameters: { 'origin': '*' },
                ajax: { timeout: 10000 }
            } ),
            lang = mw.config.get( 'wgUserLanguage' ),
            node = $( this );
        wikidataApi.get( {
            'action': 'wbgetentities',
            'format': 'json',
            'ids': node.text(),
            'props': 'labels|descriptions',
            'languages': lang,
            'languagefallback': 1,
            'origin': '*'
        } ).then( function( data ) {
            var entity = data.entities[ node.text() ],
                label = entity.labels[ lang ].value,
                description = entity.descriptions[ lang ].value;
            
            node.html( label + ' <i>(' + node.text() + ')</i><br><small>' + description + '</small>' )
        } );
    }
} );