MediaWiki:Common.js:修订间差异

(创建页面,内容为“→‎这里的任何JavaScript将为所有用户在每次页面加载时加载。:​ (function($, mw) { "use strict"; →‎使用了 ding.js 来显示提示,位于[[MediaWiki:Gadget-ding.js]],作者为[[User:Bluedeck]]:​ // 只在浏览页面时显示 if (mw.config.get('wgAction') !== 'view') return; var ding = window.bldkDingExposedInterface; // Cookie 处理函数 function setCookie(name, value, days) { var expires = "…”
 
无编辑摘要
第2行: 第2行:
(function($, mw) {
(function($, mw) {
    "use strict";
    "use strict";
   /* 使用了 ding.js 来显示提示,位于[[MediaWiki:Gadget-ding.js]],作者为[[User:Bluedeck]] */


    // 只在浏览页面时显示
    // 只在浏览页面时显示
    if (mw.config.get('wgAction') !== 'view') return;
    if (mw.config.get('wgAction') !== 'view') return;
   var ding = window.bldkDingExposedInterface;


    // Cookie 处理函数
    // Cookie 处理函数
第30行: 第26行:
      }
      }
      return null;
      return null;
   }
   // 自定义通知函数(替代 ding.js)
   function showNotification(message, type, ttl) {
     // 插入通知样式
     if (!document.getElementById('hoi4_notification_styles')) {
       document.body.insertAdjacentHTML('afterbegin', `
         <style id="hoi4_notification_styles">
           .hoi4-notification {
             position: fixed;
             bottom: 0;
             left: 0;
             right: 0;
             margin: 0;
             padding: 0.6em 2em;
             line-height: 1.4em;
             text-align: center;
             z-index: 10001;
             font-size: 86%;
             font-weight: bold;
             transform: translateY(100%);
             transition: all 0.3s ease-in-out;
             opacity: 1;
             box-shadow: 0 -2px 5px rgba(0,0,0,0.2);
           }
           .hoi4-notification.success {
             background: rgba(0, 175, 137, 0.9);
             color: white;
           }
           .hoi4-notification.warning {
             background: rgba(221, 51, 51, 0.9);
             color: white;
           }
         </style>
       `);
     }
     // 创建通知元素
     var notificationId = 'hoi4_notification_' + Date.now();
     document.body.insertAdjacentHTML('beforeend', `
       <div id="${notificationId}" class="hoi4-notification ${type}">
         ${message}
       </div>
     `);
     var notification = document.getElementById(notificationId);
     // 显示动画
     setTimeout(function() {
       notification.style.transform = 'translateY(0%)';
     }, 10);
     // 自动消失
     if (ttl) {
       setTimeout(function() {
         notification.style.transform = 'translateY(100%)';
         setTimeout(function() {
           notification.remove();
         }, 300);
       }, ttl);
     }
    }
    }


第36行: 第92行:
      return; // 用户已同意,不显示弹窗
      return; // 用户已同意,不显示弹窗
    }
    }
   // 模糊页面内容
   document.body.style.filter = 'blur(5px)';
   document.body.style.transition = 'filter 0.3s ease';


    // 创建全屏弹窗
    // 创建全屏弹窗
    var popupHtml = `
    var popupHtml = `
      <div id="hoi4_legal_popup" style="
      <div id="hoi4_legal_popup" style="
        position: fixed; top: 0; left: 0; right: 0; bottom: 0;
        position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
        background: rgba(0, 0, 0, 0.8); z-index: 10000;
        background: rgba(0, 0, 0, 0.8); z-index: 10000;
        display: flex; justify-content: center; align-items: center;
        display: flex; justify-content: center; align-items: center;
第46行: 第106行:
        <div style="
        <div style="
          background: #333; padding: 20px; border-radius: 10px;
          background: #333; padding: 20px; border-radius: 10px;
          max-width: 600px; text-align: center;">
          max-width: 600px; text-align: center; box-shadow: 0 0 10px rgba(0,0,0,0.5);">
          <h2>法律声明</h2>
          <h2>法律声明</h2>
          <p>欢迎体验《钢铁雄心 IV》(Hearts of Iron IV)相关内容。本游戏涉及历史题材,在使用时需遵守相关法律法规。请确认您同意以下条款:</p>
          <p>欢迎体验《钢铁雄心 IV》(Hearts of Iron IV)相关内容。本游戏涉及历史题材,在使用时需遵守相关法律法规。请确认您同意以下条款:</p>
          <ul style="text-align: left;">
          <ul style="text-align: left; margin: 1em 0;">
            <li>不得分享或传播 游戏 内容至 未经授权的 平台。</li>
            <li> 本站内容 不得分享或传播 本站任何未经审核的 内容至 任何 平台。</li>
            <li> 不得恶意编辑或歪曲游戏 中的 历史内容 。</li>
            <li> 严禁在本站上传违反 华人民共和国法律 相关项目及文本 。</li>
            <li> 遵守相关法律法规 确保合法使用 。</li>
            <li> 因MediaWiki的特殊性,本站部分内容未经审核 请自行决定是否阅读 。</li>
          </ul>
          </ul>
          <p>若您同意,请点击“同意”继续访问;若不同意,将无法访问本页面。</p>
          <p>若您同意,请点击“同意”继续访问;若不同意,将无法访问本页面。</p>
          <button id="hoi4_agree" style="margin: 10px; padding: 10px 20px; background: #0a0; border: none; color: white; cursor: pointer;">同意</button>
          <div style="margin-top: 20px;">
         <button id="hoi4_disagree" style="margin: 10px; padding: 10px 20px; background: #a00; border: none; color: white; cursor: pointer;">不同意</button>
           <button id="hoi4_agree" style="
             margin: 10px; padding: 10px 20px; background: #0a0;
             border: none; color: white; cursor: pointer; border-radius: 5px;
             font-size: 16px; transition: background 0.2s;">
             同意
           </button>
           <button id="hoi4_disagree" style="
             margin: 10px; padding: 10px 20px; background: #a00;
             border: none; color: white; cursor: pointer; border-radius: 5px;
             font-size: 16px; transition: background 0.2s;">
             不同意
           </button>
         </div>
        </div>
        </div>
      </div>
      </div>
第68行: 第140行:
      setCookie('hoi4_legal_agreed', 'true', 365); // 保存同意状态,1年有效
      setCookie('hoi4_legal_agreed', 'true', 365); // 保存同意状态,1年有效
      $('#hoi4_legal_popup').remove(); // 移除弹窗
      $('#hoi4_legal_popup').remove(); // 移除弹窗
      ding('感谢您的配合!您已同意遵守相关法律条款。', 'success', 3000); // 显示成功通知
      document.body.style.filter = 'none'; // 取消模糊
     showNotification('感谢您的配合!您已同意遵守相关法律条款。', 'success', 3000); // 显示成功通知
    });
    });


第74行: 第147行:
    $('#hoi4_disagree').on('click', function() {
    $('#hoi4_disagree').on('click', function() {
      $('#hoi4_legal_popup').remove(); // 移除弹窗
      $('#hoi4_legal_popup').remove(); // 移除弹窗
      document.body.innerHTML = '<div style="text-align: center; padding: 50px; color: white; background: #000;">您已拒绝遵守法律条款,无法访问本页面。</div>';
     document.body.style.filter = 'none'; // 取消模糊
      ding('您已拒绝条款,访问已被禁止。', 'warning', 5000); // 显示警告通知
      document.body.innerHTML = `
       <div style="
         text-align: center; padding: 50px; color: white; background: #000;
         min-height: 100vh; display: flex; align-items: center; justify-content: center;">
         您已拒绝遵守法律条款,无法访问本页面。
       </div>
     `;
      showNotification('您已拒绝条款,访问已被禁止。', 'warning', 5000); // 显示警告通知
    });
    });
})(jQuery, mediaWiki);
})(jQuery, mediaWiki);

2025年5月29日 (四) 04:10的版本

/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
(function($, mw) {
    "use strict";

    // 只在浏览页面时显示
    if (mw.config.get('wgAction') !== 'view') return;

    // Cookie 处理函数
    function setCookie(name, value, days) {
        var expires = "";
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            expires = "; expires=" + date.toUTCString();
        }
        document.cookie = name + "=" + (value || "") + expires + "; path=/";
    }

    function getCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) === ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    }

    // 自定义通知函数(替代 ding.js)
    function showNotification(message, type, ttl) {
        // 插入通知样式
        if (!document.getElementById('hoi4_notification_styles')) {
            document.body.insertAdjacentHTML('afterbegin', `
                <style id="hoi4_notification_styles">
                    .hoi4-notification {
                        position: fixed;
                        bottom: 0;
                        left: 0;
                        right: 0;
                        margin: 0;
                        padding: 0.6em 2em;
                        line-height: 1.4em;
                        text-align: center;
                        z-index: 10001;
                        font-size: 86%;
                        font-weight: bold;
                        transform: translateY(100%);
                        transition: all 0.3s ease-in-out;
                        opacity: 1;
                        box-shadow: 0 -2px 5px rgba(0,0,0,0.2);
                    }
                    .hoi4-notification.success {
                        background: rgba(0, 175, 137, 0.9);
                        color: white;
                    }
                    .hoi4-notification.warning {
                        background: rgba(221, 51, 51, 0.9);
                        color: white;
                    }
                </style>
            `);
        }

        // 创建通知元素
        var notificationId = 'hoi4_notification_' + Date.now();
        document.body.insertAdjacentHTML('beforeend', `
            <div id="${notificationId}" class="hoi4-notification ${type}">
                ${message}
            </div>
        `);

        var notification = document.getElementById(notificationId);
        // 显示动画
        setTimeout(function() {
            notification.style.transform = 'translateY(0%)';
        }, 10);

        // 自动消失
        if (ttl) {
            setTimeout(function() {
                notification.style.transform = 'translateY(100%)';
                setTimeout(function() {
                    notification.remove();
                }, 300);
            }, ttl);
        }
    }

    // 检查用户是否已同意
    if (getCookie('hoi4_legal_agreed') === 'true') {
        return; // 用户已同意,不显示弹窗
    }

    // 模糊页面内容
    document.body.style.filter = 'blur(5px)';
    document.body.style.transition = 'filter 0.3s ease';

    // 创建全屏弹窗
    var popupHtml = `
        <div id="hoi4_legal_popup" style="
            position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
            background: rgba(0, 0, 0, 0.8); z-index: 10000;
            display: flex; justify-content: center; align-items: center;
            color: white; font-family: Arial, sans-serif;">
            <div style="
                background: #333; padding: 20px; border-radius: 10px;
                max-width: 600px; text-align: center; box-shadow: 0 0 10px rgba(0,0,0,0.5);">
                <h2>法律声明</h2>
                <p>欢迎体验《钢铁雄心 IV》(Hearts of Iron IV)相关内容。本游戏涉及历史题材,在使用时需遵守相关法律法规。请确认您同意以下条款:</p>
                <ul style="text-align: left; margin: 1em 0;">
                    <li>本站内容不得分享或传播本站任何未经审核的内容至任何平台。</li>
                    <li>严禁在本站上传违反中华人民共和国法律的相关项目及文本。</li>
                    <li>因MediaWiki的特殊性,本站部分内容未经审核,请自行决定是否阅读。</li>
                </ul>
                <p>若您同意,请点击“同意”继续访问;若不同意,将无法访问本页面。</p>
                <div style="margin-top: 20px;">
                    <button id="hoi4_agree" style="
                        margin: 10px; padding: 10px 20px; background: #0a0;
                        border: none; color: white; cursor: pointer; border-radius: 5px;
                        font-size: 16px; transition: background 0.2s;">
                        同意
                    </button>
                    <button id="hoi4_disagree" style="
                        margin: 10px; padding: 10px 20px; background: #a00;
                        border: none; color: white; cursor: pointer; border-radius: 5px;
                        font-size: 16px; transition: background 0.2s;">
                        不同意
                    </button>
                </div>
            </div>
        </div>
    `;

    // 将弹窗添加到页面
    document.body.insertAdjacentHTML('beforeend', popupHtml);

    // 处理“同意”按钮
    $('#hoi4_agree').on('click', function() {
        setCookie('hoi4_legal_agreed', 'true', 365); // 保存同意状态,1年有效
        $('#hoi4_legal_popup').remove(); // 移除弹窗
        document.body.style.filter = 'none'; // 取消模糊
        showNotification('感谢您的配合!您已同意遵守相关法律条款。', 'success', 3000); // 显示成功通知
    });

    // 处理“不同意”按钮
    $('#hoi4_disagree').on('click', function() {
        $('#hoi4_legal_popup').remove(); // 移除弹窗
        document.body.style.filter = 'none'; // 取消模糊
        document.body.innerHTML = `
            <div style="
                text-align: center; padding: 50px; color: white; background: #000;
                min-height: 100vh; display: flex; align-items: center; justify-content: center;">
                您已拒绝遵守法律条款,无法访问本页面。
            </div>
        `;
        showNotification('您已拒绝条款,访问已被禁止。', 'warning', 5000); // 显示警告通知
    });
})(jQuery, mediaWiki);