利用者:Mr.sirokuma/サブサブサブページ

出典: 謎の百科事典もどき『エンペディア(Enpedia)』
ナビゲーションに移動 検索に移動

注意: 保存後、変更を確認するにはブラウザーのキャッシュを消去する必要がある場合があります。

  • Firefox / Safari: Shift を押しながら 再読み込み をクリックするか、Ctrl-F5 または Ctrl-R を押してください (Mac では ⌘-R)
  • Google Chrome: Ctrl-Shift-R を押してください (Mac では ⌘-Shift-R)
  • Microsoft Edge: Ctrl を押しながら 最新の情報に更新 をクリックするか、Ctrl-F5 を押してください。
/**
 * 個人メニューバーにカスタムリンクを追加
 */
$(function() {
    // 1. サブサブページへのリンク
    mw.util.addPortletLink(
        'p-personal',
        mw.util.getUrl('利用者:Mr.sirokuma/サブページ'),
        'サブサブページ',
        'pt-subsubpage',
        'サブページへ移動します',
        null,
        '#pt-preferences' // 個人設定の前に挿入
    );

    // 2. 作成したページへのリンク
    mw.util.addPortletLink(
        'p-personal',
        mw.util.getUrl('利用者:Mr.sirokuma/作成したページ'),
        '作成したページ',
        'pt-myworks',
        '作成したページ一覧へ移動します',
        null,
        '#pt-preferences' // 同じく個人設定の前に挿入
    );
});
/**
 * サイドバーに編集回数カウントバーを設置(動的ステップ版)
 */
(function() {
    const userName = mw.config.get('wgUserName');
    if (!userName) return;

    $.getJSON(mw.util.wikiScript('api'), {
        action: 'query',
        list: 'users',
        ususers: userName,
        usprop: 'editcount',
        format: 'json'
    }).done(function(data) {
        const editCount = data.query.users[0].editcount;
        let nextMilestone, prevMilestone;

        // 1000回までは100刻み、それ以降は1000刻みで計算
        if (editCount < 1000) {
            nextMilestone = (Math.floor(editCount / 100) + 1) * 100;
            prevMilestone = Math.floor(editCount / 100) * 100;
        } else {
            nextMilestone = (Math.floor(editCount / 1000) + 1) * 1000;
            prevMilestone = Math.floor(editCount / 1000) * 1000;
        }

        const remaining = nextMilestone - editCount;
        const progress = ((editCount - prevMilestone) / (nextMilestone - prevMilestone)) * 100;

        const html = `
            <nav id="p-edit-progress" class="mw-portlet vector-menu vector-menu-portal portal" style="margin-top: 1em; padding: 0 0.5em;">
                <h3 style="font-size: 0.75em; font-weight: bold; color: #54595d; margin-bottom: 8px;">次まであと ${remaining} 編集</h3>
                <div class="vector-menu-content">
                    <div style="background: #eaecf0; border-radius: 10px; height: 8px; width: 100%; overflow: hidden; border: 1px solid #c8ccd1;">
                        <div style="background: #36c; height: 100%; width: ${progress}%; transition: width 0.8s ease-in-out;"></div>
                    </div>
                    <div style="font-size: 0.7em; margin-top: 5px; color: #72777d; display: flex; justify-content: space-between;">
                        <span>現在: ${editCount}</span>
                        <span>目標: ${nextMilestone}</span>
                    </div>
                </div>
            </nav>
        `;

        // Vectorのサイドバー(複数の可能性を考慮)に挿入
        const $target = $('#mw-panel').find('.vector-menu').last();
        if ($target.length) {
            $target.after(html);
        } else {
            $('#mw-panel, #p-navigation').append(html);
        }
    });
})();
/**
 * サイドバー
 */
(function() {
    let deck = [], playerHand = [], dealerHand = [], gameOver = false;

    // カードの山を作成
    function createDeck() {
        const suits = ['♠', '♥', '♦', '♣'];
        const values = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
        deck = [];
        for (let s of suits) for (let v of values) deck.push({s, v});
        deck = deck.sort(() => Math.random() - 0.5);
    }

    // 点数計算
    function getScore(hand) {
        let score = 0, aces = 0;
        hand.forEach(c => {
            if (['J', 'Q', 'K'].includes(c.v)) score += 10;
            else if (c.v === 'A') { score += 11; aces++; }
            else score += parseInt(c.v);
        });
        while (score > 21 && aces > 0) { score -= 10; aces--; }
        return score;
    }

    const gameHtml = `
        <nav id="p-blackjack" class="mw-portlet vector-menu vector-menu-portal portal" style="margin-top: 1.5em; padding: 10px 5px; border-top: 1px solid #c8ccd1; background: #f8f9fa;">
            <h3 style="font-size: 0.8em; font-weight: bold; color: #54595d; margin-bottom: 5px;">ブラックジャック</h3>
            <div id="bj-area" style="font-size: 0.75em; line-height: 1.4;">
                <div id="bj-dealer">親: ?</div>
                <div id="bj-player" style="margin: 5px 0; font-weight: bold;">子: </div>
                <div id="bj-msg" style="color: #d33; font-weight: bold; min-height: 1.2em; margin-bottom: 5px;"></div>
                <div id="bj-controls">
                    <button id="bj-hit" style="padding: 2px 5px; cursor:pointer;">ヒット</button>
                    <button id="bj-stand" style="padding: 2px 5px; cursor:pointer;">スタンド</button>
                    <button id="bj-start" style="padding: 2px 10px; cursor:pointer; display:none; background:#36c; color:#fff; border:none; border-radius:2px;">再戦</button>
                </div>
            </div>
        </nav>
    `;

    // 挿入
    const $target = $('#p-edit-progress, #mw-panel .vector-menu').last();
    $target.length ? $target.after(gameHtml) : $('#mw-panel').append(gameHtml);

    function updateDisplay(hideDealer = true) {
        const dText = hideDealer ? `${dealerHand[0].s}${dealerHand[0].v} (+?)` : 
            dealerHand.map(c => c.s + c.v).join(' ') + ` (${getScore(dealerHand)})`;
        $('#bj-dealer').text('親: ' + dText);
        $('#bj-player').text('子: ' + playerHand.map(c => c.s + c.v).join(' ') + ` (${getScore(playerHand)})`);
    }

    function startGame() {
        createDeck();
        playerHand = [deck.pop(), deck.pop()];
        dealerHand = [deck.pop(), deck.pop()];
        gameOver = false;
        $('#bj-msg').text('');
        $('#bj-start').hide();
        $('#bj-hit, #bj-stand').show();
        updateDisplay(true);
        if (getScore(playerHand) === 21) finish('BJ! 勝利!');
    }

    function finish(msg) {
        gameOver = true;
        updateDisplay(false);
        $('#bj-msg').text(msg);
        $('#bj-hit, #bj-stand').hide();
        $('#bj-start').show().css('display', 'block');
    }

    $(document).on('click', '#bj-hit', function() {
        playerHand.push(deck.pop());
        updateDisplay(true);
        if (getScore(playerHand) > 21) finish('バースト!負け');
    });

    $(document).on('click', '#bj-stand', function() {
        while (getScore(dealerHand) < 17) dealerHand.push(deck.pop());
        const p = getScore(playerHand), d = getScore(dealerHand);
        if (d > 21) finish('親バースト!勝利');
        else if (p > d) finish('勝利!');
        else if (p < d) finish('敗北...');
        else finish('引き分け');
    });

    $(document).on('click', '#bj-start', startGame);

    // 初回起動
    startGame();
})();
/**
 * モバイルビューでもサイドバーを横に表示させるためのCSS注入
 */
(function() {
    // モバイルビュー(Minervaスキン等)かどうか判定
    if (mw.config.get('skin') === 'minerva' || window.innerWidth < 768) {
        const customStyle = `
            <style>
                /* メインコンテナをフレックスボックス化 */
                #mw-mf-viewport {
                    display: flex !important;
                    flex-direction: row !important;
                    overflow-x: auto !important;
                }
                /* コンテンツエリアを狭める */
                #mw-mf-page-center {
                    flex: 0 0 70% !important;
                    width: 70% !important;
                    margin: 0 !important;
                    transform: none !important;
                }
                /* サイドバー(メニュー)を右側に強制表示 */
                #mw-mf-page-left {
                    position: relative !important;
                    flex: 0 0 30% !important;
                    width: 30% !important;
                    left: 0 !important;
                    display: block !important;
                    background: #f8f9fa !important;
                    border-left: 1px solid #ddd !important;
                    visibility: visible !important;
                }
                /* ゲームやカウントバーのフォントサイズをさらに小さく */
                #p-edit-progress, #p-blackjack {
                    font-size: 0.6em !important;
                    padding: 5px 2px !important;
                }
                #bj-controls button {
                    padding: 1px 2px !important;
                    font-size: 0.8em !important;
                }
            </style>
        `;
        $('head').append(customStyle);
    }
})();