MediaWiki:Common.js: Difference between revisions

From Ylvapedia
Jump to navigation Jump to search
mNo edit summary
m (es5 compat change)
Line 5: Line 5:
     // Define the values for red and green text
     // Define the values for red and green text
     var redValues = ["Dry", "Fairy Sized", "Dead", "Stinky", "Boring", "Crunchy", "Bitter", "Tarnished", "Bland", "Coarse", "Rustic", "Dull Color", "Harmful Substance", "Squishy", "Tasteless", "Ugly"];
     var redValues = ["Dry", "Fairy Sized", "Dead", "Stinky", "Boring", "Crunchy", "Bitter", "Tarnished", "Bland", "Coarse", "Rustic", "Dull Color", "Harmful Substance", "Squishy", "Tasteless", "Ugly"];
     var greenValues = ["Slightly moist", "Pumpkin Sized", "Almost Moving", "Faint Aroma", "Unusual", "Slightly Firm", "Slightly Sweet", "Concerning", "Collagen Rich", "Creamy", "Somewhat Dense", "Slightly Rough", "Pale Color", "Trace Vitamins", "Flaky", "Somewhat Spicy", "Glossy", ];
     var greenValues = ["Slightly moist", "Pumpkin Sized", "Almost Moving", "Faint Aroma", "Unusual", "Slightly Firm", "Slightly Sweet", "Concerning", "Collagen Rich", "Creamy", "Somewhat Dense", "Slightly Rough", "Pale Color", "Trace Vitamins", "Flaky", "Somewhat Spicy", "Glossy"];


     // Loop through each table cell in wikitable
     // Loop through each table cell in wikitable
Line 12: Line 12:


         // Check if cell text contains any redValues partially
         // Check if cell text contains any redValues partially
         if (redValues.some(value => cellText.includes(value))) {
         if (redValues.some(function (value) {
            return cellText.indexOf(value) !== -1;
        })) {
             $(this).css('color', 'red');
             $(this).css('color', 'red');
         }
         }


         // Check if cell text contains any greenValues partially
         // Check if cell text contains any greenValues partially
         if (greenValues.some(value => cellText.includes(value))) {
         if (greenValues.some(function (value) {
            return cellText.indexOf(value) !== -1;
        })) {
             $(this).css('color', 'green');
             $(this).css('color', 'green');
         }
         }
     });
     });
});
});

Revision as of 23:07, 2 March 2024

/* Any JavaScript here will be loaded for all users on every page load. */
importScript('MediaWiki:jquery.js');

$(document).ready(function () {
    // Define the values for red and green text
    var redValues = ["Dry", "Fairy Sized", "Dead", "Stinky", "Boring", "Crunchy", "Bitter", "Tarnished", "Bland", "Coarse", "Rustic", "Dull Color", "Harmful Substance", "Squishy", "Tasteless", "Ugly"];
    var greenValues = ["Slightly moist", "Pumpkin Sized", "Almost Moving", "Faint Aroma", "Unusual", "Slightly Firm", "Slightly Sweet", "Concerning", "Collagen Rich", "Creamy", "Somewhat Dense", "Slightly Rough", "Pale Color", "Trace Vitamins", "Flaky", "Somewhat Spicy", "Glossy"];

    // Loop through each table cell in wikitable
    $('.wikitable td').each(function () {
        var cellText = $(this).text().trim();

        // Check if cell text contains any redValues partially
        if (redValues.some(function (value) {
            return cellText.indexOf(value) !== -1;
        })) {
            $(this).css('color', 'red');
        }

        // Check if cell text contains any greenValues partially
        if (greenValues.some(function (value) {
            return cellText.indexOf(value) !== -1;
        })) {
            $(this).css('color', 'green');
        }
    });
});