MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
(function() { | |||
// 如果已经添加过标记,说明整个页面生命周期内已经执行过 | |||
if (window.__globalFooterAdded) { | |||
return; | |||
// | } | ||
if ( | |||
// 要插入的 HTML | |||
var footerHtml = '<div id="global-footer-links" style="width:100%; margin-top:20px; padding:15px 0; display:flex; justify-content:space-between; flex-wrap:wrap; gap:10px; border-top:1px solid #ccc;">' + | var footerHtml = '<div id="global-footer-links" style="width:100%; margin-top:20px; padding:15px 0; display:flex; justify-content:space-between; flex-wrap:wrap; gap:10px; border-top:1px solid #ccc;">' + | ||
'<div><a href="https://new.pvzhe.wiki/index.php?title=特殊:创建账户&returnto=首页">加入我们</a></div>' + | '<div><a href="https://new.pvzhe.wiki/index.php?title=特殊:创建账户&returnto=首页">加入我们</a></div>' + | ||
| 第12行: | 第11行: | ||
'</div>'; | '</div>'; | ||
// | // 插入函数 | ||
function insertFooter() { | |||
document. | // 再次检查是否已经存在 | ||
document.querySelector('#mw-footer') | if (document.getElementById('global-footer-links')) { | ||
return true; | |||
} | |||
document.querySelector('#mw-content-text | |||
// 查找页脚 | |||
var footer = document.querySelector('#footer, #mw-footer, footer, .footer'); | |||
if (footer) { | |||
footer.insertAdjacentHTML('beforebegin', footerHtml); | |||
window.__globalFooterAdded = true; | |||
return true; | |||
} | |||
// 备选:查找内容区 | |||
var content = document.querySelector('#mw-content-text, .mw-body-content, #content'); | |||
if (content) { | |||
content.insertAdjacentHTML('beforeend', footerHtml); | |||
window.__globalFooterAdded = true; | |||
return true; | |||
} | } | ||
return false; | |||
} | } | ||
// | // 立即尝试插入(如果 DOM 已就绪) | ||
if ( | if (document.readyState === 'loading') { | ||
document.addEventListener('DOMContentLoaded', function() { | |||
// 延迟一点确保页脚元素已渲染 | |||
setTimeout(function() { | |||
if (!insertFooter()) { | |||
// 如果还没找到,用 MutationObserver 等待 | |||
var observer = new MutationObserver(function() { | |||
if (insertFooter()) { | |||
observer.disconnect(); | |||
} | |||
}); | |||
observer.observe(document.body, { childList: true, subtree: true }); | |||
// 5秒后自动停止,避免无限等待 | |||
setTimeout(function() { observer.disconnect(); }, 5000); | |||
} | |||
}, 100); | |||
}); | |||
} else { | |||
setTimeout(function() { | |||
if (!insertFooter()) { | |||
var observer = new MutationObserver(function() { | |||
if (insertFooter()) { | |||
observer.disconnect(); | |||
} | |||
}); | |||
observer.observe(document.body, { childList: true, subtree: true }); | |||
setTimeout(function() { observer.disconnect(); }, 5000); | |||
} | |||
}, 100); | |||
} | } | ||
} | })(); | ||
2026年3月22日 (日) 05:26的版本
(function() {
// 如果已经添加过标记,说明整个页面生命周期内已经执行过
if (window.__globalFooterAdded) {
return;
}
// 要插入的 HTML
var footerHtml = '<div id="global-footer-links" style="width:100%; margin-top:20px; padding:15px 0; display:flex; justify-content:space-between; flex-wrap:wrap; gap:10px; border-top:1px solid #ccc;">' +
'<div><a href="https://new.pvzhe.wiki/index.php?title=特殊:创建账户&returnto=首页">加入我们</a></div>' +
'<div><a href="https://www.pvzhe.com/new">前往官网以了解更多游戏信息</a></div>' +
'</div>';
// 插入函数
function insertFooter() {
// 再次检查是否已经存在
if (document.getElementById('global-footer-links')) {
return true;
}
// 查找页脚
var footer = document.querySelector('#footer, #mw-footer, footer, .footer');
if (footer) {
footer.insertAdjacentHTML('beforebegin', footerHtml);
window.__globalFooterAdded = true;
return true;
}
// 备选:查找内容区
var content = document.querySelector('#mw-content-text, .mw-body-content, #content');
if (content) {
content.insertAdjacentHTML('beforeend', footerHtml);
window.__globalFooterAdded = true;
return true;
}
return false;
}
// 立即尝试插入(如果 DOM 已就绪)
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function() {
// 延迟一点确保页脚元素已渲染
setTimeout(function() {
if (!insertFooter()) {
// 如果还没找到,用 MutationObserver 等待
var observer = new MutationObserver(function() {
if (insertFooter()) {
observer.disconnect();
}
});
observer.observe(document.body, { childList: true, subtree: true });
// 5秒后自动停止,避免无限等待
setTimeout(function() { observer.disconnect(); }, 5000);
}
}, 100);
});
} else {
setTimeout(function() {
if (!insertFooter()) {
var observer = new MutationObserver(function() {
if (insertFooter()) {
observer.disconnect();
}
});
observer.observe(document.body, { childList: true, subtree: true });
setTimeout(function() { observer.disconnect(); }, 5000);
}
}, 100);
}
})();