Jump to content

MediaWiki:Common.js: Difference between revisions

The comprehensive free global encyclopedia of CEOs, corporate leadership, and business excellence
Improve 3D tag cloud mouse responsiveness with smooth interpolation and increased sensitivity
Add footer disclaimer via JavaScript injection
Line 1: Line 1:
/**
/* Add Wikipedia disclaimer to footer */
* Add statistics banner to account creation page
$(document).ready(function() {
*/
    // Find the footer copyright element
(function() {
    var $footer = $('#footer-info-copyright');
    // Only run on Special:CreateAccount page
    if (typeof mw !== 'undefined' && mw.config && mw.config.get('wgCanonicalSpecialPageName') !== 'CreateAccount') {
        return;
    }
 
    if (typeof mw !== 'undefined' && mw.Api && typeof $ !== 'undefined') {
        // Get site statistics via API
        var api = new mw.Api();
 
        api.get({
            action: 'query',
            meta: 'siteinfo',
            siprop: 'statistics',
            format: 'json'
        }).done(function(data) {
            var stats = data.query.statistics;
 
            // Create statistics banner
            var banner = $('<div>').addClass('createaccount-statistics').html(
                '<div class="createaccount-statistics-title">CEO.wiki is made by people like you.</div>' +
                '<div class="createaccount-statistics-grid">' +
                    '<div class="createaccount-stat-item">' +
                        '<div class="createaccount-stat-number">' + stats.edits.toLocaleString() + '</div>' +
                        '<div class="createaccount-stat-label">Edits</div>' +
                    '</div>' +
                    '<div class="createaccount-stat-item">' +
                        '<div class="createaccount-stat-number">' + stats.pages.toLocaleString() + '</div>' +
                        '<div class="createaccount-stat-label">Pages</div>' +
                    '</div>' +
                    '<div class="createaccount-stat-item">' +
                        '<div class="createaccount-stat-number">' + stats.activeusers.toLocaleString() + '</div>' +
                        '<div class="createaccount-stat-label">Recent Contributors</div>' +
                    '</div>' +
                '</div>'
            );
 
            // Insert banner before the form
            $('#userloginForm').before(banner);
        });
    }
})();
 
/**
* 3D Rotating Tag Cloud - Extra Large Text for Accessibility
*/
(function() {
    'use strict';
   
    console.log('[TagCloud] Script loaded');
      
      
    // Check if we're on Main Page
     if ($footer.length) {
     if (typeof mw !== 'undefined' && mw.config) {
        // Footer exists, ensure disclaimer is visible
         var pageName = mw.config.get('wgPageName');
         var footerHTML = $footer.html();
         console.log('[TagCloud] Page name:', pageName);
         if (footerHTML && footerHTML.indexOf('CEO.wiki is operated as an independent') === -1) {
        if (pageName !== 'Main_Page') {
             // Disclaimer not found, add it
             console.log('[TagCloud] Not Main Page, exiting');
            $footer.append(' <strong>CEO.wiki is operated as an independent collaborative encyclopedia project and is not affiliated with Wikipedia or the Wikimedia Foundation.</strong>');
            return;
         }
         }
    } else {
        // Footer doesn't exist, create it
        var disclaimer = '<div id="footer-info-copyright" style="text-align: center; padding: 20px; background: #f8f9fa; border-top: 1px solid #ddd; margin-top: 40px; font-size: 0.85em; line-height: 1.6;">Text is available under the <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="nofollow">Creative Commons Attribution-ShareAlike 4.0 License</a>; additional terms may apply. By using this site, you agree to the <a href="/wiki/CEO.wiki:Terms_of_Use">Terms of Use</a>, <a href="/wiki/CEO.wiki:Privacy_Policy">Privacy Policy</a>, and all <a href="/wiki/CEO.wiki:General_disclaimer">disclaimers</a>. <strong>CEO.wiki is operated as an independent collaborative encyclopedia project and is not affiliated with Wikipedia or the Wikimedia Foundation.</strong> See our <a href="/wiki/CEO.wiki:Takedown_Request_Policy">Takedown Request Policy</a> for content concerns.</div>';
        $('.mw-footer-container, .mw-page-container, #footer, body').append(disclaimer);
     }
     }
   
});
    var attempts = 0;
    var maxAttempts = 50;
   
    function tryInitialize() {
        attempts++;
       
        // Look for the placeholder div
        var placeholder = document.getElementById('ceocloud-placeholder');
        if (!placeholder) {
            if (attempts < maxAttempts) {
                console.log('[TagCloud] Placeholder not found yet, retrying... (attempt ' + attempts + '/' + maxAttempts + ')');
                setTimeout(tryInitialize, 100);
            } else {
                console.error('[TagCloud] Placeholder div not found after ' + maxAttempts + ' attempts. Giving up.');
            }
            return;
        }
       
        console.log('[TagCloud] Placeholder found after ' + attempts + ' attempts! Creating canvas...');
       
        // Create canvas element dynamically
        var canvas = document.createElement('canvas');
        canvas.id = 'tagcanvas';
        canvas.width = 800;
        canvas.height = 400;
        canvas.style.maxWidth = '100%';
        canvas.style.height = 'auto';
       
        // Clear placeholder and add canvas
        placeholder.innerHTML = '';
        placeholder.appendChild(canvas);
       
        console.log('[TagCloud] Canvas created and added to DOM');
       
        var ctx = canvas.getContext('2d');
        if (!ctx) {
            console.error('[TagCloud] Could not get 2D context');
            return;
        }
       
        var width = canvas.width;
        var height = canvas.height;
       
        console.log('[TagCloud] Canvas size:', width, 'x', height);
       
        // Tags configuration - 100% larger than previous (now 4x original size for elderly users)
        var tags = [
            { text: 'Satya Nadella', url: '/wiki/Satya_Nadella', size: 144 },
            { text: 'Tim Cook', url: '/wiki/Tim_Cook', size: 132 },
            { text: 'Elon Musk', url: '/wiki/Elon_Musk', size: 156 },
            { text: 'Mark Zuckerberg', url: '/wiki/Mark_Zuckerberg', size: 120 },
            { text: 'Sundar Pichai', url: '/wiki/Sundar_Pichai', size: 120 },
            { text: 'Andy Jassy', url: '/wiki/Andy_Jassy', size: 108 },
            { text: 'Jensen Huang', url: '/wiki/Jensen_Huang', size: 132 },
            { text: 'Lisa Su', url: '/wiki/Lisa_Su', size: 108 },
            { text: 'Mary Barra', url: '/wiki/Mary_Barra', size: 108 },
            { text: 'Jamie Dimon', url: '/wiki/Jamie_Dimon', size: 108 },
            { text: 'Microsoft', url: '/wiki/Microsoft', size: 96 },
            { text: 'Apple', url: '/wiki/Apple_Inc.', size: 96 },
            { text: 'Amazon', url: '/wiki/Amazon', size: 96 },
            { text: 'Google', url: '/wiki/Google', size: 96 },
            { text: 'Tesla', url: '/wiki/Tesla', size: 96 },
            { text: 'Leadership', url: '/wiki/Category:Chief_executive_officers', size: 84 },
            { text: 'Innovation', url: '/wiki/Category:Business_strategies', size: 84 },
            { text: 'Technology', url: '/wiki/Category:Companies', size: 84 },
            { text: 'Strategy', url: '/wiki/Category:Business_strategies', size: 84 },
            { text: 'Cloud Computing', url: '/wiki/Category:Industry_analysis', size: 84 }
        ];
       
        // Initialize 3D positions
        var radius = 180;
        var dtr = Math.PI / 180;
        var mcList = [];
        var lasta = 1;
        var lastb = 1;
        var tspeed = 0.5;
        var size = 250;
        var mouseX = 0;
        var mouseY = 0;
        var active = false;
       
        // Build tag objects
        for (var i = 0; i < tags.length; i++) {
            var oTag = {};
            oTag.offsetWidth = tags[i].size * 5;
            oTag.offsetHeight = tags[i].size;
            oTag.text = tags[i].text;
            oTag.url = tags[i].url;
            oTag.size = tags[i].size;
            mcList.push(oTag);
        }
       
        var sa, ca, sb, cb, sc, cc;
       
        function sineCosine(a, b, c) {
            sa = Math.sin(a * dtr);
            ca = Math.cos(a * dtr);
            sb = Math.sin(b * dtr);
            cb = Math.cos(b * dtr);
            sc = Math.sin(c * dtr);
            cc = Math.cos(c * dtr);
        }
       
        function positionAll() {
            var phi = 0;
            var theta = 0;
            var max = mcList.length;
           
            for (var i = 0; i < max; i++) {
                phi = Math.acos(-1 + (2 * i + 1) / max);
                theta = Math.sqrt(max * Math.PI) * phi;
               
                mcList[i].cx = radius * Math.cos(theta) * Math.sin(phi);
                mcList[i].cy = radius * Math.sin(theta) * Math.sin(phi);
                mcList[i].cz = radius * Math.cos(phi);
            }
        }
       
        function doPosition() {
            ctx.clearRect(0, 0, width, height);
           
            for (var i = 0; i < mcList.length; i++) {
                var tag = mcList[i];
                var x = tag.x + width / 2;
                var y = tag.y + height / 2;
               
                var alpha = Math.max(0.2, Math.min(1, tag.alpha));
                var fontSize = Math.max(10, tag.size * tag.scale);
               
                ctx.save();
                // Use Wikipedia-style serif font (Linux Libertine, Georgia, Times)
                ctx.font = fontSize + 'px "Linux Libertine", Georgia, "Times New Roman", serif';
                ctx.fillStyle = 'rgba(255, 255, 255, ' + alpha + ')';
                ctx.textAlign = 'center';
                ctx.textBaseline = 'middle';
                ctx.shadowColor = 'rgba(0, 0, 0, 0.5)';
                ctx.shadowBlur = 4;
                ctx.shadowOffsetX = 0;
                ctx.shadowOffsetY = 2;
                ctx.fillText(tag.text, x, y);
                ctx.restore();
               
                tag.cx = x;
                tag.cy = y;
            }
        }
       
        function depthSort() {
            mcList.sort(function(a, b) {
                return (b.cz - a.cz);
            });
        }
       
        function update() {
            var a, b;
 
            if (active) {
                // Mouse-controlled rotation - make it responsive to mouse position
                var targetA = (-Math.min(Math.max(-mouseY, -size), size) / radius) * tspeed * 2;
                var targetB = (Math.min(Math.max(-mouseX, -size), size) / radius) * tspeed * 2;
 
                // Smooth interpolation toward mouse position for fluid movement
                a = lasta * 0.8 + targetA * 0.2;
                b = lastb * 0.8 + targetB * 0.2;
            } else {
                // Always maintain minimum constant rotation to keep animation running indefinitely
                a = lasta * 0.98 + 0.005; // Small vertical rotation
                b = lastb * 0.98 + 0.015; // Slightly larger horizontal rotation
            }
 
            lasta = a;
            lastb = b;
 
            // REMOVED: Early return that was stopping animation
            // Animation now continues indefinitely
 
            var c = 0;
            sineCosine(a, b, c);
           
            for (var i = 0; i < mcList.length; i++) {
                var rx1 = mcList[i].cx;
                var ry1 = mcList[i].cy * ca + mcList[i].cz * (-sa);
                var rz1 = mcList[i].cy * sa + mcList[i].cz * ca;
               
                var rx2 = rx1 * cb + rz1 * sb;
                var ry2 = ry1;
                var rz2 = rx1 * (-sb) + rz1 * cb;
               
                var rx3 = rx2 * cc + ry2 * (-sc);
                var ry3 = rx2 * sc + ry2 * cc;
                var rz3 = rz2;
               
                mcList[i].cx = rx3;
                mcList[i].cy = ry3;
                mcList[i].cz = rz3;
               
                var per = size / (size + rz3);
               
                mcList[i].x = rx3 * per;
                mcList[i].y = ry3 * per;
                mcList[i].scale = per;
                mcList[i].alpha = per;
                mcList[i].alpha = (mcList[i].alpha - 0.6) * (10 / 6);
            }
           
            doPosition();
            depthSort();
        }
       
        // Event handlers
        canvas.onmouseover = function() {
            active = true;
        };
       
        canvas.onmouseout = function() {
            active = false;
        };
       
        canvas.onmousemove = function(ev) {
            var rect = canvas.getBoundingClientRect();
            mouseX = ev.clientX - rect.left - width / 2;
            mouseY = ev.clientY - rect.top - height / 2;
        };
       
        canvas.onclick = function(ev) {
            var rect = canvas.getBoundingClientRect();
            var mx = ev.clientX - rect.left;
            var my = ev.clientY - rect.top;
           
            for (var i = 0; i < mcList.length; i++) {
                var tag = mcList[i];
                var dx = mx - tag.cx;
                var dy = my - tag.cy;
                var dist = Math.sqrt(dx * dx + dy * dy);
               
                if (dist < 50) {
                    window.location.href = tag.url;
                    break;
                }
            }
        };
       
        canvas.style.cursor = 'pointer';
       
        // Initialize
        sineCosine(0, 0, 0);
        positionAll();
        setInterval(update, 30);
       
        console.log('[TagCloud] Successfully initialized with extra large text! Animation started.');
    }
   
    // Start trying to find the placeholder
    tryInitialize();
})();
/* ============================================================================
  SPECIAL:CREATEACCOUNT - STATISTICS BANNER
  ============================================================================ */
(function() {
    'use strict';
   
    // Only run on Special:CreateAccount page
    if (mw.config.get('wgCanonicalSpecialPageName') !== 'Createaccount') {
        return;
    }
   
    // Wait for DOM to be ready
    $(document).ready(function() {
        console.log('CreateAccount: Adding statistics banner');
       
        // Create statistics banner
        var $banner = $('<div>')
            .addClass('createaccount-statistics-banner')
            .html(
                '<div class="createaccount-statistics-title">CEO.wiki is made by people like you.</div>' +
                '<div class="createaccount-statistics-grid">' +
                    '<div class="createaccount-stat-item">' +
                        '<div class="createaccount-stat-number">383</div>' +
                        '<div class="createaccount-stat-label">edits</div>' +
                    '</div>' +
                    '<div class="createaccount-stat-item">' +
                        '<div class="createaccount-stat-number">41</div>' +
                        '<div class="createaccount-stat-label">pages</div>' +
                    '</div>' +
                    '<div class="createaccount-stat-item">' +
                        '<div class="createaccount-stat-number">6</div>' +
                        '<div class="createaccount-stat-label">recent contributors</div>' +
                    '</div>' +
                '</div>'
            );
       
        // Find the form and prepend the banner
        var $form = $('.mw-htmlform, #userlogin2, form[name="userlogin2"]');
        if ($form.length > 0) {
            $form.prepend($banner);
            console.log('CreateAccount: Statistics banner added successfully');
        } else {
            // Fallback: add to bodyContent
            $('#bodyContent').prepend($banner);
            console.log('CreateAccount: Statistics banner added to bodyContent (fallback)');
        }
    });
})();
/**
* Clean up registration page - Hide redundant security verification text
* Keep only hCaptcha widget with clean, modern design
*/
(function() {
    // Only run on Special:CreateAccount page
    if (typeof mw === 'undefined' || !mw.config || mw.config.get('wgCanonicalSpecialPageName') !== 'CreateAccount') {
        return;
    }
 
    // Wait for DOM to be ready
    $(document).ready(function() {
        // Hide any headings containing "Security Verification" or "Anti-Bot Protection"
        $('h1, h2, h3, h4, h5, h6').each(function() {
            var text = $(this).text().toLowerCase();
            if (text.includes('security verification') ||
                text.includes('anti-bot protection') ||
                text.includes('bot protection')) {
                $(this).hide();
            }
        });
 
        // Hide any labels that say "CAPTCHA" or "Security Question"
        $('label').each(function() {
            var text = $(this).text().toLowerCase();
            if (text.includes('captcha') && !text.includes('hcaptcha')) {
                $(this).hide();
            }
        });
 
        // Clean up CAPTCHA field wrapper
        $('.mw-htmlform-field-HTMLHCaptchaField').each(function() {
            $(this).css({
                'border': 'none',
                'padding': '0',
                'background': 'transparent'
            });
        });
 
        // Add a subtle note above hCaptcha
        if ($('.h-captcha').length > 0) {
            $('.h-captcha').parent().prepend(
                '<div style="text-align: center; margin-bottom: 12px; color: #6b7280; font-size: 14px;">' +
                'Complete the verification below to create your account' +
                '</div>'
            );
        }
 
        // Remove any duplicate CAPTCHA text/labels
        $('.mw-confirmedit-captcha-and-reload .mw-label').hide();
        $('.fancycaptcha-captcha-container .mw-label').hide();
    });
})();

Revision as of 09:41, 21 October 2025

/* Add Wikipedia disclaimer to footer */
$(document).ready(function() {
    // Find the footer copyright element
    var $footer = $('#footer-info-copyright');
    
    if ($footer.length) {
        // Footer exists, ensure disclaimer is visible
        var footerHTML = $footer.html();
        if (footerHTML && footerHTML.indexOf('CEO.wiki is operated as an independent') === -1) {
            // Disclaimer not found, add it
            $footer.append(' <strong>CEO.wiki is operated as an independent collaborative encyclopedia project and is not affiliated with Wikipedia or the Wikimedia Foundation.</strong>');
        }
    } else {
        // Footer doesn't exist, create it
        var disclaimer = '<div id="footer-info-copyright" style="text-align: center; padding: 20px; background: #f8f9fa; border-top: 1px solid #ddd; margin-top: 40px; font-size: 0.85em; line-height: 1.6;">Text is available under the <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="nofollow">Creative Commons Attribution-ShareAlike 4.0 License</a>; additional terms may apply. By using this site, you agree to the <a href="/wiki/CEO.wiki:Terms_of_Use">Terms of Use</a>, <a href="/wiki/CEO.wiki:Privacy_Policy">Privacy Policy</a>, and all <a href="/wiki/CEO.wiki:General_disclaimer">disclaimers</a>. <strong>CEO.wiki is operated as an independent collaborative encyclopedia project and is not affiliated with Wikipedia or the Wikimedia Foundation.</strong> See our <a href="/wiki/CEO.wiki:Takedown_Request_Policy">Takedown Request Policy</a> for content concerns.</div>';
        $('.mw-footer-container, .mw-page-container, #footer, body').append(disclaimer);
    }
});