注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
/* 这里的任何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 = "";
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;
}
// 检查用户是否已同意
if (getCookie('hoi4_legal_agreed') === 'true') {
return; // 用户已同意,不显示弹窗
}
// 创建全屏弹窗
var popupHtml = `
<div id="hoi4_legal_popup" style="
position: fixed; top: 0; left: 0; right: 0; bottom: 0;
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;">
<h2>法律声明</h2>
<p>欢迎体验《钢铁雄心 IV》(Hearts of Iron IV)相关内容。本游戏涉及历史题材,在使用时需遵守相关法律法规。请确认您同意以下条款:</p>
<ul style="text-align: left;">
<li>不得分享或传播游戏内容至未经授权的平台。</li>
<li>不得恶意编辑或歪曲游戏中的历史内容。</li>
<li>遵守相关法律法规,确保合法使用。</li>
</ul>
<p>若您同意,请点击“同意”继续访问;若不同意,将无法访问本页面。</p>
<button id="hoi4_agree" style="margin: 10px; padding: 10px 20px; background: #0a0; border: none; color: white; cursor: pointer;">同意</button>
<button id="hoi4_disagree" style="margin: 10px; padding: 10px 20px; background: #a00; border: none; color: white; cursor: pointer;">不同意</button>
</div>
</div>
`;
// 将弹窗添加到页面
document.body.insertAdjacentHTML('beforeend', popupHtml);
// 处理“同意”按钮
$('#hoi4_agree').on('click', function() {
setCookie('hoi4_legal_agreed', 'true', 365); // 保存同意状态,1年有效
$('#hoi4_legal_popup').remove(); // 移除弹窗
ding('感谢您的配合!您已同意遵守相关法律条款。', 'success', 3000); // 显示成功通知
});
// 处理“不同意”按钮
$('#hoi4_disagree').on('click', function() {
$('#hoi4_legal_popup').remove(); // 移除弹窗
document.body.innerHTML = '<div style="text-align: center; padding: 50px; color: white; background: #000;">您已拒绝遵守法律条款,无法访问本页面。</div>';
ding('您已拒绝条款,访问已被禁止。', 'warning', 5000); // 显示警告通知
});
})(jQuery, mediaWiki);