MediaWiki:Common.js

/* 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; }

var pageHTML = $('.mw-parser-output').html;

/* CONTEST RESULTS */ var resultsRegex = //gm; let m;

while ((m = resultsRegex.exec(pageHTML)) !== null) { if (m.index === resultsRegex.lastIndex) { resultsRegex.lastIndex++; }   var wikiString = m[0]; var edition = m[1]; var editionInt = parseInt(edition); var show = m[2].toLowerCase; $.getJSON('https://fantasiacontest.miraheze.org/wiki/EditionData:'+edition+'?action=raw', function(data) {   	var resultsTable = '{| class="wikitable sortable" width="100%"'+"\n";    	resultsTable += '! width="8%"|Draw ! width="25%"|Country ! width="25%"|Artist ! width="25%"|Song ! width="8%"|Place ! width="8%"|Points'+"\n";		var draw = 1;		var countryInfo = data.countries;		var showResults = data.results[show];		console.log(showResults);		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 += '| '+"\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);    }); }