|
|
1行目: |
1行目: |
| // @ts-check
| |
|
| |
| (function () { | | (function () { |
| /** | | var config = mw.config.get(["wgServer", "wgScriptPath"]); |
| * @typedef {import("jquery")} JQuery
| | mw.loader.load(config.wgServer + config.wgScriptPath + "/MobileUI.js"); |
| */
| |
| | |
| /**
| |
| * @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);
| |
| | |
| /**
| |
| * @type {MobileUI}
| |
| */
| |
| const mobileUI = await response.json();
| |
| | |
| const menu = $(".menu");
| |
| | |
| menu.find("ul").first().remove();
| |
| | |
| if (config.wgArticleId > 1) {
| |
| const hlist = $("<ul>")
| |
| .addClass("hlist")
| |
| .css("word-break", "break-all")
| |
| .prependTo(menu);
| |
| | |
| const li = $("<li>").appendTo(hlist);
| |
| const dl = $("<dl>").appendTo(li);
| |
| | |
| $("<dt>")
| |
| .text("ページの短縮URL")
| |
| .css("display", "block")
| |
| .css("padding-left", "1em")
| |
| .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);
| |
| }
| |
| })(); | | })(); |