MediaWiki:Gadget-heimu-toggle.js
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件。
/* eslint-disable prefer-arrow-callback */
/* eslint-disable prefer-template */
/* eslint-disable comma-dangle */
/* eslint-disable no-var */
/* eslint-disable no-unused-vars */
/* eslint dot-notation: ["error", { "allowPattern": "^(?:catch|default)$" } ] */
// eslint-disable-next-line no-redeclare
/* global mw, $, OO, moment, Cron, wgULS, insertToBottomRightCorner */
/* eslint-enable no-unused-vars */
"use strict";
// <pre>
$(function () {
if (!$(".heimu, .colormu")[0] || $("#heimu_toggle")[0]) {
return;
}
$(".colormu").each(function () {
this.dataset.backgroundColor = $(this).css("background-color");
});
var $body = $("body");
var btn = insertToBottomRightCorner(wgULS("半隐黑幕", "半隱黑幕")).attr("id", "heimu_toggle").css({
"user-select": "none",
order: "50",
});
btn.on("click", function () {
btn.text($("body.heimu_toggle_on")[0] ? wgULS("半隐黑幕", "半隱黑幕") : wgULS("隐藏黑幕", "隱藏黑幕"));
$body.toggleClass("heimu_toggle_on");
$(".colormu").each(function () {
var $thisColormu = $(this);
if ($thisColormu.hasClass("colormu_toggle_on")) {
$thisColormu.removeClass("colormu_toggle_on");
$thisColormu.css("background-color", this.dataset.backgroundColor);
} else {
$thisColormu.addClass("colormu_toggle_on");
$thisColormu.css("background-color", this.dataset.backgroundColor.replace(/\brgb\(([^)]+)\)/, "rgba($1, .17)").replace(/\brgba\((\d+,\s*\d+,\s*\d+),\s*\d+(?:\.\d+)?\)/, "rgba($1, .17)"));
}
});
});
if (+mw.user.options.get("gadget-HeimuToggleDefaultOn", 0) === 1) {
btn.trigger("click");
}
});
// </pre>