MediaWiki:Common.js: Difference between revisions

From The Jadnix Codex

No edit summary
No edit summary
Tag: Manual revert
 
(36 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* ============================================================
/* ============================================================
   R&R CRDD CALCULATOR LOGIC (V2 - Fixed Display)
   JADNIX CODEX: CORE SCRIPTS (Themes + Calculator + Logos)
   ============================================================ */
   ============================================================ */
$(function() {
$(function() {
     // Only run if the calculator exists
     /* --- PART A: LOGO & THEME SYSTEM --- */
     if (!$('#crdd-interface').length) return;
      
    // 1. DEFINE LOGOS
    const logos = {
        still:  'https://files.catbox.moe/0cmhjh.png',
        dealer:  'https://files.catbox.moe/73m0cp.png',
        skipper: 'https://files.catbox.moe/8gs8n5.png'
    };
 
    // 2. HELPER: FORCE LOGO SWAP
    function swapLogo(url) {
        $('#p-logo a').css('background-image', 'url(' + url + ')');
    }


     // 1. UPDATE INDIVIDUAL NUMBERS INSTANTLY
     // 3. DETECT FACTION -> APPLY CLASS & LOGO
     $('.crdd-range').on('input', function() {
     if ($('.faction-dealer').length) {
         // Find the "0" next to this slider and update it
        $('body').addClass('theme-dealer');
         $(this).next('.crdd-value-display').text($(this).val());
         swapLogo(logos.dealer);
     });
    }
    else if ($('.faction-skipper').length) {
         $('body').addClass('theme-skipper');
        swapLogo(logos.skipper);
    }
    else if ($('.faction-still').length) {
        $('body').addClass('theme-still');
     }


     // 2. CALCULATE TOTALS
    /* --- PART B: CRDD CALCULATOR LOGIC --- */
     function updateCRDD() {
   
        let totalScore = 0;
     // Only run if calculator is present
        let activeMaxScore = 0;
     if ($('#crdd-interface').length) {
        let criticalOverride = false;
          
          
         // --- SECTION 1: SUBJECT ---
         // Update number displays instantly
         let subjSkip = $('#skip-subject').is(':checked');
         $('.crdd-range').on('input', function() {
        if (!subjSkip) {
             $(this).next('.crdd-value-display').text($(this).val());
             let s1 = parseInt($('#s-strength').val()) || 0;
        });
            let s2 = parseInt($('#s-durability').val()) || 0;
 
            let s3 = parseInt($('#s-mobility').val()) || 0;
        // The Calculation Function
            let s4 = parseInt($('#s-intel').val()) || 0;
        function updateCRDD() {
             let s5 = parseInt($('#s-stamina').val()) || 0;
             let totalScore = 0;
             let s6 = parseInt($('#s-threat').val()) || 0;
             let activeMaxScore = 0;
             let s7 = parseInt($('#s-swarm').val()) || 0;
             let criticalOverride = false;
              
              
             if (s6 > 24) criticalOverride = true;
             // SECTION 1: SUBJECT
            let subjSkip = $('#skip-subject').is(':checked');
            if (!subjSkip) {
                let s1 = parseInt($('#s-strength').val()) || 0;
                let s2 = parseInt($('#s-durability').val()) || 0;
                let s3 = parseInt($('#s-mobility').val()) || 0;
                let s4 = parseInt($('#s-intel').val()) || 0;
                let s5 = parseInt($('#s-stamina').val()) || 0;
                let s6 = parseInt($('#s-threat').val()) || 0;
                let s7 = parseInt($('#s-swarm').val()) || 0;
               
                // Critical Check
                if (s6 > 24) criticalOverride = true;
               
                let avg = (s1+s2+s3+s4+s5+s6+s7) / 7;
                totalScore += avg;
                activeMaxScore += 33;
               
                let rating = "DOCILE";
                if (avg > 8) rating = "NEUTRAL";
                if (avg > 16) rating = "HOSTILE";
                if (avg > 24) rating = "VILE";
                $('#result-subject').text(avg.toFixed(1) + " (" + rating + ")");
               
            } else {
                $('#result-subject').text("SKIPPED");
            }
 
            // SECTION 2: ITEM
            let itemSkip = $('#skip-item').is(':checked');
            if (!itemSkip) {
                let i1 = parseInt($('#i-entropy').val()) || 0;
                let i2 = parseInt($('#i-instability').val()) || 0;
                let i3 = parseInt($('#i-radiation').val()) || 0;
                let i4 = parseInt($('#i-corrupt').val()) || 0;
                let i5 = parseInt($('#i-volatility').val()) || 0;
                let i6 = parseInt($('#i-unport').val()) || 0;
                let i7 = parseInt($('#i-anomalous').val()) || 0;
                let i8 = parseInt($('#i-qty').val()) || 0;
 
                if (i7 > 24) criticalOverride = true;
 
                let avg = (i1+i2+i3+i4+i5+i6+i7+i8) / 8;
                totalScore += avg;
                activeMaxScore += 33;
               
                let rating = "FUNCTIONAL";
                if (avg > 8) rating = "ALTERED";
                if (avg > 16) rating = "UNSTABLE";
                if (avg > 24) rating = "VOID";
                $('#result-item').text(avg.toFixed(1) + " (" + rating + ")");
            } else {
                $('#result-item').text("SKIPPED");
            }
 
            // SECTION 3: SEAM
            let seamSkip = $('#skip-seam').is(':checked');
            if (!seamSkip) {
                let m1 = parseInt($('#m-instability').val()) || 0;
                let m2 = parseInt($('#m-leakage').val()) || 0;
                let m3 = parseInt($('#m-geo').val()) || 0;
                let m4 = parseInt($('#m-atmo').val()) || 0;
                let m5 = parseInt($('#m-topo').val()) || 0;
                let m6 = parseInt($('#m-dead').val()) || 0;
                let m7 = parseInt($('#m-laws').val()) || 0;
 
                // Critical Checks
                if (m3 > 24 || m4 > 24 || m6 > 24 || m7 > 24) criticalOverride = true;
 
                let avg = (m1+m2+m3+m4+m5+m6+m7) / 7;
                totalScore += avg;
                activeMaxScore += 33;
               
                let rating = "ANCHORED";
                if (avg > 8) rating = "VOLATILE";
                if (avg > 16) rating = "FRACTURED";
                if (avg > 24) rating = "NULL";
                $('#result-seam').text(avg.toFixed(1) + " (" + rating + ")");
               
            } else {
                $('#result-seam').text("SKIPPED");
            }
 
            // FINAL RESULT LOGIC
            let finalBox = $('#crdd-final-output');
            let finalLabel = $('#crdd-final-label');
              
              
             let avg = (s1+s2+s3+s4+s5+s6+s7) / 7;
             if (activeMaxScore === 0) {
             totalScore += avg;
                finalBox.text("ERROR: NO DATA");
             activeMaxScore += 33;
                finalBox.css('color', 'red');
                return;
             }
 
             let percent = (totalScore / activeMaxScore) * 100;
              
              
             let rating = "DOCILE";
             // STATE 1: CRITICAL OVERRIDE (Specific stat > 24)
            if (avg > 8) rating = "NEUTRAL";
            // Visual: Blinding White, Red Text, "LEAVE NOW"
            if (avg > 16) rating = "HOSTILE";
            if (criticalOverride) {
            if (avg > 24) rating = "VILE";
                finalLabel.text("CRITICAL THREAT DETECTED");
            $('#result-subject').text(avg.toFixed(1) + " (" + rating + ")");
                finalBox.text("NULL (" + percent.toFixed(1) + "% - LEAVE NOW)");
           
                finalBox.css({
            if (avg > 24) criticalOverride = true;
                    'background-color': '#ffffff',
        } else {
                    'color': '#000000',
            $('#result-subject').text("SKIPPED");
                    'border-color': '#ff0000',
                    'text-shadow': '0 0 10px red',
                    'box-shadow': '0 0 30px rgba(255, 0, 0, 0.8)'
                });
            }
            // STATE 2: NORMAL CALCULATION (Including Organic Null)
            else {
                let finalRating = "ANCHORED";
                let finalColor = "#00ff9f"; // Green
                let finalMsg = "YOU ARE SAFE";
                let finalShadow = finalColor;
                let finalBg = "transparent";
                let finalBoxShadow = "none";
 
                if (percent > 25) {
                    finalRating = "VOLATILE";  
                    finalColor = "#ffd700"; // Gold
                    finalMsg = "PROCEED WITH CAUTION";
                    finalShadow = finalColor;
                }
                if (percent > 50) {
                    finalRating = "FRACTURED";
                    finalColor = "#ff4500"; // Orange-Red
                    finalMsg = "YOU ARE IN DANGER";  
                    finalShadow = finalColor;
                }
               
                // ORGANIC NULL (Math > 75%, but no critical trigger)
                // Visual: Dead Grey, "REALITY FAILURE"
                if (percent > 75) {
                    finalRating = "NULL";
                    finalColor = "#888888"; // Grey
                    finalMsg = "REALITY FAILURE";  
                    finalShadow = "#000000"; // No Glow
                }
 
                finalLabel.text(finalMsg);
                finalBox.text(finalRating + " (" + percent.toFixed(1) + "%)");
               
                finalBox.css({
                    'background-color': finalBg,
                    'color': finalColor,
                    'border-color': finalColor,
                    'text-shadow': '0 0 10px ' + finalShadow,
                    'box-shadow': finalBoxShadow
                });
            }
         }
         }


         // --- SECTION 2: ITEM ---
         // Trigger update on any change
         let itemSkip = $('#skip-item').is(':checked');
         $('.crdd-range, input[type=checkbox]').on('input change', updateCRDD);
        if (!itemSkip) {
    }
            let i1 = parseInt($('#i-entropy').val()) || 0;
});
             let i2 = parseInt($('#i-instability').val()) || 0;
 
             let i3 = parseInt($('#i-radiation').val()) || 0;
/* ============================================================
            let i4 = parseInt($('#i-corrupt').val()) || 0;
  SPLASH SCREEN RANDOMIZER
            let i5 = parseInt($('#i-volatility').val()) || 0;
  ============================================================ */
            let i6 = parseInt($('#i-unport').val()) || 0;
$(function() {
            let i7 = parseInt($('#i-anomalous').val()) || 0;
    if ($('body').hasClass('page-Warning')) {
            let i8 = parseInt($('#i-qty').val()) || 0;
        const factions = [
            { name: 'still', class: 'splash-purple', status: 'RECOGNIZED', pact: 'THE QUIESCENT PACT', target: 'ALPHA-EARTH' },
             { name: 'dealer', class: 'splash-gold', status: 'PAID IN FULL', pact: 'HOUSE VOIDSEED TERMS', target: 'THE GILDED GATE' },
             { name: 'skipper', class: 'splash-blue', status: 'SECURED', pact: 'R&R SAFETY PROTOCOLS', target: 'SUB-DIMENSION 00' }
        ];
 
        const roll = Math.floor(Math.random() * factions.length);
        const winner = factions[roll];
 
        $('body').addClass(winner.class);
        $('#splash-status').text(winner.status);
        $('#splash-pact').text(winner.pact);
        $('#splash-target').text(winner.target);
    }
});
 
/* ============================================================
  CONVENIENT DISCUSSIONS (FORUM ENGINE)
  ============================================================ */
mw.loader.load('https://commons.wikimedia.org/w/index.php?title=User:Jack_who_built_the_house/convenientDiscussions.js&action=raw&ctype=text/javascript');


            if (i7 > 24) criticalOverride = true;
// Optional Config: Force Dark Mode compatibility settings if available
window.convenientDiscussions = window.convenientDiscussions || {};
window.convenientDiscussions.config = {
    // This helps the script guess where the comment ends in custom skins
    defaultCommentLinkType: 'diff',
};


            let avg = (i1+i2+i3+i4+i5+i6+i7+i8) / 8;
/* ============================================================
            totalScore += avg;
  FORCE VIEW MODE FOR TALK PAGES (STOP AUTO-EDIT)
            activeMaxScore += 33;
  ============================================================ */
           
$(function() {
            let rating = "FUNCTIONAL";
    // Target the Discussion Tab link (ID usually #ca-talk)
            if (avg > 8) rating = "ALTERED";
    var talkTab = $('#ca-talk a');
            if (avg > 16) rating = "UNSTABLE";
            if (avg > 24) rating = "VOID";
            $('#result-item').text(avg.toFixed(1) + " (" + rating + ")");
        } else {
            $('#result-item').text("SKIPPED");
        }


        // --- SECTION 3: SEAM ---
    if (talkTab.length) {
        let seamSkip = $('#skip-seam').is(':checked');
         var href = talkTab.attr('href');
         if (!seamSkip) {
            let m1 = parseInt($('#m-instability').val()) || 0;
            let m2 = parseInt($('#m-leakage').val()) || 0;
            let m3 = parseInt($('#m-geo').val()) || 0;
            let m4 = parseInt($('#m-atmo').val()) || 0;
            let m5 = parseInt($('#m-topo').val()) || 0;
            let m6 = parseInt($('#m-dead').val()) || 0;
            let m7 = parseInt($('#m-laws').val()) || 0;


             if (m3 > 24 || m4 > 24 || m6 > 24 || m7 > 24) criticalOverride = true;
        // Check if the link forces an edit (Red Links usually do)
        if (href && (href.indexOf('action=edit') !== -1)) {
           
            // 1. Remove the 'action=edit' and 'redlink=1' parameters
            // This converts "/w/index.php?title=Talk:Home&action=edit" -> "/w/index.php?title=Talk:Home"
            var cleanUrl = href.replace(/&action=edit.*/, '').replace(/\?action=edit.*/, '?');
           
            // 2. Cleanup trailing question marks if regex was messy
             if (cleanUrl.endsWith('?')) {
                cleanUrl = cleanUrl.slice(0, -1);
            }


             let avg = (m1+m2+m3+m4+m5+m6+m7) / 7;
             // 3. Update the link
             totalScore += avg;
             talkTab.attr('href', cleanUrl);
            activeMaxScore += 33;
              
              
             let rating = "ANCHORED";
             // 4. (Optional) Visual cue - remove the 'new' class so it doesn't look red
            if (avg > 8) rating = "VOLATILE";
             // talkTab.removeClass('new');  
            if (avg > 16) rating = "FRACTURED";
            if (avg > 24) rating = "NULL";
            $('#result-seam').text(avg.toFixed(1) + " (" + rating + ")");
             if (avg > 24) criticalOverride = true;
        } else {
            $('#result-seam').text("SKIPPED");
         }
         }
    }
});


        // --- FINAL RESULT ---
/* ============================================================
        let finalBox = $('#crdd-final-output');
  ONYX REGISTRY: SMART SCANNER (NAME & VALUE)
         let finalLabel = $('#crdd-final-label');
  ============================================================ */
$(function() {
    $('#onyx-scanner-input').on('input', function() {
         var input = $(this).val().toLowerCase().trim();
          
          
         if (activeMaxScore === 0) {
        // 1. Reset state if empty
             finalBox.text("ERROR: NO DATA");
         if (input === "") {
            finalBox.css('color', 'red');
             $('.onyx-row').css({'opacity': '1', 'background': 'transparent', 'display': 'table-row'});
             return;
             return;
         }
         }


         let percent = (totalScore / activeMaxScore) * 100;
         // 2. Check if the user is typing a Number or a Name
       
        var isNumeric = !isNaN(input) && !isNaN(parseFloat(input));
         if (criticalOverride) {
 
             finalLabel.text("CRITICAL THREAT DETECTED");
         $('.onyx-row').each(function() {
             finalBox.text("NULL (LEAVE NOW)");
             var row = $(this);
            finalBox.css({
            var name = row.find('td:first-child').text().toLowerCase();
                'color': '#000000',
             var cr = parseInt(row.attr('data-cr')) || 0;
                'background': '#fff',
 
                 'text-shadow': '0 0 10px red'
            if (isNumeric) {
             });
                // VALUE SEARCH: Highlight rows where CR is equal to or less than input
        } else {
                var targetCR = parseInt(input);
             let finalRating = "ANCHORED";
                if (cr <= targetCR) {
            let finalColor = "#00ff9f";  
                    row.css({'opacity': '1', 'background': 'rgba(218, 165, 32, 0.15)', 'display': 'table-row'});
            let finalMsg = "YOU ARE SAFE";
                 } else {
                    row.css({'opacity': '0.2', 'background': 'transparent', 'display': 'table-row'});
                }
             } else {
                // NAME SEARCH: Filter list to match name string
                if (name.indexOf(input) !== -1) {
                    row.css({'opacity': '1', 'background': 'transparent', 'display': 'table-row'});
                } else {
                    row.css('display', 'none'); // Hide non-matching names
                }
             }
        });
    });
});


            if (percent > 25) { finalRating = "VOLATILE"; finalColor = "#ffd700"; finalMsg = "PROCEED WITH CAUTION"; }
/* ============================================================
             if (percent > 50) { finalRating = "FRACTURED"; finalColor = "#ff4500"; finalMsg = "YOU ARE IN DANGER"; }
  ONYX REGISTRY: CLIENT-SIDE BAR RENDERING
             if (percent > 75) { finalRating = "NULL"; finalColor = "#555"; finalMsg = "LEAVE NOW"; }
  ============================================================ */
$(function() {
    function renderOnyxBars() {
        $('.onyx-row').each(function() {
            var row = $(this);
            var cr = parseInt(row.attr('data-cr')) || 0;
           
            // 1. Determine the Scale (Mortal/Immortal/Ceaseless)
            var scale = 10000;
             if (cr >= 10000) scale = 100000;
             if (cr >= 100000) scale = 1000000;


             finalLabel.text(finalMsg);
             // 2. Calculate and apply widths
             finalBox.text(finalRating + " (" + percent.toFixed(1) + "%)");
            var stats = ['str', 'def', 'spd', 'acu', 'sol'];
            finalBox.css({
             stats.forEach(function(stat) {
                 'color': finalColor,
                var val = parseInt(row.attr('data-' + stat)) || 0;
                 'background': 'transparent',
                var percent = (val / scale) * 100;
                 'text-shadow': '0 0 10px ' + finalColor
                 if (percent > 100) percent = 100; // Cap at 100%
                  
                 row.find('.bar-' + stat).css('width', percent + '%');
             });
             });
         }
         });
     }
     }


     // Trigger update on any change
     // Run it immediately
     $('.crdd-range, input[type=checkbox]').on('input change', updateCRDD);
    renderOnyxBars();
   
    // Safety: Run again if the scanner is used
     $('#onyx-scanner-input').on('input', function() {
        setTimeout(renderOnyxBars, 50);
    });
});
});


/* ============================================================
/* ============================================================
   AUTO-THEMER (Detect Factions and Paint the UI)
   ART LOADOUT MATRIX: TAB SWITCHING LOGIC
   ============================================================ */
   ============================================================ */
$(function() {
$(function() {
     // If the content contains the Dealer wrapper...
     $('body').on('click', '.loadout-tab', function() {
    if ($('.faction-dealer').length > 0) {
        var $this = $(this);
         // ...Tell the Body/Skin to become Dealer Themed
        var targetId = $this.attr('data-tab');
        $('body').addClass('theme-dealer');
        var $container = $this.closest('.loadout-container');
    }
 
         $container.find('.loadout-tab').removeClass('active');
        $this.addClass('active');


    // If the content contains the Skipper wrapper...
        $container.find('.tab-pane').hide();
    if ($('.faction-skipper').length > 0) {
         $container.find('#' + targetId).show();
         // ...Tell the Body/Skin to become Skipper Themed
     });
        $('body').addClass('theme-skipper');
     }
});
});

Latest revision as of 05:45, 15 February 2026

/* ============================================================
   JADNIX CODEX: CORE SCRIPTS (Themes + Calculator + Logos)
   ============================================================ */

$(function() {
    /* --- PART A: LOGO & THEME SYSTEM --- */
    
    // 1. DEFINE LOGOS
    const logos = {
        still:   'https://files.catbox.moe/0cmhjh.png',
        dealer:  'https://files.catbox.moe/73m0cp.png',
        skipper: 'https://files.catbox.moe/8gs8n5.png'
    };

    // 2. HELPER: FORCE LOGO SWAP
    function swapLogo(url) {
        $('#p-logo a').css('background-image', 'url(' + url + ')');
    }

    // 3. DETECT FACTION -> APPLY CLASS & LOGO
    if ($('.faction-dealer').length) {
        $('body').addClass('theme-dealer');
        swapLogo(logos.dealer);
    }
    else if ($('.faction-skipper').length) {
        $('body').addClass('theme-skipper');
        swapLogo(logos.skipper);
    }
    else if ($('.faction-still').length) {
        $('body').addClass('theme-still');
    }

     /* --- PART B: CRDD CALCULATOR LOGIC --- */
    
    // Only run if calculator is present
    if ($('#crdd-interface').length) {
        
        // Update number displays instantly
        $('.crdd-range').on('input', function() {
            $(this).next('.crdd-value-display').text($(this).val());
        });

        // The Calculation Function
        function updateCRDD() {
            let totalScore = 0;
            let activeMaxScore = 0;
            let criticalOverride = false;
            
            // SECTION 1: SUBJECT
            let subjSkip = $('#skip-subject').is(':checked');
            if (!subjSkip) {
                let s1 = parseInt($('#s-strength').val()) || 0;
                let s2 = parseInt($('#s-durability').val()) || 0;
                let s3 = parseInt($('#s-mobility').val()) || 0;
                let s4 = parseInt($('#s-intel').val()) || 0;
                let s5 = parseInt($('#s-stamina').val()) || 0;
                let s6 = parseInt($('#s-threat').val()) || 0;
                let s7 = parseInt($('#s-swarm').val()) || 0;
                
                // Critical Check
                if (s6 > 24) criticalOverride = true;
                
                let avg = (s1+s2+s3+s4+s5+s6+s7) / 7;
                totalScore += avg;
                activeMaxScore += 33;
                
                let rating = "DOCILE";
                if (avg > 8) rating = "NEUTRAL";
                if (avg > 16) rating = "HOSTILE";
                if (avg > 24) rating = "VILE";
                $('#result-subject').text(avg.toFixed(1) + " (" + rating + ")");
                
            } else {
                 $('#result-subject').text("SKIPPED");
            }

            // SECTION 2: ITEM
            let itemSkip = $('#skip-item').is(':checked');
            if (!itemSkip) {
                let i1 = parseInt($('#i-entropy').val()) || 0;
                let i2 = parseInt($('#i-instability').val()) || 0;
                let i3 = parseInt($('#i-radiation').val()) || 0;
                let i4 = parseInt($('#i-corrupt').val()) || 0;
                let i5 = parseInt($('#i-volatility').val()) || 0;
                let i6 = parseInt($('#i-unport').val()) || 0;
                let i7 = parseInt($('#i-anomalous').val()) || 0;
                let i8 = parseInt($('#i-qty').val()) || 0;

                if (i7 > 24) criticalOverride = true;

                let avg = (i1+i2+i3+i4+i5+i6+i7+i8) / 8;
                totalScore += avg;
                activeMaxScore += 33;
                
                let rating = "FUNCTIONAL";
                if (avg > 8) rating = "ALTERED";
                if (avg > 16) rating = "UNSTABLE";
                if (avg > 24) rating = "VOID";
                $('#result-item').text(avg.toFixed(1) + " (" + rating + ")");
            } else {
                $('#result-item').text("SKIPPED");
            }

            // SECTION 3: SEAM
            let seamSkip = $('#skip-seam').is(':checked');
            if (!seamSkip) {
                let m1 = parseInt($('#m-instability').val()) || 0;
                let m2 = parseInt($('#m-leakage').val()) || 0;
                let m3 = parseInt($('#m-geo').val()) || 0;
                let m4 = parseInt($('#m-atmo').val()) || 0;
                let m5 = parseInt($('#m-topo').val()) || 0;
                let m6 = parseInt($('#m-dead').val()) || 0;
                let m7 = parseInt($('#m-laws').val()) || 0;

                // Critical Checks
                if (m3 > 24 || m4 > 24 || m6 > 24 || m7 > 24) criticalOverride = true;

                let avg = (m1+m2+m3+m4+m5+m6+m7) / 7;
                totalScore += avg;
                activeMaxScore += 33;
                
                let rating = "ANCHORED";
                if (avg > 8) rating = "VOLATILE";
                if (avg > 16) rating = "FRACTURED";
                if (avg > 24) rating = "NULL";
                $('#result-seam').text(avg.toFixed(1) + " (" + rating + ")");
                
            } else {
                $('#result-seam').text("SKIPPED");
            }

            // FINAL RESULT LOGIC
            let finalBox = $('#crdd-final-output');
            let finalLabel = $('#crdd-final-label');
            
            if (activeMaxScore === 0) {
                finalBox.text("ERROR: NO DATA");
                finalBox.css('color', 'red');
                return;
            }

            let percent = (totalScore / activeMaxScore) * 100;
            
            // STATE 1: CRITICAL OVERRIDE (Specific stat > 24)
            // Visual: Blinding White, Red Text, "LEAVE NOW"
            if (criticalOverride) {
                finalLabel.text("CRITICAL THREAT DETECTED");
                finalBox.text("NULL (" + percent.toFixed(1) + "% - LEAVE NOW)");
                finalBox.css({
                    'background-color': '#ffffff',
                    'color': '#000000',
                    'border-color': '#ff0000',
                    'text-shadow': '0 0 10px red',
                    'box-shadow': '0 0 30px rgba(255, 0, 0, 0.8)'
                });
            } 
            // STATE 2: NORMAL CALCULATION (Including Organic Null)
            else {
                let finalRating = "ANCHORED";
                let finalColor = "#00ff9f"; // Green
                let finalMsg = "YOU ARE SAFE";
                let finalShadow = finalColor;
                let finalBg = "transparent";
                let finalBoxShadow = "none";

                if (percent > 25) { 
                    finalRating = "VOLATILE"; 
                    finalColor = "#ffd700"; // Gold
                    finalMsg = "PROCEED WITH CAUTION"; 
                    finalShadow = finalColor;
                }
                if (percent > 50) { 
                    finalRating = "FRACTURED"; 
                    finalColor = "#ff4500"; // Orange-Red
                    finalMsg = "YOU ARE IN DANGER"; 
                    finalShadow = finalColor;
                }
                
                // ORGANIC NULL (Math > 75%, but no critical trigger)
                // Visual: Dead Grey, "REALITY FAILURE"
                if (percent > 75) { 
                    finalRating = "NULL"; 
                    finalColor = "#888888"; // Grey
                    finalMsg = "REALITY FAILURE"; 
                    finalShadow = "#000000"; // No Glow
                }

                finalLabel.text(finalMsg);
                finalBox.text(finalRating + " (" + percent.toFixed(1) + "%)");
                
                finalBox.css({
                    'background-color': finalBg,
                    'color': finalColor,
                    'border-color': finalColor,
                    'text-shadow': '0 0 10px ' + finalShadow,
                    'box-shadow': finalBoxShadow
                });
            }
        }

        // Trigger update on any change
        $('.crdd-range, input[type=checkbox]').on('input change', updateCRDD);
    }
});

/* ============================================================
   SPLASH SCREEN RANDOMIZER
   ============================================================ */
$(function() {
    if ($('body').hasClass('page-Warning')) {
        const factions = [
            { name: 'still', class: 'splash-purple', status: 'RECOGNIZED', pact: 'THE QUIESCENT PACT', target: 'ALPHA-EARTH' },
            { name: 'dealer', class: 'splash-gold', status: 'PAID IN FULL', pact: 'HOUSE VOIDSEED TERMS', target: 'THE GILDED GATE' },
            { name: 'skipper', class: 'splash-blue', status: 'SECURED', pact: 'R&R SAFETY PROTOCOLS', target: 'SUB-DIMENSION 00' }
        ];

        const roll = Math.floor(Math.random() * factions.length);
        const winner = factions[roll];

        $('body').addClass(winner.class);
        $('#splash-status').text(winner.status);
        $('#splash-pact').text(winner.pact);
        $('#splash-target').text(winner.target);
    }
});

/* ============================================================
   CONVENIENT DISCUSSIONS (FORUM ENGINE)
   ============================================================ */
mw.loader.load('https://commons.wikimedia.org/w/index.php?title=User:Jack_who_built_the_house/convenientDiscussions.js&action=raw&ctype=text/javascript');

// Optional Config: Force Dark Mode compatibility settings if available
window.convenientDiscussions = window.convenientDiscussions || {};
window.convenientDiscussions.config = {
    // This helps the script guess where the comment ends in custom skins
    defaultCommentLinkType: 'diff',
};

/* ============================================================
   FORCE VIEW MODE FOR TALK PAGES (STOP AUTO-EDIT)
   ============================================================ */
$(function() {
    // Target the Discussion Tab link (ID usually #ca-talk)
    var talkTab = $('#ca-talk a');

    if (talkTab.length) {
        var href = talkTab.attr('href');

        // Check if the link forces an edit (Red Links usually do)
        if (href && (href.indexOf('action=edit') !== -1)) {
            
            // 1. Remove the 'action=edit' and 'redlink=1' parameters
            // This converts "/w/index.php?title=Talk:Home&action=edit" -> "/w/index.php?title=Talk:Home"
            var cleanUrl = href.replace(/&action=edit.*/, '').replace(/\?action=edit.*/, '?');
            
            // 2. Cleanup trailing question marks if regex was messy
            if (cleanUrl.endsWith('?')) {
                cleanUrl = cleanUrl.slice(0, -1);
            }

            // 3. Update the link
            talkTab.attr('href', cleanUrl);
            
            // 4. (Optional) Visual cue - remove the 'new' class so it doesn't look red
            // talkTab.removeClass('new'); 
        }
    }
});

/* ============================================================
   ONYX REGISTRY: SMART SCANNER (NAME & VALUE)
   ============================================================ */
$(function() {
    $('#onyx-scanner-input').on('input', function() {
        var input = $(this).val().toLowerCase().trim();
        
        // 1. Reset state if empty
        if (input === "") {
            $('.onyx-row').css({'opacity': '1', 'background': 'transparent', 'display': 'table-row'});
            return;
        }

        // 2. Check if the user is typing a Number or a Name
        var isNumeric = !isNaN(input) && !isNaN(parseFloat(input));

        $('.onyx-row').each(function() {
            var row = $(this);
            var name = row.find('td:first-child').text().toLowerCase();
            var cr = parseInt(row.attr('data-cr')) || 0;

            if (isNumeric) {
                // VALUE SEARCH: Highlight rows where CR is equal to or less than input
                var targetCR = parseInt(input);
                if (cr <= targetCR) {
                    row.css({'opacity': '1', 'background': 'rgba(218, 165, 32, 0.15)', 'display': 'table-row'});
                } else {
                    row.css({'opacity': '0.2', 'background': 'transparent', 'display': 'table-row'});
                }
            } else {
                // NAME SEARCH: Filter list to match name string
                if (name.indexOf(input) !== -1) {
                    row.css({'opacity': '1', 'background': 'transparent', 'display': 'table-row'});
                } else {
                    row.css('display', 'none'); // Hide non-matching names
                }
            }
        });
    });
});

/* ============================================================
   ONYX REGISTRY: CLIENT-SIDE BAR RENDERING
   ============================================================ */
$(function() {
    function renderOnyxBars() {
        $('.onyx-row').each(function() {
            var row = $(this);
            var cr = parseInt(row.attr('data-cr')) || 0;
            
            // 1. Determine the Scale (Mortal/Immortal/Ceaseless)
            var scale = 10000;
            if (cr >= 10000) scale = 100000;
            if (cr >= 100000) scale = 1000000;

            // 2. Calculate and apply widths
            var stats = ['str', 'def', 'spd', 'acu', 'sol'];
            stats.forEach(function(stat) {
                var val = parseInt(row.attr('data-' + stat)) || 0;
                var percent = (val / scale) * 100;
                if (percent > 100) percent = 100; // Cap at 100%
                
                row.find('.bar-' + stat).css('width', percent + '%');
            });
        });
    }

    // Run it immediately
    renderOnyxBars();
    
    // Safety: Run again if the scanner is used
    $('#onyx-scanner-input').on('input', function() {
        setTimeout(renderOnyxBars, 50); 
    });
});

/* ============================================================
   ART LOADOUT MATRIX: TAB SWITCHING LOGIC
   ============================================================ */
$(function() {
    $('body').on('click', '.loadout-tab', function() {
        var $this = $(this);
        var targetId = $this.attr('data-tab');
        var $container = $this.closest('.loadout-container');

        $container.find('.loadout-tab').removeClass('active');
        $this.addClass('active');

        $container.find('.tab-pane').hide();
        $container.find('#' + targetId).show();
    });
});