Jump to content

MediaWiki:Common.js

From International Treaty Law Wiki

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.
/* Any JavaScript here will be loaded for all users on every page load. */
/* Optimized Vector-2022 Utilities + Search Extensions + InfinityFree Failover */

$(function () {

    'use strict';

    /* =========================================================
       1. CLEAN PRINT CSS
    ========================================================= */

    var globalCss = `
    @media print {

        #mw-page-base,
        #mw-head-base,
        #mw-navigation,
        #mw-panel,
        #footer,
        .vector-header,
        .vector-page-toolbar,
        .vector-toc,
        .vector-sticky-header,
        .vector-page-tools,
        .vector-menu,
        .mw-indicators,
        .vector-user-links,
        .vector-search-box,
        .vector-pinned-container {
            display: none !important;
        }

        #content,
        .mw-body,
        .mw-content-container,
        .mw-body-content {
            margin: 0 !important;
            padding: 0 !important;
            width: 100% !important;
            max-width: none !important;
        }

        body,
        #content {
            background: white !important;
        }

        .mw-body-content {
            font-size: 14pt !important;
            line-height: 1.5 !important;
        }
    }

    /* =========================================================
       SEARCH COLLAPSE UI
    ========================================================= */

    #extra-search-results {
        margin-top: 2em;
        border-top: 1px solid #ddd;
        padding-top: 1em;
    }

    .search-collapse-section {
        margin-bottom: 1.5em;
        border: 1px solid #d8dee8;
        border-radius: 6px;
        overflow: hidden;
        background: #ffffff;
    }

    .search-collapse-header {
        background: #f3f6fb;
        padding: 12px 15px;
        cursor: pointer;
        font-weight: 600;
        transition: background .15s ease;
        user-select: none;
    }

    .search-collapse-header:hover {
        background: #e9eef7;
    }

    .search-collapse-header::before {
        content: "β–Ό ";
        display: inline-block;
        transition: transform .2s ease;
    }

    .search-collapse-header.collapsed::before {
        transform: rotate(-90deg);
    }

    .search-collapse-content {
        padding: 15px;
        display: block;
        background: #fff;
    }

    .search-collapse-content.collapsed {
        display: none;
    }

    .gcse-searchresults-only {
        min-height: 200px;
    }

    .search-engine-link {
        display: block;
        padding: 8px 0;
        font-size: 15px;
        border-bottom: 1px solid #f0f0f0;
    }

    .search-engine-link:last-child {
        border-bottom: none;
    }

    .search-engine-link a {
        text-decoration: none;
        color: #0645ad;
    }

    .search-engine-link a:hover {
        text-decoration: underline;
    }

    .pse-direct-link {
        margin-bottom: 15px;
        padding: 10px;
        background: #eef5ff;
        border-radius: 5px;
    }

    .pse-direct-link a {
        color: #005fcc;
        text-decoration: none;
        font-weight: 500;
    }

    .pse-direct-link a:hover {
        text-decoration: underline;
    }

    /* =========================================================
       FOOTER BLOCK
    ========================================================= */

    .mw-recommended-footer {
        margin-top: 30px;
        padding: 15px;
        border: 2px solid #3a6ea5;
        background: #eef4fb;
        border-radius: 6px;
        color: #1a1a1a;
        font-size: 14px;
        line-height: 1.5;
    }

    .mw-recommended-footer-title {
        font-size: 18px;
        font-weight: bold;
        color: #2a4d7a;
        margin-bottom: 10px;
    }

    .mw-recommended-footer-subtitle {
        font-size: 18px;
        font-weight: bold;
        color: #2a4d7a;
        margin: 20px 0 10px;
    }

    .mw-recommended-footer ul {
        margin-left: 15px;
    }

    .mw-recommended-footer a {
        word-break: break-word;
    }
    `;

    var styleEl = document.createElement('style');
    styleEl.type = 'text/css';
    styleEl.appendChild(document.createTextNode(globalCss));
    document.head.appendChild(styleEl);

    /* =========================================================
       2. VECTOR-2022 TOOLBAR
    ========================================================= */

    if (mw.config.get('wgNamespaceNumber') === 0) {

        var $actions = $('.vector-page-toolbar .vector-page-tools .vector-menu-content-list');

        if ($actions.length) {

            /* Remove old PDF buttons */

            $actions.find('li').filter(function () {

                var txt = ($(this).text() || '').toLowerCase();
                return txt.indexOf('pdf') !== -1;

            }).remove();

            /* Build toolbar in ONE prepend */

            var currentTitle = encodeURIComponent(document.title);

            var toolbarHtml = `
            <li class="vector-menu-content-list-item">
                <a href="#" class="mw-share-trigger" title="Share this page">
                    Share
                </a>
            </li>

            <li class="vector-menu-content-list-item">
                <a href="#" class="mw-print-trigger" title="Download clean PDF">
                    PDF
                </a>
            </li>

            <li class="vector-menu-content-list-item">
                <a href="https://cse.google.com/cse?cx=86021a982e3a14848&q=${currentTitle}"
                   target="_blank"
                   rel="noopener noreferrer"
                   title="Special Search">
                    Special Search
                </a>
            </li>

            <li class="vector-menu-content-list-item">
                <a href="https://github.com/MrAnonymousNWO/One_World/wiki/search?q=${currentTitle}"
                   target="_blank"
                   rel="noopener noreferrer"
                   title="One World Wiki">
                    One World Wiki
                </a>
            </li>

            <li class="vector-menu-content-list-item">
                <a href="https://github.com/ET-Pioneer/Electric-Technocracy-Pioneers-Community/wiki/search?q=${currentTitle}"
                   target="_blank"
                   rel="noopener noreferrer"
                   title="E.Tech. Wiki">
                    E.Tech. Wiki
                </a>
            </li>
            `;

            $actions.prepend(toolbarHtml);
        }
    }

    /* =========================================================
       3. GLOBAL EVENT DELEGATION
    ========================================================= */

    document.addEventListener('click', function (e) {

        /* PDF */

        if (e.target.matches('.mw-print-trigger')) {

            e.preventDefault();
            window.print();
        }

        /* Share */

        if (e.target.matches('.mw-share-trigger')) {

            e.preventDefault();

            if (navigator.share) {

                navigator.share({
                    title: document.title,
                    url: location.href
                });

            } else {

                prompt('Copy link:', location.href);
            }
        }

        /* Collapse Toggle */

        if (e.target.matches('.search-collapse-header')) {

            var targetId = e.target.getAttribute('data-target');
            var content = document.getElementById(targetId);

            e.target.classList.toggle('collapsed');

            if (content) {
                content.classList.toggle('collapsed');
            }
        }
    });

    /* =========================================================
       4. SEARCH PAGE EXTENSIONS
    ========================================================= */

    mw.loader.using('mediawiki.util', function () {

        if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') {
            return;
        }

        var query = mw.util.getParamValue('search');

        if (!query) {
            return;
        }

        var encodedQuery = encodeURIComponent(query);

        /* Insert position */

        var pagination = $('.mw-search-pager-bottom, .results-info').last();
        var insertPoint = pagination.length ? pagination : $('#mw-search-results');

        if (!insertPoint.length) {
            return;
        }

        /* Main container */

        var container = document.createElement('div');
        container.id = 'extra-search-results';

        /* =====================================================
           PSE SECTION
        ===================================================== */

        var pseSection = document.createElement('div');

        pseSection.className = 'search-collapse-section';

        var pseDirectUrl =
            'https://cse.google.com/cse?cx=86021a982e3a14848&q=' + encodedQuery;

        pseSection.innerHTML = `
        <div class="search-collapse-header"
             data-target="pse-content">
             Programmable Search Engine
        </div>

        <div class="search-collapse-content"
             id="pse-content">

            <div class="pse-direct-link">
                <a href="${pseDirectUrl}"
                   target="_blank"
                   rel="noopener noreferrer">
                    πŸ”— Open in Programmable Search Engine
                </a>
            </div>

            <div class="gcse-searchresults-only"
                 data-queryParameterName="gq">
            </div>

        </div>
        `;

        container.appendChild(pseSection);

        /* =====================================================
           GITHUB WIKIS
        ===================================================== */

        var githubSection = document.createElement('div');

        githubSection.className = 'search-collapse-section';

        githubSection.innerHTML = `
        <div class="search-collapse-header"
             data-target="github-wikis-content">
             GitHub Wikis
        </div>

        <div class="search-collapse-content"
             id="github-wikis-content">

            <div class="search-engine-link">
                <a href="https://github.com/ET-Pioneer/Electric-Technocracy-Pioneers-Community/wiki/search?q=${encodedQuery}"
                   target="_blank"
                   rel="noopener noreferrer">
                    πŸ“˜ Search in Electric Technocracy Pioneers GitHub Wiki
                </a>
            </div>

            <div class="search-engine-link">
                <a href="https://github.com/MrAnonymousNWO/One_World/wiki/search?q=${encodedQuery}"
                   target="_blank"
                   rel="noopener noreferrer">
                    πŸ“— Search in One World GitHub Wiki
                </a>
            </div>

        </div>
        `;

        container.appendChild(githubSection);

        /* =====================================================
           ALTERNATIVE SEARCH ENGINES
        ===================================================== */

        var searchEngines = [
            {
                name: 'Google',
                icon: 'πŸ”',
                url: 'https://www.google.com/search?q=' + encodedQuery
            },
            {
                name: 'Bing',
                icon: 'πŸ”Ž',
                url: 'https://www.bing.com/search?q=' + encodedQuery
            },
            {
                name: 'DuckDuckGo',
                icon: 'πŸ¦†',
                url: 'https://duckduckgo.com/?q=' + encodedQuery
            },
            {
                name: 'Yandex',
                icon: 'πŸ”',
                url: 'https://yandex.com/search/?text=' + encodedQuery
            },
            {
                name: 'Brave Search',
                icon: '🦁',
                url: 'https://search.brave.com/search?q=' + encodedQuery
            },
            {
                name: 'Ecosia',
                icon: '🌳',
                url: 'https://www.ecosia.org/search?q=' + encodedQuery
            }
        ];

        var searchLinksHtml = '';

        searchEngines.forEach(function (engine) {

            searchLinksHtml += `
            <div class="search-engine-link">
                <a href="${engine.url}"
                   target="_blank"
                   rel="noopener noreferrer">
                    ${engine.icon} Search on ${engine.name}
                </a>
            </div>
            `;
        });

        var searchSection = document.createElement('div');

        searchSection.className = 'search-collapse-section';

        searchSection.innerHTML = `
        <div class="search-collapse-header"
             data-target="search-engines-content">
             Alternative Search Engines
        </div>

        <div class="search-collapse-content"
             id="search-engines-content">
             ${searchLinksHtml}
        </div>
        `;

        container.appendChild(searchSection);

        /* =====================================================
           FOOTER BLOCK
        ===================================================== */

        var footerBlock = document.createElement('div');

        footerBlock.className = 'mw-recommended-footer';

        footerBlock.innerHTML = `
        <div class="mw-recommended-footer-title">
            Recommended GPT Tools by ChatGPT
        </div>

        <ul>

            <li>
                <b>World Succession Deed GPT</b> –
                unified global succession framework
                <br>

                <a href="https://chatgpt.com/g/g-69d82340e27081918e08803ce62e46e1-new-international-law-world-succession-deed-1400"
                   target="_blank"
                   rel="noopener noreferrer">
                   https://chatgpt.com/...world-succession-deed-1400
                </a>
            </li>

            <li>
                <b>Juridical Singularity GPT</b> –
                convergence of domestic & international law
                <br>

                <a href="https://chatgpt.com/g/g-69d95a89896081918fcb207e1665bf26-juridical-singularity-domestic-international-law"
                   target="_blank"
                   rel="noopener noreferrer">
                   https://chatgpt.com/...juridical-singularity
                </a>
            </li>

            <li>
                <b>Electric Technocracy GPT</b> –
                governance through infrastructure & automation
                <br>

                <a href="https://chatgpt.com/g/g-69d8635591d48191adc315b8f2b8be32-electric-technocracy-a-new-form-of-government"
                   target="_blank"
                   rel="noopener noreferrer">
                   https://chatgpt.com/...electric-technocracy
                </a>
            </li>

            <li>
                <b>AGE OF TRANSITION & THE MENTAL SINGULARITY GPT</b>
                <br>

                <a href="https://chatgpt.com/g/g-69d99f78d6a081919cd29d8d33531852-age-of-transition-the-mental-singularity"
                   target="_blank"
                   rel="noopener noreferrer">
                   https://chatgpt.com/...mental-singularity
                </a>
            </li>

        </ul>

        <div class="mw-recommended-footer-subtitle">
            Recommended External Resources
        </div>

        <ul>

            <li>
                🌐 <b>WSD – World Succession Deed 1400/98</b>
                <br>

                <a href="https://worldsold.wixsite.com/world-sold/en"
                   target="_blank"
                   rel="noopener noreferrer">
                   https://worldsold.wixsite.com/world-sold/en
                </a>
            </li>

            <li>
                🌐 <b>WSD – Global Legal Succession Archive</b>
                <br>

                <a href="https://worldsold.wixsite.com/global-archive"
                   target="_blank"
                   rel="noopener noreferrer">
                   https://worldsold.wixsite.com/global-archive
                </a>
            </li>

            <li>
                🌐 <b>Electric Technocracy</b>
                <br>

                <a href="https://worldsold.wixsite.com/electric-technocracy"
                   target="_blank"
                   rel="noopener noreferrer">
                   https://worldsold.wixsite.com/electric-technocracy
                </a>
            </li>

            <li>
                πŸ“˜ <b>Read the eBooks & Download free PDF</b>
                <br>

                <a href="https://4u.free.nf"
                   target="_blank"
                   rel="noopener noreferrer">
                   https://4u.free.nf
                </a>
            </li>

            <li>
                πŸŽ₯ <b>YouTube Channel</b>
                <br>

                <a href="https://www.youtube.com/@Staatensukzessionsurkunde-1400"
                   target="_blank"
                   rel="noopener noreferrer">
                   https://youtube.com/@Staatensukzessionsurkunde-1400
                </a>
            </li>

            <li>
                πŸŽ™οΈ <b>Podcast Show</b>
                <br>

                <a href="https://creators.spotify.com/pod/show/world-succession-deed"
                   target="_blank"
                   rel="noopener noreferrer">
                   https://spotify.com/...world-succession-deed
                </a>
            </li>

            <li>
                πŸš€ <b>Start-Page WSD & Electric Paradise</b>
                <br>

                <a href="https://electric-paradise.start.page"
                   target="_blank"
                   rel="noopener noreferrer">
                   https://electric-paradise.start.page
                </a>
            </li>

        </ul>
        `;

        container.appendChild(footerBlock);

        /* Insert container */

        if (pagination.length) {

            pagination.after(container);

        } else {

            insertPoint.after(container);
        }

        /* =====================================================
           GOOGLE CSE LAZY LOAD
        ===================================================== */

        function loadGoogleCSE() {

            if (window.googleCSELoaded) {
                return;
            }

            window.googleCSELoaded = true;

            window.__gcse = {

                parsetags: 'explicit',

                callback: function () {

                    var element =
                        document.querySelector('.gcse-searchresults-only');

                    if (!element) {
                        return;
                    }

                    google.search.cse.element.render({
                        div: element,
                        tag: 'searchresults-only',
                        gname: 'pse_search'
                    });

                    var searchControl =
                        google.search.cse.element.getElement('pse_search');

                    if (searchControl) {
                        searchControl.execute(query);
                    }
                }
            };

            var s = document.createElement('script');

            s.async = true;
            s.src =
                'https://cse.google.com/cse.js?cx=86021a982e3a14848';

            document.head.appendChild(s);
        }

        /* Lazy load when visible */

        if ('IntersectionObserver' in window) {

            var observer = new IntersectionObserver(function (entries) {

                if (entries[0].isIntersecting) {

                    loadGoogleCSE();
                    observer.disconnect();
                }

            }, {
                rootMargin: '300px'
            });

            observer.observe(container);

        } else {

            /* Fallback */

            setTimeout(loadGoogleCSE, 1000);
        }
    });

    /* =========================================================
       5. INFINITYFREE FAILOVER DETECTION
    ========================================================= */

    var bodyText = (
        document.body.innerText || ''
    ).toLowerCase();

    if (
        bodyText.includes('suspended') ||
        bodyText.includes('exceeding the free hosting limits')
    ) {

        window.location.href =
            'https://singularity-news.github.io/wiki/';
    }

});