Jump to content

User:Edgars2007/script.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.
var maincats, tennis, cycling,football;
var WDid = 'Q123';
var athl_name = mw.config.get( 'wgTitle' );

function generateLink() {
var arr = [];
$('.myclass').each(function() {
	var fieldValue = $(this).val();
	if(fieldValue) {
		var fieldName = $(this).attr('name');
		arr.push( WDid + '\t' + fieldName + '\t"' + fieldValue + '"' );
	}
});

console.log('massiivs no inputiem ', arr);
var stringForLink = arr.join("\n");
var finalURL = "<a href='https://tools.wmflabs.org/wikidata-todo/quick_statements.php?list=" + encodeURIComponent(stringForLink) + "'>Atvērt</a>"
//console.log(finalURL);
$('p#foobarlorem').html(finalURL);
}

tennis=[
    ["ATP","atpworldtour.com","536"],
    ["WTA","wtatennis.com","597"],
    ["ITF","itftennis.com","599"]
];

cycling = [
	["Cycling Archives","cyclingarchives.com","1409"],
	["Cycling Quotient (men)","cqranking.com","1541"],
	["Cycling Quotient (women)","cqranking.com","2709"],
	["ProCyclingStats","procyclingstats.com","1663"]
];

football = [
	["FIFA","fifa.com","1469"],
	["UEFA","uefa.com","2276"],
	["Soccerbase","soccerbase.com","2193"],
	["Soccerway","soccerway.com","2369"],
	["NFT","national-football-teams.com","2574"],
	["Transfermarkt","transfermarkt.com","2446"]
];

maincats = [
	["Athletics","iaaf.org","1146"],
	["Boxing","boxrec.com","1967"],
	["Rowing","worldrowing.com","2091"],
	["Fencing","fie.org","2423"],
	["Table tennis","","1364"],
	["Swimming","swimrankings.net","2640"],
	["Gymnastics","database.fig-gymnastics.com","2696"],
	["Modern pentathlon","uipmworld.org","2726"],
	["Wrestling","iat.uni-leipzig.de","2727"],
	["Triatlon","iat.uni-leipzig.de","2778"],
	["Weightlifting","iat.uni-leipzig.de","2779"],
	["Diving","iat.uni-leipzig.de","2780"],
	["Badminton","bwfcontent.tournamentsoftware.com","2729"],
	["ISSF","issf-sports.org","2730"],
	["Sailing","sailing.org","2804"],
	["Judo","judoinside.com","2767"],
	["Beach Volleyball","bvbinfo.com","2800"],
	["FIVB","fivb.org","2801"]
];
/* =========================================== Tennis =========================================== */
var lenTen = tennis.length;

var tennisT = "<b>Tennis</b><br /><table><tr><th>prop</th><th>Web</th><th>Input</th></tr>";

for (var i = 0; i < lenTen; i++) {
  tenniswebpage = tennis[i][0];
  tennisurl = tennis[i][1];
  tennisprop = tennis[i][2];
  
  tennisT += "<tr><td>P"+ tennisprop +"</td><td><a href='https://www.google.com/search?q=" + encodeURIComponent(athl_name) + " site:" + encodeURIComponent(tennisurl) + "'>" + tenniswebpage + " - "+ tennisprop +"</a></td><td><input class='myclass' type='text' name='P" + tennisprop + "' value=''></td></tr>";

}

tennisT += '</table>';
/* =========================================== Cycling =========================================== */
var lenCyc = cycling.length;

var cyclingT = "<b>Cycling</b><br /><table><tr><th>prop</th><th>Web</th><th>Input</th></tr>";

for (var i = 0; i < lenCyc; i++) {
  cyclingwebpage = cycling[i][0];
  cyclingurl = cycling[i][1];
  cyclingprop = cycling[i][2];
  
  cyclingT += "<tr><td>P"+ cyclingprop +"</td><td><a href='https://www.google.com/search?q=" + encodeURIComponent(athl_name) + " site:" + encodeURIComponent(cyclingurl) + "'>" + cyclingwebpage + " - "+ cyclingprop +"</a></td><td><input class='myclass' type='text' name='P" + cyclingprop + "' value=''></td></tr>";

}

cyclingT += '</table>';
/* =========================================== Football =========================================== */
var lenFoot = football.length;

var footballT = "<b>Football</b><br /><table><tr><th>prop</th><th>Web</th><th>Input</th></tr>";

for (var i = 0; i < lenFoot; i++) {
  footballwebpage = football[i][0];
  footballurl = football[i][1];
  footballprop = football[i][2];
  
  footballT += "<tr><td>P"+ footballprop +"</td><td><a href='https://www.google.com/search?q=" + encodeURIComponent(athl_name) + " site:" + encodeURIComponent(footballurl) + "'>" + footballwebpage + " - "+ footballprop +"</a></td><td><input class='myclass' type='text' name='P" + footballprop + "' value=''></td></tr>";

}

footballT += '</table>';
/* =========================================== Main =========================================== */
var lenMain = maincats.length;

var maincatsT = "<b>Main</b><br /><table><tr><th>prop</th><th>Web</th><th>Input</th></tr>";

for (var i = 0; i < lenMain; i++) {
  maincatswebpage = maincats[i][0];
  maincatsurl = maincats[i][1];
  maincatsprop = maincats[i][2];
  
  maincatsT += "<tr><td>P"+ maincatsprop +"</td><td><a href='https://www.google.com/search?q=" + encodeURIComponent(athl_name) + " site:" + encodeURIComponent(maincatsurl) + "'>" + maincatswebpage + " - "+ maincatsprop +"</a></td><td><input class='myclass' type='text' name='P" + maincatsprop + "' value=''></td></tr>";

}

maincatsT += '</table>';




var text2 = '<br><button onclick="generateLink()">Ģenerēt QuickStatements</button><br><br><p id="foobarlorem"></p>';

$( function( $ ){
  function addAliasesFromRedirects(){
   mw.util.addCSS(".YRRedirectsToAdd{float: left; white-space: nowrap; border: 1px soslid #AAA; border-radius: 3px; cursor: pointer; background-color: #FFF; padding: 2px 5px; margin: 2px; }.YRRedirectsToAdd:hover{ background-color: #F0F6FF; box-shadow: 0 0 5px #CCC inset; }.YRRedirectsToAdd.selected{ border-color:#0CC; background-color: #DFF; }")

   mw.loader.using( ['jquery.ui'], function() {
     var $dialog = $("<div>").text( 'df' ).dialog({
       title: 'Add external IDs to athlete',
       autoOpen: true,
       width: 450,
	//height: 500,
     });
         $dialog
            //.text( 'messages.dialogintro' )
            //.append($("<hr>"))
            .append(tennisT)
            .append(cyclingT)
            .append(footballT)
            .append(maincatsT)
            .append(text2)

   })
  }
  $( mw.util.addPortletLink( 'p-cactions', '#', 'Rio IDs', null, 'messages.FRTooltip' ) ).on( "click", addAliasesFromRedirects );
})