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

No edit summary
testing
Line 2: Line 2:




/* Icon selector */
mw.hook('wikipage.content').add(function() {
(function () {
     const personal = document.querySelector(".vector-menu-content-list");
     'use strict';
    const test2 = document.createElement("li");
    const test3 = document.createElement("li");
    const test4 = document.createElement("li");
    test2.innerHTML = `<a href="/User:Kai/common.js">common.js</a>`;
    test3.innerHTML = `<a href="/Wiki_Redesign.css">wiki redesign.css</a>`;
    test4.innerHTML = `<a href="/User:Kai/common.css">common.css</a>`;


     var PREFERENCE_KEY = 'userjs-selectedicon';
     personal.prepend(test3, test2, test4);


     (function applyIconImmediately() {
     const toggleWidth = document.createElement("a");
        try {
    toggleWidth.classList.add("toggle-width");
            var cachedIcon = localStorage.getItem(PREFERENCE_KEY);
            if (cachedIcon) {
                document.body.className =
                    document.body.className.replace(/usericon-\w+/g, '');
                document.body.classList.add('usericon-' + cachedIcon);
            }
            document.body.classList.add('usericon-loaded');
        } catch (e) {}
    })();


     var availableIcons = [
     toggleWidth.addEventListener("click", function() {
        { id: 'abrams', name: 'Abrams' },
         document.body.classList.toggle("fixed-width-mode");
        { id: 'apollo', name: 'Apollo' },
         const isActive = document.body.classList.contains("fixed-width-mode");
        { id: 'bebop', name: 'Bebop' },
         localStorage.setItem("fixedWidth", isActive);
        { 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 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)];
    const widthCheck = localStorage.getItem("fixedWidth");
                mw.notify(msg, { type: 'success' });
    if (widthCheck === "true") {
 
        document.body.classList.add("fixed-width-mode");
                $('.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 () {
     personal.prepend(toggleWidth);
        var config = mw.config.get([
});
            'wgNamespaceNumber',
            'wgTitle',
            'wgUserName'
        ]);
 
        if (
            config.wgNamespaceNumber === 2 &&
            config.wgTitle === config.wgUserName &&
            config.wgUserName
        ) {
            createIconSelector();
        }
    });
 
})();


/**
/**