MediaWiki:Gadget-ShowAvatar.js: Difference between revisions

    叶子和他的Vtuber们
    (Created page with ""use strict"; // <pre> $(() => { const commonsUrl = new mw.Uri(`${mw.config.get("wgServer")}${mw.config.get("wgScriptPath")}/`); commonsUrl.query.user = mw.config.get("wgPageName").replace(/^user:/i, ""); commonsUrl.path = "/extensions/Avatar/avatar.php"; const imgUrl = new mw.Uri(commonsUrl); imgUrl.query.user = mw.config.get("wgUserName"); const img = $("<img>").attr("src", imgUrl); const link = $("<a>").attr("href", `${mw.config.get("wgServ...")
     
    No edit summary
     
    (5 intermediate revisions by the same user not shown)
    Line 1: Line 1:
    "use strict";
    const img = $('<img>').attr('src', mw.config.get('wgScriptPath') + '/extensions/Avatar/avatar.php?nocache=true&user=' + mw.user.id());
    // <pre>
    const link = $('<a>').attr('href', mw.util.getUrl('Special:UploadAvatar')).append(img);
    $(() => {
    if(window.innerWidth>500){
        const commonsUrl = new mw.Uri(`${mw.config.get("wgServer")}${mw.config.get("wgScriptPath")}/`);
    $('#pt-userpage-2').before($('<li id="pt-avatar"></li>').append(link));
        commonsUrl.query.user = mw.config.get("wgPageName").replace(/^user:/i, "");
    }
        commonsUrl.path = "/extensions/Avatar/avatar.php";
        const imgUrl = new mw.Uri(commonsUrl);
        imgUrl.query.user = mw.config.get("wgUserName");
        const img = $("<img>").attr("src", imgUrl);
        const link = $("<a>").attr("href", `${mw.config.get("wgServer")}/Special:UploadAvatar`).append(img);
        $("#pt-userpage").before($('<li id="pt-avatar"></li>').append(link));
        if (mw.config.get("wgNamespaceNumber") === 2 && !mw.config.get("wgPageName").includes("/")) {
            const hrefUrl = new mw.Uri(commonsUrl);
            hrefUrl.path = "/Special:Viewavatar";
            const srcUrl = new mw.Uri(commonsUrl);
            $(".ns-2 #firstHeading").prepend($("<a/>").attr({
                href: hrefUrl,
                title: "查看头像",
            }).prepend($("<img/>").attr("src", srcUrl).css({
                width: "1.2em",
                height: "1.2em",
                "border-radius": "10px",
                padding: "4px",
            })));
        }
    });
    // </pre>

    Latest revision as of 11:29, 22 December 2022

    const img = $('<img>').attr('src', mw.config.get('wgScriptPath') + '/extensions/Avatar/avatar.php?nocache=true&user=' + mw.user.id());
    const link = $('<a>').attr('href', mw.util.getUrl('Special:UploadAvatar')).append(img);
    if(window.innerWidth>500){
    	$('#pt-userpage-2').before($('<li id="pt-avatar"></li>').append(link));
    }