User:Wecury/js/moe-history.js
来自Vocawiki
更多操作
< User:Wecury | js
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl + F5或Ctrl + R(Mac为⌘ R)
- Google Chrome:按Ctrl + Shift + R(Mac为⌘ Shift R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl + F5。
/*!
* 萌百历史跳转按钮
* ------------------------------------------------------------------
* 在任意页面的「版本历史」底部,添加一个按钮,点击后在新窗口打开萌娘百科中对应页面的版本历史。
*
* 使用:
* - 在个人 JS(User:你的用户名/common.js)中加入一行引用:
* importScript('User:Wecury/js/moe-history.js');
*/
"use strict";
$(function () {
if (mw.config.get("wgAction") !== "history") {
return;
}
const title = (mw.config.get("wgPageName") || "").replace(/_/g, " ");
if (!title) {
return;
}
const moegirlUrl =
"https://zh.moegirl.org.cn/index.php?title=" +
encodeURIComponent(title) +
"&action=history";
document
.querySelectorAll(".mw-history-compareselectedversions")
.forEach((container) => {
if (container.querySelector(".mw-history-moegirl-button")) {
return;
}
const btn = document.createElement("button");
btn.type = "button";
btn.className =
"cdx-button mw-history-moegirl-button";
btn.style.color = "var(--color-success)";
btn.style.backgroundColor = "var(--background-color-success-subtle)";
btn.style.borderColor = "var(--border-color-success)";
btn.title = "在萌娘百科中查看“" + title + "”的版本历史";
btn.textContent = "考古";
btn.addEventListener("click", (e) => {
e.preventDefault();
window.open(moegirlUrl, "_blank", "noopener");
});
container.appendChild(btn);
});
});