|
Tags: Replaced Manual revert |
Line 1: |
Line 1: |
| "use strict";
| | $('.mw-userlink').each(function(_, item) { |
| // <pre>
| | item = $(item); |
| (() => {
| | item.prepend($('<img/>').addClass('userlink-avatar').attr('src', mw.config.get('wgScriptPath') + '/extensions/Avatar/avatar.php?user=' + item.text())); |
| const magnifierOn = +mw.user.options.get("gadget-userLinkAvatarMagnifier", 0) === 1;
| | }); |
| const $window = $(window);
| |
| const loadingImage = ""//og link: "https://img.moegirl.org.cn/common/d/d1/Windows_10_loading.gif";
| |
| $window.on("load.UserLinkAvatar", () => {
| |
| const images = [];
| |
| $(".mw-userlink:not(.user-avatar-added)").each((_, ele) => {
| |
| const item = $(ele);
| |
| const src = `${mw.config.get("wgServer")}${mw.config.get("wgScriptPath")}/extensions/Avatar/avatar.php?user=${encodeURIComponent(item.text())}`;
| |
| const img = $("<img/>").on("error", () => {
| |
| window.setTimeout(() => {
| |
| img.closest(".userlink-avatar").remove();
| |
| }, 0);
| |
| }).addClass("userlink-avatar-small").attr({
| |
| "data-src": src,
| |
| src: loadingImage,
| |
| });
| |
| images.push(img[0]);
| |
| const bigAvatar = $("<span/>").addClass("userlink-avatar");
| |
| item.prepend(bigAvatar.append(img));
| |
| item.addClass("user-avatar-added");
| |
| if (magnifierOn) {
| |
| const magnifierImg = $("<img/>", {
| |
| attr: {
| |
| "data-src": src,
| |
| src: loadingImage,
| |
| },
| |
| on: {
| |
| error: () => {
| |
| window.setTimeout(() => {
| |
| magnifierImg.closest(".userlink-avatar-large").remove();
| |
| }, 0);
| |
| },
| |
| },
| |
| });
| |
| images.push(magnifierImg[0]);
| |
| bigAvatar.on("click", () => {
| |
| window.open(`${mw.config.get("wgServer")}${mw.config.get("wgScriptPath")}/index.php?title=Special:ViewAvatar&user=${encodeURIComponent(item.text())}`, "_blank");
| |
| return false;
| |
| }).append($("<div/>", {
| |
| attr: {
| |
| "class": "userlink-avatar-large",
| |
| },
| |
| }).prepend(magnifierImg)).addClass("userlink-avatar-hover");
| |
| item.before(bigAvatar);
| |
| bigAvatar.add(bigAvatar.children()).attr("title", `查看用户${item.text()}的头像`);
| |
| }
| |
| });
| |
| if (typeof window.lazyload === "function") {
| |
| window.lazyload(images);
| |
| } else {
| |
| images.forEach((ele) => {
| |
| ele.src = ele.dataset.src;
| |
| });
| |
| }
| |
| });
| |
| $(() => {
| |
| $window.trigger("load.UserLinkAvatar");
| |
| });
| |
| })(); | |
| // </pre>
| |