User:Edgars2007/test.js
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)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
var langs = ['en','de','nl','fr','it','es','pl','pt','sv','nl','ro','no','da','sv'];
if (mw.config.get('wgNamespaceNumber') == 0){
var pagetitle = mw.config.get('wgTitle');
var label;
var api = new mw.Api( {
ajax: {
headers: { 'Api-User-Agent': 'd:User:Edgars2007/test.js' }
} } );
api.get( {
action: 'wbgetentities',
ids: pagetitle,
props: 'labels'
} )
.done( function ( data ) {
var isjson = data.entities[pagetitle].labels.length;
if ( !isjson ) {
var i;
for (i = 0; i < langs.length; i++) {
if (data.entities[pagetitle].labels[langs[i]] != undefined) {
label = data.entities[pagetitle].labels[langs[i]].value;
console.log(label);
break;
}
}
if (label != undefined) {
console.log('no label2');
//console.log(name);
label = label.replace( /\s\(.*\)/, '' );
//console.log(name);
$( function() {
mw.util.addPortletLink(
'p-tb',
'http://tools.wmflabs.org/mix-n-match/?mode=search&query=' + encodeURIComponent( label ) + '&exclude=&include=',
'mix-n-match'
);
} );
} else {
console.log('no label123');
}
}
}).fail(function (e) {
console.log('Failed');
});
}