User:Monster Domosed/common.js: Difference between revisions

Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
mw.loader.load('https://deadlock.wiki/index.php?title=User:Monster_Domosed/Wiki_Redesign.js&action=raw&ctype=text/javascript');
/*mw.loader.load('https://deadlock.wiki/index.php?title=User:Monster_Domosed/Wiki_Redesign.js&action=raw&ctype=text/javascript');*/
 
 
/* Icon selector */
(function () {
    'use strict';
 
    var availableIcons = [
        { id: 'abrams', name: 'Abrams' },
        { id: 'apollo', name: 'Apollo' },
        { id: 'bebop', name: 'Bebop' },
        { id: 'billy', name: 'Billy' },
        { id: 'calico', name: 'Calico' },
        { id: 'celeste', name: 'Celeste' },
        { id: 'doorman', name: 'The Doorman' },
        { id: 'drifter', name: 'Drifter' },
        { id: 'dynamo', name: 'Dynamo' },
        { id: 'graves', name: 'Graves' },
        { id: 'grey-talon', name: 'Grey Talon' },
        { id: 'haze', name: 'Haze' },
        { id: 'holliday', name: 'Holliday' },
        { id: 'infernus', name: 'Infernus' },
        { id: 'ivy', name: 'Ivy' },
        { id: 'kelvin', name: 'Kelvin' },
        { id: 'lady-geist', name: 'Lady Geist' },
        { id: 'lash', name: 'Lash' },
        { id: 'mcginnis', name: 'McGinnis' },
        { id: 'mina', name: 'Mina' },
        { id: 'mirage', name: 'Mirage' },
        { id: 'mo-krill', name: 'Mo & Krill' },
        { id: 'paige', name: 'Paige' },
        { id: 'paradox', name: 'Paradox' },
        { id: 'pocket', name: 'Pocket' },
        { id: 'rem', name: 'Rem' },
        { id: 'seven', name: 'Seven' },
        { id: 'shiv', name: 'Shiv' },
        { id: 'silver', name: 'Silver' },
        { id: 'sinclair', name: 'Sinclair' },
        { id: 'venator', name: 'Venator' },
        { id: 'victor', name: 'Victor' },
        { id: 'vindicta', name: 'Vindicta' },
        { id: 'viscous', name: 'Viscous' },
        { id: 'vyper', name: 'Vyper' },
        { id: 'warden', name: 'Warden' },
        { id: 'wraith', name: 'Wraith' },
        { id: 'yamato', name: 'Yamato' }
    ];
 
    var PREFERENCE_KEY = 'userjs-selectedicon';
 
    var remClickCount = 0;
    var remClickTimer = null;
 
    var isInfected = false;
    var infectionInterval = null;
 
    var buddyMessages = [
        "I got little buddies.",
        "They cute.",
        "They love.",
        "They help.",
        "They great at shuffleboard.",
        "They do lots of things!",
        "Hi friends!",
        "Come help!",
        "I know you'll help me."
    ];
 
    var helperSounds = [
        'Familiar helper emote 01.mp3',
        'Familiar helper emote 02.mp3',
        'Familiar helper emote 03.mp3',
        'Familiar helper emote 04.mp3',
        'Familiar helper emote 05.mp3',
        'Familiar helper emote 06.mp3',
        'Familiar helper emote 07.mp3',
        'Familiar helper emote 08.mp3',
        'Familiar helper emote 09.mp3',
        'Familiar helper emote 10.mp3',
        'Familiar helper emote 11.mp3',
        'Familiar helper emote 12.mp3',
        'Familiar helper emote 13.mp3',
        'Familiar helper emote 14.mp3',
        'Familiar helper emote 15.mp3',
        'Familiar helper emote 16.mp3'
    ];
 
    function getFilePath(filename) {
        return mw.util.getUrl('Special:FilePath/' + filename);
    }
 
    function playHelperSound() {
        var file = helperSounds[Math.floor(Math.random() * helperSounds.length)];
        var audio = new Audio(getFilePath(file));
        audio.volume = 0.1;
        audio.play().catch(function () {});
    }
 
    function getCachedIcon() {
        return localStorage.getItem(PREFERENCE_KEY);
    }
 
    function setCachedIcon(iconId) {
        localStorage.setItem(PREFERENCE_KEY, iconId);
    }
 
    function applyIcon(iconId) {
        document.body.className =
            document.body.className.replace(/usericon-\w+/g, '');
        document.body.classList.add('usericon-' + iconId);
    }
 
    function selectIcon(iconId, force) {
        var currentIcon = getCachedIcon() || 'rem';
 
        if (!force && currentIcon === iconId) {
            return;
        }
 
        setCachedIcon(iconId);
        applyIcon(iconId);
 
        mw.loader.using(['mediawiki.api'], function () {
            var api = new mw.Api();
 
            api.saveOption(PREFERENCE_KEY, iconId)
                .done(function () {
                    if (iconId !== 'rem-helper') {
                        mw.notify('Icon updated successfully!', {
                            type: 'success'
                        });
                    }
                })
                .fail(function () {
                    mw.notify('Failed to save icon.', {
                        type: 'error'
                    });
                });
        });
    }
 
    function infectIcon($el) {
        $el.attr('data-icon', 'rem-helper');
        $el.find('img').attr('src', getFilePath('Rem_helper.png'));
        $el.find('span').text('Rem Helper');
        $el.addClass('infected');
 
 
        if (getCachedIcon() === 'rem-helper') {
            $('.usericon-option').removeClass('selected');
            $el.addClass('selected');
        }
    }
 
    function startInfection() {
        if (isInfected) return;
 
        isInfected = true;
 
        var msg = buddyMessages[Math.floor(Math.random() * buddyMessages.length)];
        mw.notify(msg, { type: 'success' });
 
        playHelperSound();
 
        var $icons = $('.usericon-option');
        var remaining = $icons.toArray();
 
        infectionInterval = setInterval(function () {
            if (remaining.length === 0) {
                clearInterval(infectionInterval);
                return;
            }
 
            var count = Math.ceil(Math.random() * 3);
 
            for (var i = 0; i < count && remaining.length > 0; i++) {
                var index = Math.floor(Math.random() * remaining.length);
                var el = remaining.splice(index, 1)[0];
                infectIcon($(el));
            }
        }, 400);
    }
 
    function createIconSelector() {
        var currentIcon = getCachedIcon() || 'rem';
 
        var html = '<div id="usericon-selector">' +
            '<h3>Choose Your Profile Icon</h3>' +
            '<div class="usericon-grid">';
 
        availableIcons.forEach(function (icon) {
            var selected = icon.id === currentIcon ? ' selected' : '';
            var imgSrc = getFilePath(icon.name + '.png');
 
            html += '<div class="usericon-option' + selected + '" data-icon="' + icon.id + '">' +
                '<img src="' + imgSrc + '">' +
                '<span>' + icon.name + '</span>' +
                '</div>';
        });
 
        html += '</div></div>';
 
        var $selector = $(html);
        $('#mw-content-text').prepend($selector);
 
        $('.usericon-option').on('click', function () {
            var iconId = $(this).data('icon');
 
            if (isInfected) {
                iconId = 'rem-helper';
 
                var msg = buddyMessages[Math.floor(Math.random() * buddyMessages.length)];
                mw.notify(msg, { type: 'success' });
 
                $('.usericon-option').removeClass('selected');
                $(this).addClass('selected');
 
                selectIcon(iconId, true);
                return;
            }
 
            if (iconId === 'rem') {
                remClickCount++;
 
                clearTimeout(remClickTimer);
                remClickTimer = setTimeout(function () {
                    remClickCount = 0;
                }, 1500);
 
                if (remClickCount >= 5) {
                    remClickCount = 0;
                    startInfection();
                    return;
                }
            } else {
                remClickCount = 0;
            }
 
            $('.usericon-option').removeClass('selected');
            $(this).addClass('selected');
 
            selectIcon(iconId);
        });
    }
 
    mw.loader.using(['mediawiki.util'], function () {
        applyIcon(getCachedIcon() || 'rem');
 
        var config = mw.config.get([
            'wgNamespaceNumber',
            'wgTitle',
            'wgUserName'
        ]);
 
        if (
            config.wgNamespaceNumber === 2 &&
            config.wgTitle === config.wgUserName &&
            config.wgUserName
        ) {
            createIconSelector();
        }
    });
 
})();
 


/**
/**