MediaWiki:Common.js:修订间差异

无编辑摘要
标签替换
 
第1行: 第1行:
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
(function($, mw) {
   "use strict";
   // 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);

2025年5月29日 (四) 15:43的最新版本

/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */