Anonymous

MediaWiki:Common.js: Difference between revisions

From Elwiki
no edit summary
No edit summary
No edit summary
 
(93 intermediate revisions by 2 users not shown)
Line 1: Line 1:
function matchHeaderText() {
    $('table[cellpadding="5"][border="1"][style] tr[style]:not(.dungeon-page-fields tr), table[cellpadding="5"][border="1"][style] tr[class]:not(.dungeon-page-fields tr), .instance-page .segment-header, .auto-header-color .segment-header, .alt-langs th, .updates-table th, table[cellpadding="5"][border="1"][class*="colortable-"] th, .auto-text-color .segment-header').each(function () {
        var rgb = $(this).css('backgroundColor');
        var colors = rgb.match(/\d+/g);
        var o = Math.round(((parseInt(colors[0]) * 299) + (parseInt(colors[1]) * 587) + (parseInt(colors[2]) * 114)) / 1000);
        if ($(this).parents('.section-characters').length) return;
        if (o < 155 && rgb != 'rgba(0, 0, 0, 0)') {
            $(this).addClass('force-white');
        } else if (!$(this).is('tr')) {
            $(this).addClass('force-black');
        }
    });
    setTimeout(function () {
        $('.segment-partial .mw-collapsible-text, .segment .mw-collapsible-text').each(function () {
            var matched_white = $(this).parents('.segment').find('.segment-header:eq(0)').hasClass('force-white');
            var matched_black = $(this).parents('.segment').find('.segment-header:eq(0)').hasClass('force-black');
            if (matched_white) {
                $(this).addClass('force-white')
            } else if (matched_black) {
                $(this).addClass('force-black')
            }
        });
    }, 50);
}
var loadJS = function (url, implementationCode, location) {
    var scriptTag = document.createElement('script');
    scriptTag.src = url;
    scriptTag.onload = implementationCode;
    scriptTag.onreadystatechange = implementationCode;
    location.appendChild(scriptTag);
};
var popperLoaded = function () {
    var tippyLoaded = function () {
        tippy('.tippy-btn', {
            interactive: true,
            allowHTML: true,
            appendTo: document.body,
            delay: 200
        });
        document.body.classList.add('tippy-loaded');
    };
    loadJS('https://elwiki.net/wiki/index.php?title=MediaWiki:Tippy.js&action=raw&ctype=text/javascript', tippyLoaded, document.body);
}
function enhancements() {
    $('.infobox .tabs-tabbox').before('<div class="tabs-background"></div>');
    $('dfn').parents('p').remove();
    $('.sidebar-chunk #nav > ul > li:has(".mw-selflink")').find('> a').addClass('mw-has-selflink');
    if (window.location.pathname == '/w/Special:RecentChanges') $('#mw-site-navigation .sidebar-chunk a[href="/w/Special:RecentChanges"]').addClass('mw-has-selflink');
    $('#p-banner').html("<span><span class='main-accent'>El</span>wiki</span>");
    $('.region-map img[alt="About this image"]').attr('src', 'https://elwiki.net/wiki/images/1/1f/UI_-_Help.png').show();
    $('table[cellpadding="5"][border="1"][style] tr[style*="rgb(68, 68, 68)"] th').css('border-color', 'black');
    matchHeaderText();
    $('.skill-nav-skill:has(.mw-selflink)').addClass('self-skill');
    $("#ca-ve-edit").clone().attr('id', 'ca-ve-edit-clone').prependTo($('#p-views .mw-portlet-body ul'));
    $("#ca-ve-edit").hide();
    var rows_to_highlight = [
        'Normal',
        '[Enhanced]',
        'PvE',
        'PvP'
    ]
    rows_to_highlight.forEach(function (rowContent) {
        var rows = $('[class^="colortable-"] td b:contains("' + rowContent + '")');
        rows.each(function () {
            const textContent = $(this).parents('td')[0].textContent.trim();
            if (textContent == rowContent) $(this).parent().addClass('tone-4');
        })
    })
    loadJS('https://unpkg.com/@popperjs/core@2.11.6/dist/umd/popper.min.js', popperLoaded, document.body);
    $('.related-skills td[width="150"]').each(function () {
        if (!$(this).find('.skill-wrap').length) {
            $(this).wrapInner('<div class="skill-wrap-text"></div>');
            $(this).wrapInner('<div class="skill-wrap"></div>');
        }
    });
    $('.related-skills:not(.no-div):not(.skill-table)').each(function () {
        var limit = $(this).attr('width');
        var limitString = '';
        if (limit !== undefined) limitString = " data-limit='" + limit + "'";
        $(this).replaceWith($(this).html()
            .replace(/<tbody/gi, "<div class='" + $(this).attr('class') + "'" + limitString)
            .replace(/<tr/gi, "<div data-type='table-row'")
            .replace(/<\/tr>/gi, "</div>")
            .replace(/<td/gi, "<div data-type='table-cell'")
            .replace(/<\/td>/gi, "</div>")
            .replace(/<th/gi, "<div data-type='table-head'")
            .replace(/<\/th>/gi, "</div>")
            .replace(/<\/tbody/gi, "<\/div")
        );
    });
    $('.skill-wrap:not(.no-div .skill-wrap, .skill-table .skill-wrap)').each(function () {
        var link = $(this).find('> .skill-wrap-text a:not(.image)').attr('href');
        $(this).wrap('<a href="' + link + '">');
    });
    $('.related-skills.no-div td[width="150"]').click(function () {
        $(this).find('.skill-wrap > .skill-wrap-text a:not(.image)').get(0).click();
    });
    function chunk(arr, len) {
        var chunks = [],
            i = 0,
            n = arr.length;
        while (i < n) {
            chunks.push(arr.slice(i, i += len));
        }
        return chunks;
    }
    $('.related-skills:not(.skill-table)').each(function () {
        var cell = $(this).find('[data-type="table-cell"]');
        var limit = $(this).attr('data-limit');
        if (limit !== undefined && limit != '' && !isNaN(limit)) limit = parseInt(limit) * 2;
        else limit = 8;
        var attempt = false;
        $(this).find('[data-type="table-row"]').each(function () {
            if ($(this).find('[data-type="table-cell"]').length > limit) attempt = true;
        });
        if (attempt) {
            var overflow_elems = chunk(cell, limit);
            $(this).empty();
            for (var i = 0; i < overflow_elems.length; i++) {
                $(this).append('<div data-type="table-row">');
                $(this).find('[data-type="table-row"]:last').append(overflow_elems[i]);
            }
        }
    });
    $('.related-skills:not(.no-div):not(.skill-table)').addClass('shown');
    $('.boss-timer-section .tabber-tab').click(function (e) {
        if (e.screenX && e.screenX != 0 && e.screenY && e.screenY != 0) {
            setCookie('current-server-timer', $(this).text());
        }
    });
    $('.henir-stage .inner').click(function (e) {
        e.preventDefault();
        var link = $(this).find('a:not(.tippy-content a)').attr('href');
        //window.location.href = window.location.origin + link;
        window.open(window.location.origin + link)
    });
    setTimeout(function () { $('.current-info .segment-contents > .mw-collapsible-content').addClass('shown') }, 100);
    if (typeof character_banner_exists !== undefined) mw.loader.load('https://elwiki.net/wiki/index.php?title=MediaWiki:Character-Banner.js&action=raw&ctype=text/javascript');
    if ($('.boss-timer').length) {
        mw.loader.load('https://elwiki.net/wiki/index.php?title=MediaWiki:BossTimer.js&action=raw&ctype=text/javascript');
    }
    if ($('.server-time-wrap').length) {
        mw.loader.load('https://elwiki.net/wiki/index.php?title=MediaWiki:ServerTime.js&action=raw&ctype=text/javascript');
    }
    $('.dungeon-map .region-map').prepend('<div class="tabber-list-toggle"><img src="https://elwiki.net/wiki/images/7/7c/UI_-_Toggle.png"/></div>');
    $('.tabber-list-toggle img').click(function () {
        $('.tabber-list-toggle img').toggleClass('back');
        $('.dungeon-map .tabber-vertical .tabber-ul').toggleClass('list-hidden');
    });
    $('body').append('<div id="dark-mode-switch"></div>')
    $('#dark-mode-switch').click(function () {
        setCookie('not-new', true);
        if ($('body').hasClass('dark-mode')) {
            setCookie('elwiki-dark-mode', 'false');
        } else {
            setCookie('elwiki-dark-mode', 'true');
        }
        setTimeout(function () {
            window.location.reload(1);
        }, 50)
    });
    if (getCookie('elwiki-dark-mode') == 'true') $('body').addClass('dark-mode');
    if (getCookie('not-new') == null) $('#dark-mode-switch').addClass('new');
    // This is pretty cringe, tabs don't load sometimes
    if (!$('.tabber-new.loaded').length) mw.loader.load('https://elwiki.net/wiki/index.php?title=MediaWiki:Gadget-Tabs.js&action=raw&ctype=text/javascript')
}
$(function () {
    doRoundEdges();
    performIE();
    enhancements();
    // Fix the preview button losing custom script output
    // This is a complete ChatGPT moment, I couldn't be arsed to debug on my own
    $(document).on('DOMNodeInserted', function (event) {
        var element = event.target;
        if ($(element).hasClass('previewnote')) {
            var previewLoaded = $(element).find('.previewloading').length == 0;
            if (previewLoaded && !$(element).hasClass('custom-preview-run')) {
                $(element).addClass('custom-preview-run');
                enhancements();
            }
        }
    });
});
if ($('.skin-minerva').length) {
    var time_loading = 0;
    var chkReadyState = setInterval(function () {
        if (document.readyState == "complete" || time_loading > 3000) {
            // clear the interval
            clearInterval(chkReadyState);
            $('#loading-screen').css({ transition: '300ms', pointerEvents: 'none', opacity: 0 });
        }
        time_loading += 100;
    }, 100);
}
function docReady(fn) {
function docReady(fn) {
     // see if DOM is already available
     // see if DOM is already available
Line 232: Line 457:
     Rounded("div#nifty", "all", "#FFF", "#D4DDFF", "smooth");
     Rounded("div#nifty", "all", "#FFF", "#D4DDFF", "smooth");
}
}


/* IE Correction Code **********************************************
/* IE Correction Code **********************************************
Line 284: Line 500:
     }
     }
}
}
//Fix height issue with ads
var HeightFix = $("#mw-content-block");
//$("#mw-related-navigation").css("min-height", HeightFix.height());
$("#mw-related-navigation").attr("style", "max-height: " + HeightFix.height() + "px !important");
//$("#mw-related-navigation").attr("style", "height: 100% !important");


//Get Ad Dart Number
//Get Ad Dart Number
Line 293: Line 515:
genSetRandDARTNumber();
genSetRandDARTNumber();


function matchHeaderText(force) {
// Fix scripts literally disappearing when clicking "save changes" in VE
    $('table[cellpadding="5"][border="1"][style] tr[style]:not(.dungeon-page-fields tr), .segment-header:not(.job-change-collapsible .segment-header, .auto-coloring-off .segment-header)').each(function () {
mw.hook('ve.activationComplete').add(function () {
        var rgb = $(this).css('backgroundColor');
     var originalSaveComplete = ve.init.mw.ArticleTarget.prototype.saveComplete;
        var colors = rgb.match(/\d+/g);
     ve.init.mw.ArticleTarget.prototype.saveComplete = function (data) {
        var o = Math.round(((parseInt(colors[0]) * 299) + (parseInt(colors[1]) * 587) + (parseInt(colors[2]) * 114)) / 1000);
         // Calling the original implementation first
        if ($(this).parents('.section-characters').length) return;
         originalSaveComplete.call(this, data);
        if (o < 155 && rgb != 'rgba(0, 0, 0, 0)') {
         // Custom things
            $(this).addClass('force-white'); //css('color', 'white').css('text-shadow', '1px 1px 1px #000');
         doRoundEdges();
        } else if ($(this).parents('.instance-page').length || $(this).parents('.auto-header-color').length || force) {
         enhancements();
            $(this).addClass('force-black'); //.css('color', 'black').css('text-shadow', 'none');
        }
    });
    setTimeout(function () {
        $('.segment-partial .mw-collapsible-text, .segment .mw-collapsible-text').each(function () {
            var color = $(this).parents('.segment').find('.segment-header:eq(0)').css('color');
            var shadow = $(this).parents('.segment').find('.segment-header:eq(0)').css('text-shadow');
            $(this).css({ color: color, textShadow: shadow })
        });
    }, 50);
}
 
$(function () {
     doRoundEdges();
    performIE();
    $('.infobox .tabs-tabbox').before('<div class="tabs-background"></div>');
    $('dfn').parents('p').remove();
    $('.sidebar-chunk #nav > ul > li:has(".mw-selflink")').find('> a').addClass('mw-has-selflink');
    if (window.location.pathname == '/w/Special:RecentChanges') $('#mw-site-navigation .sidebar-chunk a[href="/w/Special:RecentChanges"]').addClass('mw-has-selflink');
    $('#p-banner').html("<span><span class='main-accent'>El</span>wiki</span>");
    $('.region-map img[alt="About this image"]').attr('src', 'https://elwiki.net/wiki/images/1/1f/UI_-_Help.png').show();
    $('table[cellpadding="5"][border="1"][style] tr[style*="rgb(68, 68, 68)"] th').css('border-color', 'black');
 
    matchHeaderText();
     $('.skill-nav-skill:has(.mw-selflink)').addClass('self-skill');
 
});
 
docReady(function () {
 
    $('.related-skills td[width="150"]').each(function () {
        if (!$(this).find('.skill-wrap').length) {
            $(this).wrapInner('<div class="skill-wrap-text"></div>');
            $(this).wrapInner('<div class="skill-wrap"></div>');
        }
    });
 
    $('.related-skills:not(.no-div)').each(function () {
         var limit = $(this).attr('width');
        var limitString = '';
        if (limit !== undefined) limitString = " data-limit='" + limit + "'";
        $(this).replaceWith($(this).html()
            .replace(/<tbody/gi, "<div class='" + $(this).attr('class') + "'" + limitString)
            .replace(/<tr/gi, "<div data-type='table-row'")
            .replace(/<\/tr>/gi, "</div>")
            .replace(/<td/gi, "<div data-type='table-cell'")
            .replace(/<\/td>/gi, "</div>")
            .replace(/<th/gi, "<div data-type='table-head'")
            .replace(/<\/th>/gi, "</div>")
            .replace(/<\/tbody/gi, "<\/div")
        );
    });
 
    $('.skill-wrap:not(.no-div .skill-wrap)').each(function () {
        var link = $(this).find('> .skill-wrap-text a:not(.image)').attr('href');
        $(this).wrap('<a href="' + link + '">');
    });
 
    $('.related-skills.no-div td[width="150"]').click(function () {
        $(this).find('.skill-wrap > .skill-wrap-text a:not(.image)').get(0).click();
    });
 
    function chunk(arr, len) {
        var chunks = [],
            i = 0,
            n = arr.length;
        while (i < n) {
            chunks.push(arr.slice(i, i += len));
        }
        return chunks;
    }
 
 
    $('.related-skills').each(function () {
        var cell = $(this).find('[data-type="table-cell"]');
        var limit = $(this).attr('data-limit');
        if (limit !== undefined && limit != '' && !isNaN(limit)) limit = parseInt(limit) * 2;
        else limit = 8;
        var attempt = false;
         $(this).find('[data-type="table-row"]').each(function () {
            if ($(this).find('[data-type="table-cell"]').length > limit) attempt = true;
        });
        if (attempt) {
            var overflow_elems = chunk(cell, limit);
            $(this).empty();
            for (var i = 0; i < overflow_elems.length; i++) {
                $(this).append('<div data-type="table-row">');
                $(this).find('[data-type="table-row"]:last').append(overflow_elems[i]);
            }
        }
    });
 
    $('.related-skills:not(.no-div)').addClass('shown');
 
 
    $('.boss-timer-section .tabber-tab').click(function (e) {
        if (e.screenX && e.screenX != 0 && e.screenY && e.screenY != 0) {
            setCookie('current-server-timer', $(this).text());
        }
    });
 
    $('.henir-stage').click(function (e) {
        e.preventDefault();
        var link = $(this).find('a').attr('href');
         //window.location.href = window.location.origin + link;
         window.open(window.location.origin + link)
    });
 
    setTimeout(function () { $('.current-info .segment-contents > .mw-collapsible-content').addClass('shown') }, 100);
 
    if (typeof character_banner_exists !== undefined) mw.loader.load('https://elwiki.net/wiki/index.php?title=MediaWiki:Character-Banner.js&action=raw&ctype=text/javascript');
 
    if ($('.boss-timer').length) {
         mw.loader.load('https://elwiki.net/wiki/index.php?title=MediaWiki:BossTimer.js&action=raw&ctype=text/javascript');
     }
     }
    $('.dungeon-map .region-map').prepend('<div class="tabber-list-toggle"><img src="https://elwiki.net/wiki/images/7/7c/UI_-_Toggle.png"/></div>');
    $('.tabber-list-toggle img').click(function () {
        $('.tabber-list-toggle img').toggleClass('back');
        $('.dungeon-map .tabber-vertical .tabber-ul').toggleClass('list-hidden');
    });
    $('body').append('<div id="dark-mode-switch"></div>')
    $('#dark-mode-switch').click(function () {
        setCookie('not-new', true);
        if ($('body').hasClass('dark-mode')) {
            setCookie('elwiki-dark-mode', 'false');
        } else {
            setCookie('elwiki-dark-mode', 'true');
        }
        setTimeout(function(){
            window.location.reload(1);
        }, 50)
    });
    if (getCookie('elwiki-dark-mode') == 'true') $('body').addClass('dark-mode');
    if (getCookie('not-new') == null) $('#dark-mode-switch').addClass('new');
});
});
if ($('.skin-minerva').length) {
    var time_loading = 0;
    var chkReadyState = setInterval(function () {
        if (document.readyState == "complete" || time_loading > 3000) {
            // clear the interval
            clearInterval(chkReadyState);
            $('#loading-screen').css({ transition: '300ms', pointerEvents: 'none', opacity: 0 });
        }
        time_loading += 100;
    }, 100);
}
25,204

edits