MediaWiki:Common.js

来自Mindustry中文wiki
绿豆留言 | 贡献2025年11月29日 (六) 19:53的版本

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:Ctrl-F5
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* 点击按钮复制内容的脚本 */
$(function() {
    $('.copy-button').click(function() {
        var text = $(this).attr('data-text');
        var $temp = $("<textarea>");
        $("body").append($temp);
        $temp.val(text).select();
        document.execCommand("copy");
        $temp.remove();
        alert("复制成功!");
    });
});
/* Mindustry 顶部导航栏 - 暴力插入版 */
$(document).ready(function() {
    // 1. 定义菜单内容 (直接写死白色字体,防止看不见)
    var myMenu = `
    <div id="mindustry-nav" style="display: flex; align-items: center; height: 100%; margin-left: 20px; z-index: 999;">
        <a href="/index.php/首页" style="color: #fff !important; font-weight: bold; font-size: 16px; margin-right: 20px; text-decoration: none;">首页</a>
        <a href="/index.php/单位" style="color: #fff !important; font-weight: bold; font-size: 16px; margin-right: 20px; text-decoration: none;">单位</a>
        <a href="/index.php/建筑" style="color: #fff !important; font-weight: bold; font-size: 16px; margin-right: 20px; text-decoration: none;">建筑</a>
        <a href="/index.php/逻辑" style="color: #fff !important; font-weight: bold; font-size: 16px; margin-right: 20px; text-decoration: none;">逻辑</a>
    </div>
    `;

    // 2. 尝试插入到 Logo 所在的容器中
    // Vector 2022 的 Logo 容器通常叫 .vector-header-start
    var target = $('.vector-header-start');
    
    // 如果找不到,尝试找 .mw-logo (旧版兼容)
    if (target.length === 0) {
        target = $('.mw-logo').parent();
    }

    // 执行插入
    target.append(myMenu);
    
    // 3. 调试信息 (按F12看控制台用)
    console.log("Mindustry 导航栏脚本已执行");
});