本网站正在建设中(~ ̄▽ ̄)~
- 你好~!欢迎来到中文歌声合成个人收集站-VCPedia.cn!
- 若发现页面信息有误或投稿至本站,请联系管理员。
MediaWiki:Gadget-site-js.js:修订间差异
跳到导航
跳到搜索
小无编辑摘要 |
小无编辑摘要 |
||
第225行: | 第225行: | ||
} | } | ||
/* T:注解 */ | /* T:注解 */ | ||
$(".annotation").each((_, ele) | $(".annotation").each(function (_, ele) { | ||
var popup = new OO.ui.PopupWidget({ | |||
$content: $(ele).children(".annotation-content"), | |||
padded: true, | |||
autoFlip: false, | |||
}); | }); | ||
$(ele) | |||
.append(popup.$element) | |||
.on("mouseover", function () { | |||
popup.toggle(true); | |||
}) | |||
.on("mouseout", function () { | |||
popup.toggle(false); | |||
}); | |||
}); | |||
/* 修正嵌套使用删除线、黑幕、彩色幕和胡话模板 */ | /* 修正嵌套使用删除线、黑幕、彩色幕和胡话模板 */ | ||
var templateTags = ["s", "del"]; | var templateTags = ["s", "del"]; |
2025年1月19日 (日) 18:49的最新版本
/* <pre> */ var _addText = '{{DifMGP|适配收集站}}'; "use strict"; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; (function ($, mw) { /* 检查是否为维护组成员 */ var wgUserGroups = mw.config.get("wgUserGroups"); var isMGPMGUser = wgUserGroups.includes("patroller") || wgUserGroups.includes("sysop"); var wgNamespaceNumber = mw.config.get("wgNamespaceNumber"); var wgAction = mw.config.get("wgAction"); var html = document.documentElement; var $body = $(document.body); var $window = $(window); /* 函数定义体 */ /* Tabs */ function tabs() { var defaultStyle = { purple: { labelColor: " ", labelBackgroundColor: "#9070c0", labelBorderColor: "#b090e0 #7050a0 #9070c0 #b090e0", labelPadding: ".2em .3em .2em .3em", textBorderColor: "#9070c0", textBackgroundColor: "#f0edf5", textPadding: "1em", }, green: { labelColor: " ", labelBackgroundColor: "#75c045", labelBorderColor: "#90d060 #60b030 #75c045 #90d060", labelPadding: ".2em .3em .2em .3em", textBorderColor: "#75c045 #60b030 #60b030 #75c045", textBackgroundColor: "#f5fffa", textPadding: "1em", }, red: { labelColor: " ", labelBackgroundColor: "#FF0000", labelBorderColor: "#FF8888 #CC0000 #FF0000 #FF8888", labelPadding: ".2em .3em .2em .3em", textBorderColor: "#FF0000 #CC0000 #CC0000 #FF0000", textBackgroundColor: "#fffafa", textPadding: "1em", }, blue: { labelColor: " ", labelBackgroundColor: "#5b8dd6", labelBorderColor: "#88abde #3379de #5b8dd6 #88abde", labelPadding: ".2em .3em .2em .3em", textBackgroundColor: "#f0f8ff", textBorderColor: "#5b8dd6 #3379de #3379de #5b8dd6", textPadding: "1em", }, yellow: { labelColor: " ", labelBackgroundColor: "#ffe147", labelBorderColor: "#ffe977 #ffd813 #ffe147 #ffe977", labelPadding: ".2em .3em .2em .3em", textBackgroundColor: "#fffce8", textBorderColor: "#ffe147 #ffd813 #ffd813 #ffe147", textPadding: "1em", }, orange: { labelColor: " ", labelBackgroundColor: "#ff9d42", labelBorderColor: "#ffac5d #ff820e #ff9d42 #ffac5d", labelPadding: ".2em .3em .2em .3em", textBackgroundColor: "#ffeedd", textBorderColor: "#ff9d42 #ff820e #ff820e #ff9d42", textPadding: "1em", }, black: { labelColor: " ", labelBackgroundColor: "#7f7f7f", labelBorderColor: "#999999 #4c4c4c #7f7f7f #999999", labelPadding: ".2em .3em .2em .3em", textBackgroundColor: "#e5e5e5", textBorderColor: "#7f7f7f #4c4c4c #4c4c4c #7f7f7f", textPadding: "1em", }, }; var sides = { top: { className: "tabLabelTop", labelColorSide: "top", labelBorderSide: ["left", "right"], labelColorSideReverse: "bottom", dividerSizeType: "height", }, bottom: { className: "tabLabelBottom", labelColorSide: "bottom", labelBorderSide: ["left", "right"], labelColorSideReverse: "top", dividerSizeType: "height", }, left: { className: "tabLabelLeft", labelColorSide: "left", labelBorderSide: ["top", "bottom"], labelColorSideReverse: "right", dividerSizeType: "width", }, right: { className: "tabLabelRight", labelColorSide: "right", labelBorderSide: ["top", "bottom"], labelColorSideReverse: "left", dividerSizeType: "width", }, }; var truthy = ["1", "on", "true", "yes"]; $body.addClass("tab"); var getOwnPropertyNamesLength = function (obj) { return Reflect.ownKeys(obj).length; }; var toLowerFirstCase = function (str) { return str.substring(0, 1).toLowerCase() + str.substring(1); }; var toUpperFirstCase = function (str) { return str.substring(0, 1).toUpperCase() + str.substring(1); }; mw.hook("wikipage.content").add(function (content) { content.find(".Tabs").each(function () { var self = $(this); if (self.children(".TabLabel")[0]) { return true; } var classList = Array.from(this.classList).filter(function (n) { return Reflect.has(defaultStyle, n); }); var data = $.extend({ labelPadding: "2px", labelBorderColor: "#aaa", labelColor: "green", labelBackgroundColor: $("#content").css("background-color") || "rgba(247,251,255,0.8)", textPadding: "20px 30px", textBorderColor: "#aaa", textBackgroundColor: "white", defaultTab: 1, }, classList[0] ? defaultStyle[classList[0]] || {} : {}, this.dataset || {}); var styleSheet = { label: {}, text: {}, }; var tabLabel = self.append('<div class="TabLabel"></div>').children(".TabLabel"), tabDivider = self.append('<div class="TabDivider"></div>').children(".TabDivider"), tabContent = self.append('<div class="TabContent"></div>').children(".TabContent"), labelPadding = data.labelPadding, labelColor = data.labelColor, labelSide = Reflect.has(sides, data.labelSide) ? data.labelSide : "top", side = sides[labelSide], labelColorSideReverse = truthy.includes(data.labelColorSideReverse), dividerSize = parseInt(data.dividerSize); var defaultTab = parseInt(data.defaultTab); if (labelSide === "top") { tabLabel.after(tabDivider); tabDivider.after(tabContent); } else if (labelSide === "bottom") { tabContent.after(tabDivider); tabDivider.after(tabLabel); } if (!isNaN(dividerSize) && dividerSize > 0) { self.find(".TabDivider")[side.dividerSizeType](dividerSize); } var labelColorName = toUpperFirstCase(labelColorSideReverse ? side.labelColorSideReverse : side.labelColorSide); self.addClass(side.className); if (labelColorSideReverse) { self.addClass("reverse"); } self.children(".Tab").each(function () { if ($(this).children(".TabLabelText").text().replace(/\s/g, "").length || $(this).children(".TabLabelText").children().length) { $(this).children(".TabLabelText").appendTo(tabLabel); $(this).children(".TabContentText").appendTo(self.children(".TabContent")); } $(this).remove(); }); if (isNaN(defaultTab) || defaultTab <= 0 || defaultTab > tabLabel.children(".TabLabelText").length) { defaultTab = 1; } tabLabel.children(".TabLabelText").on("click", function () { var label = $(this); label.addClass("selected").siblings().removeClass("selected").css({ "border-color": "transparent", "background-color": "inherit", }); tabContent.children(".TabContentText").eq(tabLabel.children(".TabLabelText").index(label)).addClass("selected").siblings().removeClass("selected").removeAttr("style"); if (getOwnPropertyNamesLength(styleSheet.label) > 0) { label.css(styleSheet.label); } setTimeout(function () { $window.triggerHandler("scroll"); }, 1); }).eq(defaultTab - 1).trigger("click"); if (labelPadding) { tabLabel.children(".TabLabelText").css("padding", labelPadding); } ["labelBorderColor", "labelBackgroundColor", "textPadding", "textBorderColor", "textBackgroundColor"].forEach(function (n) { var target = /^label/.test(n) ? "label" : "text", key = toLowerFirstCase(n.replace(target, "")); styleSheet[target][key] = data[n]; }); if (labelColor) { styleSheet.label["border".concat(labelColorName, "Color")] = labelColor; } else if (styleSheet.label.borderColor) { styleSheet.label["border".concat(labelColorName, "Color")] = "green"; } tabLabel.find(".selected").trigger("click"); if (getOwnPropertyNamesLength(styleSheet.text) > 0) { tabContent.css(styleSheet.text); } if (data.autoWidth === "yes") { self.addClass("AutoWidth"); } if (data.float === "left") { self.addClass("FloatLeft"); } if (data.float === "right") { self.addClass("FloatRight"); } }); }); } /* T:注解 */ $(".annotation").each(function (_, ele) { var popup = new OO.ui.PopupWidget({ $content: $(ele).children(".annotation-content"), padded: true, autoFlip: false, }); $(ele) .append(popup.$element) .on("mouseover", function () { popup.toggle(true); }) .on("mouseout", function () { popup.toggle(false); }); }); /* 修正嵌套使用删除线、黑幕、彩色幕和胡话模板 */ var templateTags = ["s", "del"]; var templateClasses = [".heimu", ".colormu", ".just-kidding-text"]; var templateStr = __spreadArray(__spreadArray([], templateTags, true), templateClasses, true).join(", "); /** * @param {JQuery<HTMLDivElement>} $content */ /* 水印 */ // https://github.com/zloirock/core-js/blob/v3.29.1/packages/core-js/modules/es.unescape.js var hex2 = /^[\da-f]{2}$/i; var hex4 = /^[\da-f]{4}$/i; function unescapeString (string){ var str = string; var result = ""; var length = str.length; var index = 0; var chr, part; while (index < length) { chr = str.charAt(index++); if (chr === "%") { if (str.charAt(index) === "u") { part = str.slice(index + 1, index + 5); if (hex4.exec(part)) { result += String.fromCharCode(parseInt(part, 16)); index += 5; continue; } } else { part = str.slice(index, index + 2); if (hex2.exec(part)) { result += String.fromCharCode(parseInt(part, 16)); index += 2; continue; } } } result += chr; } return result; }; function watermark(txt, size) { $("<div>").css({ position: "fixed !important", "z-index": "99999 !important", inset: "0px !important", "background-repeat": "repeat !important", "pointer-events": "none !important", display: "block !important", visibility: "visible !important", width: "unset !important", height: "unset !important", opacity: "unset !important", "background-color": "unset !important", "background-image": "url(\"data:image/svg+xml;base64,".concat(btoa("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"".concat(size, "\" height=\"").concat(size, "\"><foreignObject width=\"").concat(size, "\" height=\"").concat(size, "\"><html xmlns=\"http://www.w3.org/1999/xhtml\" style=\"width: ").concat(size, "px; height: ").concat(size, "px;\"><head></head><body style=\"width: ").concat(size, "px; height: ").concat(size, "px; margin: 0px;\"><div style=\"width: 100% !important; height: 100% !important; opacity: .17 !important; font-size: 24px !important; position: relative !important; color: black !important;\"><div style=\"transform: rotate(-15deg) translateX(-50%) translateY(-50%) !important; word-break: break-all !important; top: 36% !important; left: 50% !important; position: absolute !important; width: 100% !important; text-align: center !important;\">").concat(unescapeString(encodeURIComponent(txt)), "</div></div></body></html></foreignObject></svg>")), "\") !important;") }).appendTo("body"); }; /* 获取特定名字空间前缀正则表达式 */ var getNamespacePrefixRegex = function (namespaceNumber) { return RegExp("^(?:".concat(Object.entries(mw.config.get("wgNamespaceIds")).filter(function (config) { return config[1] === namespaceNumber; }).map(function (config) { return config[0].toLowerCase(); }).join("|"), "):"), "i"); }; // 列表侧边距 function listMarginLeft() { $(".mw-parser-output ul:not(.margin-left-set), .mw-parser-output ol:not(.margin-left-set), #mw-content-text > pre.prettyprint ul:not(.margin-left-set), #mw-content-text > pre.prettyprint ol:not(.margin-left-set)").each(function (_, ele) { var $ele = $(ele); if (/none.+none/i.test($ele.css("list-style")) || $ele.is(".gallery")) { if ($ele.parent().is("li") && $ele.parent().parent().is("ul, ol")) { $ele.css("margin-left", "1.2em"); } else { $ele.css("margin-left", "0.2em"); } } else if ($ele.is("ol")) { var li = $ele.children("li"); var start = $ele.attr("start"); var max_1 = /^\d+$/.test(start) ? +start : 0; li.each(function (_, e) { var value = $(e).attr("value"); if (/^\d+$/.test(value)) { max_1 = Math.max(max_1, +value); } else { max_1++; } }); $ele.attr("data-last-margin-left-max-length", max_1).css("margin-left", "".concat("".concat(max_1).length * 0.5 + 1.2, "em")); } else { $ele.css("margin-left", "1.2em"); } $ele.addClass("margin-left-set"); }); } ; // 页面历史表单部分按钮改为 post function historyForm() { var form = $("#mw-history-compare"); // form.find('[name="editchangetags"], [name="revisiondelete"]').attr("formmethod", "post"); // 不知为何,该方式不生效 form.find('[name="editchangetags"], [name="revisiondelete"]').on("click", function () { form.attr("method", "post"); setTimeout(function () { form.removeAttr("method"); }, 16); }); } ; /* 函数执行体 */ $(function () { // Tabs tabs(); // 修复错误嵌套模板 mw.hook("wikipage.content").add(templateFix); // 页面历史表单部分按钮改为 post if (wgAction === "history") { historyForm(); } var needHashChange = /[)]$/.test(location.pathname + location.search); if (needHashChange) { var originHash = location.hash; location.hash = "%"; location.hash = originHash; } $window.on("hashchange.hashchange", function () { var hash = decodeURIComponent(location.hash.replace(/^#/, "")); if (hash.length > 0) { var target = document.getElementById(hash); if (target) { var $target_1 = $(target); var needScroll = true; var mwCollapsible = $target_1.closest(".mw-collapsible.mw-collapsed"); if (mwCollapsible.length > 0) { mwCollapsible.find(".mw-collapsible-toggle").first().triggerHandler("click"); // needScroll = false; } var tabContentTextUnselected = $target_1.closest(".TabContentText:not(.selected)"); if (tabContentTextUnselected.length > 0) { tabContentTextUnselected.closest(".Tabs").children(".TabLabel").children().eq(tabContentTextUnselected.index()).trigger("click"); // needScroll = false; } if (needScroll) { setTimeout(function () { $("html, body").scrollTop($target_1.offset().top - window.innerHeight / 8); }, 50); } } } }); $window.triggerHandler("hashchange.hashchange"); // 列表侧边距 setInterval(listMarginLeft, 200); // 鼠标动作解除邮件地址反爬虫机制 ["copy", "keydown", "scroll", "mousemove"].forEach(function (type) { document.addEventListener(type, function () { $(".mailSymbol").replaceWith('<span title="Template:Mail@">@</span>'); }, { capture: true, passive: true, }); }); // 只在ns0和ns2的子页面加载预加载工具 if (![0, 2].includes(mw.config.get("wgNamespaceNumber")) || mw.config.get("wgNamespaceNumber") === 2 && !mw.config.get("wgPageName").includes("/")) { $("#multiboilerplateform").remove(); } // 标题反转义,来自维基百科 var firstHeading = $("#firstHeading").length ? $("#firstHeading") : $("#section_0"); var firstHeadingOld = firstHeading.html() || ""; var firstHeadingNew = firstHeadingOld; firstHeadingNew = firstHeadingNew.replace(/\n/g, " "); // 恢复换行符 firstHeadingNew = firstHeadingNew.replace(/<(\/?)(span|small|br)(.*?)>/g, "<$1$2$3>"); // 恢复 <span> <small> <br> 标签 firstHeadingNew = firstHeadingNew.replace(/<(\/?)(ruby|rb|rt)(.*?)>/g, "<$1$2$3>"); // 恢复模板 ruby 的使用 firstHeadingNew = firstHeadingNew.replace(/&/g, "&"); // 恢复 & 符号 // 如有需要恢复其他标签可在此补充,但请注意可能的安全隐患 if (firstHeadingNew !== firstHeadingOld) { firstHeading.html(firstHeadingNew); // $("title").text(firstHeading.text().replace(firstHeading.find('.mw-editsection').text(), '') + ' - 萌娘百科,' + wgUVS('万物皆可萌的百科全书', '萬物皆可萌的百科全書')); } }); // 以下代码应在全部内容加载完成后工作 $window.on("load", function () { $window.triggerHandler("resize"); }); })(jQuery, mediaWiki); /* </pre> */