MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
无编辑摘要 |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
(function() { | (function() { | ||
if (window.__globalFooterAdded) return; | // 防止重复执行的全局标志 | ||
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;">' + | 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>' + | ||
| 第7行: | 第11行: | ||
'</div>'; | '</div>'; | ||
// 插入函数 | |||
function insertFooter() { | function insertFooter() { | ||
if (document.getElementById('global-footer-links') | if (document.getElementById('global-footer-links')) { | ||
return true; | return true; | ||
} | } | ||
// | // 手机端常用容器(Minerva 皮肤) | ||
var | var mobileSelectors = [ | ||
if ( | '.mw-body', // Minerva 主内容区 | ||
'.content', // 通用内容区 | |||
'main', // HTML5 主标签 | |||
'.mw-footer-container', // Minerva 页脚容器 | |||
'.minerva-footer' // Minerva 页脚 | |||
]; | |||
// PC 端常用容器 | |||
var pcSelectors = [ | |||
'#footer', // Vector 皮肤页脚 | |||
'#mw-footer', // 通用页脚 | |||
'footer', // HTML5 页脚 | |||
'.footer' // 通用页脚类 | |||
]; | |||
// 先找页脚(PC 和手机) | |||
var allSelectors = mobileSelectors.concat(pcSelectors); | |||
for (var i = 0; i < allSelectors.length; i++) { | |||
var element = document.querySelector(allSelectors[i]); | |||
if (element) { | |||
// 如果是内容区(.mw-body 等),用 append;如果是页脚,用 before | |||
if (allSelectors[i] === '.mw-body' || allSelectors[i] === '.content' || allSelectors[i] === 'main') { | |||
element.insertAdjacentHTML('beforeend', footerHtml); | |||
} else { | |||
element.insertAdjacentHTML('beforebegin', footerHtml); | |||
} | |||
window.__globalFooterAdded = true; | |||
return true; | |||
} | |||
} | } | ||
// | // 最后的备选:找任何主要内容区 | ||
var | var lastResort = document.querySelector('#mw-content-text, .mw-body-content, #content'); | ||
if ( | if (lastResort) { | ||
lastResort.insertAdjacentHTML('beforeend', footerHtml); | |||
window.__globalFooterAdded = true; | window.__globalFooterAdded = true; | ||
return true; | return true; | ||
| 第37行: | 第61行: | ||
} | } | ||
// | // 执行插入(兼容各种加载时机) | ||
if (document.readyState === 'loading') { | function tryInsert() { | ||
if (insertFooter()) return; | |||
// 如果 DOM 还没准备好,等待 | |||
if (document.readyState === 'loading') { | |||
document.addEventListener('DOMContentLoaded', function() { | |||
setTimeout(insertFooter, 300); | |||
}); | |||
} | |||
// 监听 DOM 变化(应对动态加载内容) | |||
var observer = new MutationObserver(function() { | |||
if (insertFooter()) { | |||
observer.disconnect(); | |||
} | |||
}); | }); | ||
observer.observe(document.body, { childList: true, subtree: true }); | |||
setTimeout( | setTimeout(function() { observer.disconnect(); }, 10000); | ||
} | } | ||
// | // 立即执行 | ||
tryInsert(); | |||
})(); | })(); | ||
2026年3月22日 (日) 05:42的版本
(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;
}
// 手机端常用容器(Minerva 皮肤)
var mobileSelectors = [
'.mw-body', // Minerva 主内容区
'.content', // 通用内容区
'main', // HTML5 主标签
'.mw-footer-container', // Minerva 页脚容器
'.minerva-footer' // Minerva 页脚
];
// PC 端常用容器
var pcSelectors = [
'#footer', // Vector 皮肤页脚
'#mw-footer', // 通用页脚
'footer', // HTML5 页脚
'.footer' // 通用页脚类
];
// 先找页脚(PC 和手机)
var allSelectors = mobileSelectors.concat(pcSelectors);
for (var i = 0; i < allSelectors.length; i++) {
var element = document.querySelector(allSelectors[i]);
if (element) {
// 如果是内容区(.mw-body 等),用 append;如果是页脚,用 before
if (allSelectors[i] === '.mw-body' || allSelectors[i] === '.content' || allSelectors[i] === 'main') {
element.insertAdjacentHTML('beforeend', footerHtml);
} else {
element.insertAdjacentHTML('beforebegin', footerHtml);
}
window.__globalFooterAdded = true;
return true;
}
}
// 最后的备选:找任何主要内容区
var lastResort = document.querySelector('#mw-content-text, .mw-body-content, #content');
if (lastResort) {
lastResort.insertAdjacentHTML('beforeend', footerHtml);
window.__globalFooterAdded = true;
return true;
}
return false;
}
// 执行插入(兼容各种加载时机)
function tryInsert() {
if (insertFooter()) return;
// 如果 DOM 还没准备好,等待
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function() {
setTimeout(insertFooter, 300);
});
}
// 监听 DOM 变化(应对动态加载内容)
var observer = new MutationObserver(function() {
if (insertFooter()) {
observer.disconnect();
}
});
observer.observe(document.body, { childList: true, subtree: true });
setTimeout(function() { observer.disconnect(); }, 10000);
}
// 立即执行
tryInsert();
})();