MediaWiki:Common.js
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
// 等待页面内容加载完成
mw.hook('wikipage.content').add(function() {
// 仅在 Minerva 皮肤下生效
if (mw.config.get('skin') !== 'minerva') return;
// 1. 获取当前页面信息
const pageTitle = mw.config.get('wgPageName');
const isTalkPage = mw.config.get('wgNamespaceNumber') % 2 === 1; // 判断是否为讨论页
const isExistingPage = mw.config.get('wgArticleId') > 0; // 判断页面是否存在
// 2. 构造核心链接
const editUrl = mw.util.getUrl(pageTitle, { action: 'edit' });
const historyUrl = mw.util.getUrl(pageTitle, { action: 'history' });
const talkTitle = isTalkPage ? pageTitle.replace(/^Talk:/, '') : `Talk:${pageTitle}`;
const talkUrl = mw.util.getUrl(talkTitle);
// 3. 创建底部按钮容器(样式模仿 Wikidot 的简洁风格)
const bottomBar = document.createElement('div');
bottomBar.id = 'custom-wiki-bottom-bar';
bottomBar.style.cssText = `
`;
// 4. 定义按钮组
const buttons = [
{
url: editUrl,
text: isExistingPage ? '编辑页面' : '创建页面',
color: '#3366cc' // 经典 MediaWiki 蓝
},
{
url: historyUrl,
text: '查看历史',
color: '#72777d' // 中性灰
},
{
url: talkUrl,
text: isTalkPage ? '返回条目' : '讨论页',
color: '#202122' // 深灰
}
];
// 5. 生成按钮并插入容器
buttons.forEach(btn => {
const link = document.createElement('a');
link.href = btn.url;
link.textContent = btn.text;
link.style.cssText = `
display: inline-block;
margin: 0 0.75rem;
padding: 0.5rem 1.25rem;
background-color: ${btn.color};
color: white;
text-decoration: none;
border-radius: 4px;
font-size: 0.95rem;
font-weight: 500;
transition: opacity 0.2s;
`;
link.onmouseover = () => link.style.opacity = '0.85';
link.onmouseout = () => link.style.opacity = '1';
bottomBar.appendChild(link);
});
// 6. 将按钮栏插入到 main#content 内部的最底部
const content = document.querySelector('main#content, #content');
if (content) {
bottomBar.style.marginTop = '2.5rem';
content.appendChild(bottomBar);
}
});