MediaWiki:Common.js: Difference between revisions

From Fantasipedia
Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
 
(22 intermediate revisions by the same user not shown)
Line 32: Line 32:
}
}


$(".semi-place").each(function() {
var pageHTML = $('.mw-parser-output').html();
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+'"');
}
});


/* CONTEST RESULTS */
/* COUNTRY RESULT TABLES */
var resultsRegex = /{{#ContestResults:([1-9](?:[0-9]{1,})?)\|(SF[1-3]|GF)}}/gm;
let m;


const LAST25 = [1, 2];
while ((m = resultsRegex.exec(pageHTML)) !== null) {
const LAST27 = [13, 16];
if (m.index === resultsRegex.lastIndex) {

resultsRegex.lastIndex++;
$(".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");
}
}
});

var wikiString = m[0];
/* CONTEST RESULTS
var edition = m[1];

var editionInt = parseInt(edition);
mw.loader.using( 'mw.Api' ).then(function () {
var show = m[2].toLowerCase();
var api = new mw.Api();
$.getJSON('https://fantasiacontest.miraheze.org/wiki/EditionData:'+edition+'?action=raw', function(data) {
$(".contest-results").each(function() {
var resultsTable = '{| class="wikitable sortable" width="100%"'+"\n";
var classList = $(this).attr('class').split(/\s+/);
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 edition = classList[1].replace('edition-', '');
var draw = 1;
var countryInfo = data.countries;
var editionInt = parseInt(edition);
var show = classList[2].replace('show-', '').toLowerCase();
var showResults = data.results[show];
console.log(showResults);
var resultsTable = '';
showResults.forEach(function (resultData) {
var country = resultData.country;
$.getJSON('https://fantasiacontest.miraheze.org/wiki/EditionData:'+edition+'?action=raw', function(data) {
var place = resultData.place;
resultsTable = '{| class="wikitable sortable" width="100%"'+"\n";
var points = resultData.points;
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 artist = countryInfo[country].artist;
var draw = 1;
var featured = (countryInfo[country].featured === undefined) ? [] : countryInfo[country].featured;
var countryInfo = data.countries;
var song = countryInfo[country].song;
var showResults = data.results[show];
showResults.forEach(function (resultData) {
var qualified = false;
var country = resultData.country;
var place = resultData.place;
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";
var points = resultData.points;
} else {
var artist = countryInfo[country].artist;
resultsTable += '|- style="background:navajowhite;font-weight:bold;"'+"\n";
var featured = (countryInfo[country].featured === undefined) ? [] : countryInfo[country].featured;
}
var song = countryInfo[country].song;
resultsTable += '| align="center"| '+String(draw).padStart(2, '0')+"\n";
var qualified = false;
resultsTable += '| {{fc|'+country+'}}'+"\n";
if ((show === 'sf1' || show === 'sf2' || show === 'sf3') && (editionInt === 1 && place <= 12) || (editionInt === 2 && place <= 10) || (editionInt >= 3 && place <= 7) || (editionInt === 11 && place === 8)) {
resultsTable += '| '+createArtistString(true, artist, featured)+"\n";
resultsTable += '| "'+song+'"'+"\n";
resultsTable += '|- style="background:navajowhite;font-weight:bold;"'+"\n";
} else if (show === 'final' && place === 1) {
resultsTable += '| align="center"| '+String(place)+"\n";
resultsTable += '| align="center"| '+String(points)+"\n";
resultsTable += '|- style="background:gold;font-weight:bold;"'+"\n";
});
} else {
resultsTable += '|-'+"\n";
}
resultsTable += '|}';
resultsTable += '| align="center"| '+String(draw).padStart(2, '0')+"\n";
console.log(resultsTable);
resultsTable += '| {{fc|'+country+'}}'+"\n";
resultsTable += '| '+createArtistString(true, artist, featured)+"\n";
pageHTML = pageHTML.replace(wikiString, resultsTable);
resultsTable += '| "'+song+'"'+"\n";
$('.mw-parser-output').html(pageHTML);
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['*']);
});
});
});
});
*/

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['*']);
			});
	    });
	});
});
*/