MediaWiki:Gadget-UserLinkAvatar.js

    叶子和他的Vtuber们
    Revision as of 09:39, 22 December 2022 by LovelyA72 (talk | contribs) (Created page with ""use strict"; // <pre> (() => { 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("wgS...")
    (diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

    Note: After publishing, you may have to bypass your browser's cache to see the changes.

    • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
    • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
    • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
    • Opera: Press Ctrl-F5.
    "use strict";
    // <pre>
    (() => {
        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>