「MediaWiki:Mobile.js」の版間の差分

提供:Vikipedia
編集の要約なし
編集の要約なし
タグ: モバイル編集 モバイルウェブ編集
 
(同じ利用者による、間の30版が非表示)
1行目: 1行目:
// @ts-check
window.___mobileJSLoaded = true;


(async () => {
(function () {
     /**
     var disableMobileUI = false
    * @typedef {import("jquery")} JQuery
        || window.localStorage.getItem("disableMobileUI")
    */
        || window.sessionStorage.getItem("disableMobileUI")
 
     if (disableMobileUI) {
    /**
        return;
    * @typedef MobileUIMenuItem
     }
    * @prop {string} title
    * @prop {string} page
    * @prop {string | string[]} [class]
    */
 
    /**
    * @typedef MobileUI
    * @prop {MobileUIMenuItem[]} menu
    */
 
    const config = {
        wgArticleId: Number(),
        wgServer: "",
        wgScriptPath: String(),
    };
 
     Object.assign(config, mw.config.get(Object.keys(config)));
 
    const wikiURL = `${config.wgServer}${config.wgScriptPath}`;
 
     const mobileUIPath = `${wikiURL}/index.php?title=MediaWiki:MobileUI.json&action=raw&ctype=application/json`;
    const response = await window.fetch(mobileUIPath);


     /**
     var wgScript = mw.config.get("wgScript");
    * @type {MobileUI}
    */
    const mobileUI = await response.json();


     const menu = $(".menu");
     var builderURL = wgScript
        + "?"
        + new URLSearchParams({
            title: "MediaWiki:MobileUI.js",
            action: "raw",
            ctype: "text/javascript"
        })
        .toString();


     menu.find("ul").first().remove();
     var builderThread = mw.loader
        .getScript(builderURL)
        .then(function () {
            return new MobileUIBuilder(mw)
                .prebuild();
        });


     if (config.wgArticleId > 1) {
     var dataURL = wgScript
         const hlist = $("<ul>")
         + "?"
             .addClass("hlist")
        + new URLSearchParams({
             .css("word-break", "break-all")
             title: "MediaWiki:MobileUI.json",
            .prependTo(menu);
             action: "raw",
            ctype: "application/json"
        })
        .toString();


        const li = $("<li>").appendTo(hlist);
    var dataThread = $
         const dl = $("<dl>").appendTo(li);
        .getJSON(dataURL)
         .then(Object);


        $("<dt>")
    $
            .text("ページの短縮URL")
         .when(builderThread, dataThread)
            .css("display", "block")
         .done(function (builder, data) {
            .css("padding-left", "1em")
             builder.build(data);
            .appendTo(dl);
        });
 
         const dd = $("<dd>")
            .css("display", "block")
            .appendTo(dl);
 
        const shortURL = `${wikiURL}/?curid=${config.wgArticleId}`;
 
         $("<a>")
            .text(shortURL)
            .attr("href", shortURL)
             .appendTo(dd);
    }
 
    const ul = $("<ul>").prependTo(menu);
 
    for (const menuItem of mobileUI.menu) {
        const li = $("<li>").appendTo(ul);
 
        $("<a>")
            .text(menuItem.title)
            .addClass(["mw-ui-icon", "mw-ui-icon-before"])
            .attr("href", menuItem.page)
            .appendTo(li);
    }
})();
})();

2020年9月30日 (水) 01:46時点における最新版

window.___mobileJSLoaded = true;

(function () {
    var disableMobileUI = false
        || window.localStorage.getItem("disableMobileUI")
        || window.sessionStorage.getItem("disableMobileUI")
    if (disableMobileUI) {
        return;
    }

    var wgScript = mw.config.get("wgScript");

    var builderURL = wgScript
        + "?"
        + new URLSearchParams({
            title: "MediaWiki:MobileUI.js",
            action: "raw",
            ctype: "text/javascript"
        })
        .toString();

    var builderThread = mw.loader
        .getScript(builderURL)
        .then(function () {
            return new MobileUIBuilder(mw)
                .prebuild();
        });

    var dataURL = wgScript
        + "?"
        + new URLSearchParams({
            title: "MediaWiki:MobileUI.json",
            action: "raw",
            ctype: "application/json"
        })
        .toString();

    var dataThread = $
        .getJSON(dataURL)
        .then(Object);

    $
        .when(builderThread, dataThread)
        .done(function (builder, data) {
            builder.build(data);
        });
})();