MediaWiki:Common.js

From Oddsparks Wiki
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

// Function to change multiplayer
function updateCalculation(clickedButton) {
    if (!clickedButton.classList.contains("active")) {
        const $recipeCalc = $(clickedButton.closest('.recipe-calc'));
        $recipeCalc.find('.recipe-button.active').removeClass('active');
        $(clickedButton).addClass("active");

        const multiplayer = +$(clickedButton).find('.value').text();
        const duration = +$recipeCalc.find('.duration').text();
        
        var calcVal = duration / multiplayer;
        //calcVal = calcVal % 1 !== 0 ? calcVal.toFixed(2) : calcVal;
        calcVal = parseFloat(calcVal.toFixed(2).replace(/\.?0+$/, ''));
        var calPerMin = parseFloat(((60/duration)*multiplayer).toFixed(3).replace(/\.?0+$/, ''));

        $recipeCalc.find('.calculated-duration').text(calcVal);
        $recipeCalc.find('.calculated-duration-in-min').text(calPerMin);
    }
}

// Call the function when the document is ready
$(document).ready(function() {
    $('.recipe-calc').on('click', '.recipe-button', function() {
        updateCalculation(this);
    });
    
    var elements = document.querySelectorAll('.rating-star');

	elements.forEach(function(element) {
    	var style = getComputedStyle(element);
    	var checkColor = style.getPropertyValue('--check-color');
    	var uncheckColor = style.getPropertyValue('--uncheck-color')

		var mySVG = '<?xml version="1.0"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" version="1.1" xml:space="preserve" viewBox="0 0 48 48"><path d="m26.05,2.44l5.4,10.95c0.38,0.76 1.11,1.29 1.95,1.41l12.09,1.76c2.12,0.31 2.96,2.91 1.43,4.4l-8.75,8.53c-0.61,0.6 -0.89,1.45 -0.74,2.29l2.06,12.04c0.36,2.11 -1.85,3.72 -3.74,2.72l-10.82,-5.68c-0.38,-0.2 -0.55,-0.36 -1.2,-0.3c-0.65,0.06 -1.18,-39.55 0,-39.56c1.18,-0.01 1.84,0.48 2.32,1.44z" fill="'+uncheckColor+'" id="svg_1"/><path d="m23.95,40.57c-0.41,0 -0.82,0.1 -1.2,0.3l-10.82,5.68c-1.89,1 -4.1,-0.61 -3.74,-2.72l2.06,-12.04c0.15,-0.84 -0.13,-1.7 -0.74,-2.29l-8.75,-8.53c-1.53,-1.49 -0.68,-4.09 1.43,-4.4l12.09,-1.76c0.85,-0.12 1.57,-0.65 1.95,-1.41l5.41,-10.95c0.47,-0.96 1.39,-1.44 2.31,-1.44l0,39.56z" fill="'+checkColor+'" id="svg_3"/></svg>';
		var mySVG64 = window.btoa(mySVG);

		element.style.backgroundImage = "url('data:image/svg+xml;base64," + mySVG64 + "')";
	});
    
});