MediaWiki:Gadget-ShowContributors.js:修订间差异
MediaWiki界面页面
更多操作
![]() OctoberSama(留言 | 贡献) 小 |
![]() OctoberSama(留言 | 贡献) 小 |
||
第8行: | 第8行: | ||
) | ) | ||
return; | return; | ||
mw.loader.addStyleTag( | |||
mw.loader.addStyleTag(` | |||
#show-contributor-button { | |||
float: right; | |||
margin-left: .5em; | |||
margin-right: 0 | |||
} | |||
/* 桌面端样式 */ | |||
@media (min-width: 1120px) { | |||
.skin-citizen #show-contributor-button { | |||
float: none; | |||
margin-left: 0; | |||
margin-right: .5em; | |||
display: inline-flex; | |||
align-items: center | |||
} | |||
.skin-citizen .page-actions { | |||
display: flex; | |||
align-items: center; | |||
gap: .5em | |||
} | |||
} | |||
/* 移动端样式 */ | |||
@media (max-width: 1119px) { | |||
.skin-citizen #show-contributor-button { | |||
position: absolute; | |||
right: 0; | |||
top: 0; | |||
} | margin: 0.5em; | ||
} | |||
.skin-citizen .citizen-page-heading { | |||
position: relative; | |||
padding-right: 100px; | |||
} | |||
} | |||
/* 其他通用样式 */ | |||
#show-contributor-header { | |||
background: #fff; | |||
border-bottom: 1px solid #aaa; | |||
font-weight: 600; | |||
padding: .3em; | |||
position: sticky; | |||
text-align: center; | |||
top: 0 | |||
} | |||
#show-contributor-headline { | |||
font-size: 1.3em | |||
} | |||
#show-contributor-close { | |||
border-radius: 50%; | |||
cursor: pointer; | |||
position: absolute; | |||
right: 5px; | |||
top: 5px | |||
} | |||
#show-contributor-close:hover { | |||
background-color: #eee | |||
} | |||
#show-contributor-table { | |||
margin: 0; | |||
width: 100% | |||
} | } | ||
#show-contributor-table .user-avatar { | |||
border-radius: 50%; | |||
height: 20px; | |||
width: 20px | |||
} | } | ||
`); | |||
await mw.loader.using([ | |||
"mediawiki.api", | |||
"mediawiki.notification", | |||
"oojs-ui", | |||
"oojs-ui.styles.icons-interactions", | |||
"jquery.tablesorter" | |||
]); | |||
class ContributorDialog extends OO.ui.Dialog { | |||
// ...保持原有类定义不变... | |||
} | } | ||
const | |||
const windowManager = new OO.ui.WindowManager({ | |||
id: "show-contributor" | id: "show-contributor" | ||
}); | }); | ||
$(document.body).append( | $(document.body).append(windowManager.$element); | ||
const | const dialog = new ContributorDialog({ | ||
size: "large" | size: "large" | ||
}); | }); | ||
windowManager.addWindows([dialog]); | |||
const | |||
const button = new OO.ui.ButtonWidget({ | |||
label: "本页贡献者", | label: "本页贡献者", | ||
icon: "search", | icon: "search", | ||
第134行: | 第104行: | ||
id: "show-contributor-button" | id: "show-contributor-button" | ||
}); | }); | ||
// 动态插入按钮 | |||
const insertButton = () => { | |||
if ("citizen" === mw.config.get("skin")) { | |||
if (window.matchMedia("(min-width: 1120px)").matches) { | |||
// 桌面端:插入到.page-actions | |||
$(".page-actions").prepend(button.$element); | |||
} else { | |||
// 移动端:插入到.citizen-page-heading | |||
$(".citizen-page-heading").append(button.$element); | |||
} | |||
} else { | |||
// 其他皮肤 | |||
$("#bodyContent").prepend(button.$element); | |||
} | |||
}; | |||
// 初始插入 | |||
insertButton(); | |||
// | // 监听窗口大小变化 | ||
if ("citizen" === mw.config.get("skin")) { | $(window).on("resize", () => { | ||
if ("citizen" === mw.config.get("skin")) { | |||
button.$element.detach(); | |||
insertButton(); | |||
} | |||
}); | |||
} | |||
button.on("click", (async () => { | |||
if (!dialog.got) { | |||
if (! | button.setLabel("正在查询"); | ||
const data = await dialog.getContributors(); | |||
const | dialog.showContributors(data); | ||
dialog.$table.tablesorter(); | |||
button.setLabel("本页贡献者"); | |||
} | } | ||
windowManager.openWindow(dialog); | |||
})) | })); | ||
})())) | })())); | ||
})(); | })(); |
2025年6月10日 (二) 23:46的版本
(() => { "use strict"; $((() => (async () => { if ( ![0, 2, 4, 10, 12, 14, 828, 274].includes(mw.config.get("wgNamespaceNumber")) || 0 === mw.config.get("wgArticleId") || !["view", "history"].includes(mw.config.get("wgAction")) ) return; mw.loader.addStyleTag(` #show-contributor-button { float: right; margin-left: .5em; margin-right: 0 } /* 桌面端样式 */ @media (min-width: 1120px) { .skin-citizen #show-contributor-button { float: none; margin-left: 0; margin-right: .5em; display: inline-flex; align-items: center } .skin-citizen .page-actions { display: flex; align-items: center; gap: .5em } } /* 移动端样式 */ @media (max-width: 1119px) { .skin-citizen #show-contributor-button { position: absolute; right: 0; top: 0; margin: 0.5em; } .skin-citizen .citizen-page-heading { position: relative; padding-right: 100px; } } /* 其他通用样式 */ #show-contributor-header { background: #fff; border-bottom: 1px solid #aaa; font-weight: 600; padding: .3em; position: sticky; text-align: center; top: 0 } #show-contributor-headline { font-size: 1.3em } #show-contributor-close { border-radius: 50%; cursor: pointer; position: absolute; right: 5px; top: 5px } #show-contributor-close:hover { background-color: #eee } #show-contributor-table { margin: 0; width: 100% } #show-contributor-table .user-avatar { border-radius: 50%; height: 20px; width: 20px } `); await mw.loader.using([ "mediawiki.api", "mediawiki.notification", "oojs-ui", "oojs-ui.styles.icons-interactions", "jquery.tablesorter" ]); class ContributorDialog extends OO.ui.Dialog { // ...保持原有类定义不变... } const windowManager = new OO.ui.WindowManager({ id: "show-contributor" }); $(document.body).append(windowManager.$element); const dialog = new ContributorDialog({ size: "large" }); windowManager.addWindows([dialog]); const button = new OO.ui.ButtonWidget({ label: "本页贡献者", icon: "search", flags: "progressive", id: "show-contributor-button" }); // 动态插入按钮 const insertButton = () => { if ("citizen" === mw.config.get("skin")) { if (window.matchMedia("(min-width: 1120px)").matches) { // 桌面端:插入到.page-actions $(".page-actions").prepend(button.$element); } else { // 移动端:插入到.citizen-page-heading $(".citizen-page-heading").append(button.$element); } } else { // 其他皮肤 $("#bodyContent").prepend(button.$element); } }; // 初始插入 insertButton(); // 监听窗口大小变化 $(window).on("resize", () => { if ("citizen" === mw.config.get("skin")) { button.$element.detach(); insertButton(); } }); button.on("click", (async () => { if (!dialog.got) { button.setLabel("正在查询"); const data = await dialog.getContributors(); dialog.showContributors(data); dialog.$table.tablesorter(); button.setLabel("本页贡献者"); } windowManager.openWindow(dialog); })); })())); })();