Jump to content

MediaWiki:Mobile.js

From Vanipedia
Revision as of 02:10, 13 November 2026 by Kashya (talk | contribs)

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* STANDALONE VANI-SEARCH CAPTURE-PHASE BYPASS */
(function() {
    function initVaniMobileSearch() {
        var header = document.querySelector('.minerva-header');
        if (!header || header.dataset.vaniBound) return;
        header.dataset.vaniBound = 'true';

        // 1. Clean out Minerva's default search form completely to stop its event listeners
        var oldForm = header.querySelector('.minerva-search-form');
        if (oldForm) oldForm.remove();

        // 2. Create a fresh, independent search container
        var container = document.createElement('div');
        container.className = 'vani-independent-search';
        container.style.cssText = 'flex: 1 1 auto !important; display: flex !important; align-items: center !important; position: relative !important; margin: 0 8px !important;';

        var input = document.createElement('input');
        input.type = 'text';
        input.className = 'vani-clean-search-input';
        input.placeholder = 'Search Vanipedia';
        input.autocomplete = 'off';
        input.style.cssText = 'width: 100% !important; height: 32px !important; background: #1f3e45 !important; color: #ffffff !important; -webkit-text-fill-color: #ffffff !important; border: 1.5px solid #f5d77f !important; border-radius: 16px !important; padding: 2px 32px 2px 12px !important; font-size: 15px !important; outline: none !important; box-sizing: border-box !important;';

        var btn = document.createElement('button');
        btn.type = 'button';
        btn.innerHTML = '🔍';
        btn.style.cssText = 'position: absolute !important; right: 8px !important; top: 50% !important; transform: translateY(-50%) !important; background: none !important; border: none !important; font-size: 15px !important; cursor: pointer !important; padding: 0 !important; line-height: 1 !important; z-index: 20 !important;';

        function executeSearch(e) {
            if (e) {
                e.preventDefault();
                e.stopPropagation();
                e.stopImmediatePropagation();
            }
            var val = input.value.trim();
            if (val !== '') {
                window.location.href = '/wiki/Special:VaniSearch?search=' + encodeURIComponent(val);
            }
        }

        btn.addEventListener('click', executeSearch, true);

        // Capture phase event interception: Stops Minerva from ever knowing you clicked or typed
        ['click', 'focus', 'focusin', 'touchstart', 'input', 'keydown'].forEach(function(eventType) {
            input.addEventListener(eventType, function(e) {
                e.stopPropagation(); // Stops Minerva's listener from triggering
                if (eventType === 'keydown' && (e.key === 'Enter' || e.keyCode === 13)) {
                    executeSearch(e);
                }
            }, true); // true = Capture phase (runs before Minerva)
        });

        container.appendChild(input);
        container.appendChild(btn);

        // Insert right after the burger menu button
        var burger = header.querySelector('.navigation-drawer, #mw-mf-main-menu-button');
        if (burger && burger.nextSibling) {
            header.insertBefore(container, burger.nextSibling);
        } else {
            header.appendChild(container);
        }
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initVaniMobileSearch);
    } else {
        initVaniMobileSearch();
    }
    setTimeout(initVaniMobileSearch, 300);
    setTimeout(initVaniMobileSearch, 1000);
})();