User:Jura1/js.js

From Wikidata
Jump to navigation Jump to search

Note: After publishing, 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: Press Ctrl-F5.
$( function() {
  if ( mw.config.get('wgNamespaceNumber') == 0 ) {
    mw.loader.using( 'oojs-ui-core' ).then( function () {
      $( '.wikibase-statementgroupview' ).each( function() {
        var pid = $( this ).attr( 'id' );
        $('.wikibase-statementgroupview#' + pid ).find('.wikibase-statementview-mainsnak-container').find('.wikibase-snakview-value').each( function() {
          var qid = $( this ).find( 'a' ).attr( 'title' );
          if ( qid ) {
            var url = 'https://query.wikidata.org/#SELECT%20%3Fitem%20%3FitemLabel%20%3FitemDescription%0A%7B%0A%09%3Fitem%20wdt%3A' + pid + '%20wd%3A' + qid + '%20.%20%0A%09SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22'+ mw.config.get( 'wgUserLanguage' ) + '%22%20%7D%0A%7D';
            var searchIcon = new OO.ui.IconWidget( {
              icon: 'search',
              iconTitle: 'More',
              $element: $( '<a/>', {
                href: url,
                target: '_blank',
                style: 'background-size: 20px 20px',
              } ),
            } );
            $( this ).find('a').after( searchIcon.$element  );
          }
        });
      });
    });
  }
});
/* Add a link in the Tools section to display depictions of items on Commons */

( function ( mw, $ ) {
	if ( !mw.config.exists( 'wbEntityId' ) ) {
	    return;
	}

    var entityId = mw.config.get( 'wbEntityId' );

    mw.util.addPortletLink(
        'p-tb',
        '//tools.wmflabs.org/depicts/#/' + entityId,
        'Commons Depicts',
        't-depicts',
        'Display images on Wikimedia Commons that depict this item'
    );
}( mediaWiki, jQuery ) );