MediaWiki:Common.js: Difference between revisions

From Fantasipedia
Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 31: Line 31:
return artistStr;
return artistStr;
}
}

$(".semi-place").each(function() {
var classList = $(this).attr('class').split(/\s+/);
var place = parseInt($(this).text());
var country = classList[1].split("-")[0]
var edition = parseInt(classList[1].split("-")[1])
if ((edition === 1 && place <= 12) || (edition === 2 && place <= 10) || (edition >= 3 && place <= 7) || (((edition === 11 && country === "Lakadamia") || edition >= 29) && place === 8)) {
$("."+classList[1]+"-semi-style").css("background-color", "navajowhite").css("font-weight", "bold");
}
});
$(".final-place").each(function() {
var classList = $(this).attr('class').split(/\s+/);
var place = parseInt($(this).text());
var country = classList[1].split("-")[0]
var edition = parseInt(classList[1].split("-")[1])
if (place === 1) {
$("."+classList[1]+"-final-style").css("background-color", "gold").css("font-weight", "bold");
}
});
$(".pre-ed-song").each(function() {
if ($(this).text().length > 0) {
var title = $(this).text();
$(this).text('"'+title+'"');
}
});

/* COUNTRY RESULT TABLES */

const LAST25 = [1, 2];
const LAST27 = [13, 16];

$(".result-table-row").children().each(function() {
var classList = $(this).attr('class').split(/\s+/);
var editionNumber = parseInt(classList[2].replace("edition-number-", ""));
if ((classList[0] === "final-result-1" || classList[0] === "semi-result-1") && classList[1] !== "semi-result-") {
$(this).css("background-color", "gold");
} else if ((classList[0] === "final-result-2" || classList[0] === "semi-result-2") && classList[1] !== "semi-result-") {
$(this).css("background-color", "silver");
} else if ((classList[0] === "final-result-3" || classList[0] === "semi-result-3") && classList[1] !== "semi-result-") {
$(this).css("background-color", "#cc9966");
} else if ((classList[0] === "final-result-25" && LAST25.includes(editionNumber)) ||
(classList[0] === "final-result-27" && LAST27.includes(editionNumber)) ||
(classList[0] === "final-result-26" && !LAST25.includes(editionNumber) && !LAST27.includes(editionNumber) && editionNumber < 29) ||
(classList[0] === "final-result-30" && !LAST25.includes(editionNumber) && !LAST27.includes(editionNumber) && editionNumber >= 29)) {
$(this).css("background-color", "#FE8080");
} else if (classList[0] === "final-result-" || classList[1] === "final-result-") {
$(this).css("background-color", "#FFCDBD");
} else if (classList[0] === "semi-result-") {
$(this).css("background-color", "#99FF99");
}

if (classList[0] === "final-result-" && classList[1] === "final-place-points") {
$(this).html("<small style='color:grey'>NQ</small>");
$(this).attr("data-sort-value", "9999");
} else if (classList[0] === "semi-result-" && classList[3] === "semi-place-points") {
$(this).html("<small style='color:darkgreen'>AQ</small>");
$(this).attr("data-sort-value", "9999");
}
});


/* CONTEST RESULTS
/* CONTEST RESULTS

Latest revision as of 12:42, 12 September 2022

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

$(".semi-place").each(function() {
	var classList = $(this).attr('class').split(/\s+/);
	var place = parseInt($(this).text());
	
	var country = classList[1].split("-")[0]
	var edition = parseInt(classList[1].split("-")[1])
	
	if ((edition === 1 && place <= 12) || (edition === 2 && place <= 10) || (edition >= 3 && place <= 7) || (((edition === 11 && country === "Lakadamia") || edition >= 29) && place === 8)) {
		$("."+classList[1]+"-semi-style").css("background-color", "navajowhite").css("font-weight", "bold");
	}
});
$(".final-place").each(function() {
	var classList = $(this).attr('class').split(/\s+/);
	var place = parseInt($(this).text());
	
	var country = classList[1].split("-")[0]
	var edition = parseInt(classList[1].split("-")[1])
	
	if (place === 1) {
		$("."+classList[1]+"-final-style").css("background-color", "gold").css("font-weight", "bold");
	}
});
$(".pre-ed-song").each(function() {
	if ($(this).text().length > 0) {
		var title = $(this).text();
		$(this).text('"'+title+'"');
	}	
});

/* COUNTRY RESULT TABLES */

const LAST25 = [1, 2];
const LAST27 = [13, 16];

$(".result-table-row").children().each(function() {
	var classList = $(this).attr('class').split(/\s+/);
    var editionNumber = parseInt(classList[2].replace("edition-number-", ""));
	
	if ((classList[0] === "final-result-1" || classList[0] === "semi-result-1") && classList[1] !== "semi-result-") {
		$(this).css("background-color", "gold");
	} else if ((classList[0] === "final-result-2" || classList[0] === "semi-result-2") && classList[1] !== "semi-result-") {
		$(this).css("background-color", "silver");
	} else if ((classList[0] === "final-result-3" || classList[0] === "semi-result-3") && classList[1] !== "semi-result-") {
		$(this).css("background-color", "#cc9966");
	} else if ((classList[0] === "final-result-25" && LAST25.includes(editionNumber)) ||
               (classList[0] === "final-result-27" && LAST27.includes(editionNumber)) ||
               (classList[0] === "final-result-26" && !LAST25.includes(editionNumber) && !LAST27.includes(editionNumber) && editionNumber < 29) ||
               (classList[0] === "final-result-30" && !LAST25.includes(editionNumber) && !LAST27.includes(editionNumber) && editionNumber >= 29)) {
		$(this).css("background-color", "#FE8080");
    } else if (classList[0] === "final-result-" || classList[1] === "final-result-") {
		$(this).css("background-color", "#FFCDBD");
	} else if (classList[0] === "semi-result-") {
		$(this).css("background-color", "#99FF99");
	}

    if (classList[0] === "final-result-" && classList[1] === "final-place-points") {
        $(this).html("<small style='color:grey'>NQ</small>");
        $(this).attr("data-sort-value", "9999");
    } else if (classList[0] === "semi-result-" && classList[3] === "semi-place-points") {
        $(this).html("<small style='color:darkgreen'>AQ</small>");
        $(this).attr("data-sort-value", "9999");
    }
});

/* CONTEST RESULTS

mw.loader.using( 'mw.Api' ).then(function () {
	var api = new mw.Api();
	
	$(".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 += '|- style="background:navajowhite;font-weight:bold;"'+"\n";
				} else if (show === 'final' && place === 1) {
					resultsTable += '|- style="background:gold;font-weight:bold;"'+"\n";
				} else {
					resultsTable += '|-'+"\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";
				
				draw++;
			});
	    	
	    	resultsTable += '|}';
	    	
	    	var params = {action: 'parse', text: resultsTable}
	    	
	    	api.get(params).done(function (data) {
	    		$("."+classList.join(".")).html(data.parse.text['*']);
			});
	    });
	});
});
*/