MediaWiki:Gadget-UserLinkAvatar.js

来自萌娘共享
AnnAngela-dbot讨论 | 贡献2024年4月16日 (二) 08:56的版本 (代码变动:e20a8415 - fix: do not replace with "mcommons" by U:星海子
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索

注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件
/**
 * -------------------------------------------------------------------------
 * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
 * -------------------------------------------------------------------------
 */
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/UserLinkAvatar/MediaWiki:Gadget-UserLinkAvatar.js|user=[[U:星海子]]|co-authors=|longId=e20a84152db23defda0f8d36c9c4c2cf86f22357|shortId=e20a8415|summary=fix: do not replace with "mcommons"}}'; 

/* <pre> */

"use strict";
(function () {
    var magnifierOn = +mw.user.options.get("gadget-userLinkAvatarMagnifier", 0) === 1;
    var $window = $(window);
    var loadingImage = "https://img.moegirl.org.cn/common/d/d1/Windows_10_loading.gif";
    $window.on("load.UserLinkAvatar", function () {
        var images = [];
        $(".mw-userlink:not(.user-avatar-added)").each(function (_, ele) {
            var item = $(ele);
            var src = "https://commons.moegirl.org.cn/extensions/Avatar/avatar.php?user=".concat(encodeURIComponent(item.text()));
            var img = $("<img/>").on("error", function () {
                window.setTimeout(function () {
                    img.closest(".userlink-avatar").remove();
                }, 0);
            }).addClass("userlink-avatar-small").attr({
                "data-src": src,
                src: loadingImage
            });
            images.push(img[0]);
            var bigAvatar = $("<span/>").addClass("userlink-avatar");
            item.prepend(bigAvatar.append(img));
            item.addClass("user-avatar-added");
            if (magnifierOn) {
                var magnifierImg_1 = $("<img/>", {
                    attr: {
                        "data-src": src,
                        src: loadingImage
                    },
                    on: {
                        error: function () {
                            window.setTimeout(function () {
                                magnifierImg_1.closest(".userlink-avatar-large").remove();
                            }, 0);
                        }
                    }
                });
                images.push(magnifierImg_1[0]);
                bigAvatar.on("click", function () {
                    window.open("https://commons.moegirl.org.cn/index.php?title=Special%3A\u67E5\u770B\u5934\u50CF&user=".concat(encodeURIComponent(item.text())), "_blank");
                    return false;
                }).append($("<div/>", {
                    attr: {
                        "class": "userlink-avatar-large"
                    }
                }).prepend(magnifierImg_1)).addClass("userlink-avatar-hover");
                item.before(bigAvatar);
                bigAvatar.add(bigAvatar.children()).attr("title", "\u67E5\u770B\u7528\u6237".concat(item.text(), "\u7684\u5934\u50CF"));
            }
        });
        if (typeof window.lazyload === "function") {
            window.lazyload(images);
        }
        else {
            images.forEach(function (ele) {
                ele.src = ele.dataset.src;
            });
        }
    });
    $(function () {
        $window.trigger("load.UserLinkAvatar");
    });
})(); 

/* </pre> */