MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
No edit summary |
No edit summary |
||
Line 50: | Line 50: | ||
var countryInfo = data.countries; |
var countryInfo = data.countries; |
||
var showResults = data.results[show]; |
var showResults = data.results[show]; |
||
⚫ | |||
showResults.forEach(function (resultData) { |
showResults.forEach(function (resultData) { |
||
var country = resultData.country; |
var country = resultData.country; |
||
Line 76: | Line 75: | ||
resultsTable += '|}'; |
resultsTable += '|}'; |
||
⚫ | |||
console.log(resultsTable); |
|||
}); |
}); |
||
⚫ | |||
⚫ | |||
$(this).html(resultsTable); |
$(this).html(resultsTable); |
Revision as of 16:33, 30 December 2019
/* Any JavaScript here will be loaded for all users on every page load. */
function createArtistString(link, artists, featured) {
featured = (featured === undefined) ? '' : featured;
var linkStart = (link === true) ? '[[' : '';
var linkEnd = (link === true) ? ']]' : '';
var artistStr = '';
if (artists.constructor === Array) {
if (artists.length == 1) {
artistStr += linkStart+artists[0]+linkEnd;
} else if (artists.length == 2) {
artistStr += linkStart+artists.join(linkEnd+' & '+linkStart)+linkEnd;
} else {
var last_artist = artists.pop();
artistStr += linkStart+artists.join(linkEnd+', '+linkStart)+linkEnd+' & '+linkStart+last_artist+linkEnd;
}
} else {
artistStr += linkStart+artists+linkEnd;
}
if (featured.length > 0) {
if (artists.constructor === Array) {
artistStr += ' feat. '+createArtistString(link, featured);
} else {
artistStr += ' feat. '+linkStart+featured+linkEnd;
}
}
return artistStr;
}
/* CONTEST RESULTS */
$(".contest-results").each(function() {
var classList = $(this).attr('class').split(/\s+/);
var edition = classList[1].replace('edition-', '');
var editionInt = parseInt(edition);
var show = classList[2].replace('show-', '').toLowerCase();
var resultsTable = '';
$.getJSON('https://fantasiacontest.miraheze.org/wiki/EditionData:'+edition+'?action=raw', function(data) {
resultsTable = '{| class="wikitable sortable" width="100%"'+"\n";
resultsTable += '! width="8%"|Draw'+"\n"+'! width="25%"|Country'+"\n"+'! width="25%"|Artist'+"\n"+'! width="25%"|Song'+"\n"+'! width="8%"|Place'+"\n"+'! width="8%"|Points'+"\n";
var draw = 1;
var countryInfo = data.countries;
var showResults = data.results[show];
showResults.forEach(function (resultData) {
var country = resultData.country;
var place = resultData.place;
var points = resultData.points;
var artist = countryInfo[country].artist;
var featured = (countryInfo[country].featured === undefined) ? [] : countryInfo[country].featured;
var song = countryInfo[country].song;
var qualified = false;
if ((show === 'sf1' || show === 'sf2' || show === 'sf3') && (editionInt === 1 && place <= 12) || (editionInt === 2 && place <= 10) || (editionInt >= 3 && place <= 7) || (editionInt === 11 && place === 8)) {
resultsTable += '|-'+"\n";
} else {
resultsTable += '|- style="background:navajowhite;font-weight:bold;"'+"\n";
}
resultsTable += '| align="center"| '+String(draw).padStart(2, '0')+"\n";
resultsTable += '| {{fc|'+country+'}}'+"\n";
resultsTable += '| '+createArtistString(true, artist, featured)+"\n";
resultsTable += '| "'+song+'"'+"\n";
resultsTable += '| align="center"| '+String(place)+"\n";
resultsTable += '| align="center"| '+String(points)+"\n";
});
resultsTable += '|}';
});
console.log(resultsTable);
$(this).html(resultsTable);
});