MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
HW(留言 | 贡献) (创建页面,内容为“→这里的任何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 = m…”) |
|||
| 第20行: | 第20行: | ||
bottomBar.id = 'custom-wiki-bottom-bar'; | bottomBar.id = 'custom-wiki-bottom-bar'; | ||
bottomBar.style.cssText = ` | bottomBar.style.cssText = ` | ||
`; | `; | ||
| 第68行: | 第63行: | ||
}); | }); | ||
// 6. 将按钮栏插入到 main#content 内部的最底部 | |||
const | const content = document.querySelector('main#content, #content'); | ||
if ( | if (content) { | ||
bottomBar.style.marginTop = '2.5rem'; | |||
content.appendChild(bottomBar); | content.appendChild(bottomBar); | ||
} | } | ||
}); | }); | ||
2026年2月19日 (四) 11:39的版本
/* 这里的任何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);
}
});