跳转到内容

MediaWiki:Gadget-ilhpp-settings.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/**!
 *  _________________________________________________________________________________
 * |                                                                                 |
 * |                      === WARNING: GLOBAL GADGET FILE ===                        |
 * |                    Changes to this page affect many users.                      |
 * |  Please discuss changes on the talk page, [[WP:VPT]] or GitHub before editing.  |
 * |_________________________________________________________________________________|
 *
 * Built from GitHub repository (https://github.com/diskdance/ilhpp), you should not make
 * changes directly here.
 *
 * See https://github.com/diskdance/ilhpp/blob/main/README.MD#%E9%83%A8%E7%BD%B2%E6%96%B9%E6%B3%95 for build instructions.
 */
// <nowiki>
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const codex = require("@wikimedia/codex");
const ext_gadget_ilhpp = require("ext.gadget.ilhpp");
const ext_gadget_HanAssist = require("ext.gadget.HanAssist");
const _hoisted_1 = { key: 0 };
const _hoisted_2 = { class: "ilhpps-small" };
const _hoisted_3 = {
  key: 1,
  class: "ilhpps-fallback"
};
const _hoisted_4 = { class: "ilhpps-fallback__text ilhpps-small" };
const _hoisted_5 = { class: "ilhpps-small" };
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  __name: "SettingsDialog",
  props: {
    "open": __spreadValues({ type: Boolean }, { required: true }),
    "openModifiers": {},
    "disabled": __spreadValues({ type: Boolean }, { required: true }),
    "disabledModifiers": {},
    "prefs": { required: true },
    "prefsModifiers": {}
  },
  emits: /* @__PURE__ */ vue.mergeModels(["save"], ["update:open", "update:disabled", "update:prefs"]),
  setup(__props, { emit: __emit }) {
    const isOpen = vue.useModel(__props, "open");
    const isDisabled = vue.useModel(__props, "disabled");
    const prefs = vue.useModel(__props, "prefs");
    const emit = __emit;
    const isFallbackTipsShowing = vue.ref(false);
    const isAnyPrefChanged = vue.ref(false);
    const haveConflicts = ext_gadget_ilhpp.haveConflicts();
    vue.watch(
      prefs,
      () => {
        isAnyPrefChanged.value = true;
      },
      { once: true, deep: true }
    );
    vue.watch(isOpen, (newValue) => {
      if (newValue) {
        isFallbackTipsShowing.value = false;
        isDisabled.value = false;
      }
    });
    function onPrimary() {
      if (prefs.value.popup === ext_gadget_ilhpp.PopupMode.Disabled && !isFallbackTipsShowing.value) {
        isFallbackTipsShowing.value = true;
      } else {
        emit("save");
      }
    }
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createBlock(vue.unref(codex.CdxDialog), {
        open: isOpen.value,
        "onUpdate:open": _cache[4] || (_cache[4] = ($event) => isOpen.value = $event),
        title: _ctx.$i18n("ilhpps-title").text(),
        "primary-action": {
          label: _ctx.$i18n("ilhpps-ok").text(),
          actionType: "progressive",
          disabled: isDisabled.value || !isAnyPrefChanged.value
        },
        "use-close-button": true,
        onPrimary
      }, vue.createSlots({
        default: vue.withCtx(() => [
          !isFallbackTipsShowing.value ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
            vue.createVNode(vue.unref(codex.CdxField), {
              "is-fieldset": true,
              disabled: isDisabled.value
            }, {
              label: vue.withCtx(() => [
                vue.createTextVNode(vue.toDisplayString(_ctx.$i18n("ilhpps-link-mode").text()), 1)
              ]),
              default: vue.withCtx(() => [
                (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(ext_gadget_ilhpp.LinkMode), (option) => {
                  return vue.openBlock(), vue.createBlock(vue.unref(codex.CdxRadio), {
                    key: option,
                    modelValue: prefs.value.link,
                    "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => prefs.value.link = $event),
                    "input-value": option,
                    name: "ilhpps-link-mode"
                  }, {
                    default: vue.withCtx(() => [
                      vue.createTextVNode(vue.toDisplayString(_ctx.$i18n(`ilhpps-link-mode-${option.toLowerCase().replace(/_/g, "-")}`).text()), 1)
                    ]),
                    _: 2
                  }, 1032, ["modelValue", "input-value"]);
                }), 128))
              ]),
              _: 1
            }, 8, ["disabled"]),
            vue.createVNode(vue.unref(codex.CdxField), {
              "is-fieldset": true,
              disabled: isDisabled.value || vue.unref(haveConflicts),
              status: vue.unref(haveConflicts) ? "error" : "default"
            }, {
              label: vue.withCtx(() => [
                vue.createTextVNode(vue.toDisplayString(_ctx.$i18n("ilhpps-popup-mode").text()), 1)
              ]),
              error: vue.withCtx(() => [
                vue.createTextVNode(vue.toDisplayString(_ctx.$i18n("ilhpps-popup-have-conflicts").text()), 1)
              ]),
              default: vue.withCtx(() => [
                (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(ext_gadget_ilhpp.PopupMode), (option) => {
                  return vue.openBlock(), vue.createBlock(vue.unref(codex.CdxRadio), {
                    key: option,
                    modelValue: prefs.value.popup,
                    "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => prefs.value.popup = $event),
                    "input-value": option,
                    name: "ilhpps-popup-mode"
                  }, vue.createSlots({
                    default: vue.withCtx(() => [
                      vue.createTextVNode(vue.toDisplayString(_ctx.$i18n(`ilhpps-popup-mode-${option.toLowerCase().replace(/_/g, "-")}`).text()) + " ", 1)
                    ]),
                    _: 2
                  }, [
                    option === vue.unref(ext_gadget_ilhpp.PopupMode).OnHover ? {
                      name: "description",
                      fn: vue.withCtx(() => [
                        vue.createElementVNode("span", _hoisted_2, vue.toDisplayString(_ctx.$i18n("ilhpps-popup-mode-footnote").text()), 1)
                      ]),
                      key: "0"
                    } : void 0
                  ]), 1032, ["modelValue", "input-value"]);
                }), 128))
              ]),
              _: 1
            }, 8, ["disabled", "status"]),
            vue.createVNode(vue.unref(codex.CdxField), {
              "is-fieldset": true,
              disabled: isDisabled.value
            }, {
              label: vue.withCtx(() => [
                vue.createTextVNode(vue.toDisplayString(_ctx.$i18n("ilhpps-orig-link-color").text()), 1)
              ]),
              default: vue.withCtx(() => [
                (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(ext_gadget_ilhpp.OrigLinkColor), (option) => {
                  return vue.openBlock(), vue.createBlock(vue.unref(codex.CdxRadio), {
                    key: option,
                    modelValue: prefs.value.origLinkColor,
                    "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => prefs.value.origLinkColor = $event),
                    "input-value": option,
                    name: "ilhpps-orig-link-color"
                  }, {
                    default: vue.withCtx(() => [
                      vue.createTextVNode(vue.toDisplayString(_ctx.$i18n(`ilhpps-orig-link-color-${option.toLowerCase().replace(/_/g, "-")}`).text()), 1)
                    ]),
                    _: 2
                  }, 1032, ["modelValue", "input-value"]);
                }), 128))
              ]),
              _: 1
            }, 8, ["disabled"]),
            vue.createVNode(vue.unref(codex.CdxField), {
              "is-fieldset": true,
              disabled: isDisabled.value
            }, {
              default: vue.withCtx(() => [
                vue.createVNode(vue.unref(codex.CdxCheckbox), {
                  modelValue: prefs.value.highlightExisting,
                  "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => prefs.value.highlightExisting = $event)
                }, {
                  default: vue.withCtx(() => [
                    vue.createTextVNode(vue.toDisplayString(_ctx.$i18n("ilhpps-highlight-existing").text()), 1)
                  ]),
                  _: 1
                }, 8, ["modelValue"])
              ]),
              _: 1
            }, 8, ["disabled"])
          ])) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_3, [
            _cache[5] || (_cache[5] = vue.createElementVNode("div", { class: "ilhpps-fallback__img" }, null, -1)),
            vue.createElementVNode("p", _hoisted_4, vue.toDisplayString(_ctx.$i18n("ilhpps-fallback-tips").text()), 1)
          ]))
        ]),
        _: 2
      }, [
        !isFallbackTipsShowing.value ? {
          name: "footer-text",
          fn: vue.withCtx(() => [
            vue.createElementVNode("span", _hoisted_5, vue.toDisplayString(_ctx.$i18n("ilhpps-footnote").text()), 1)
          ]),
          key: "0"
        } : void 0
      ]), 1032, ["open", "title", "primary-action"]);
    };
  }
});
const _export_sfc = (sfc, props) => {
  const target = sfc.__vccOpts || sfc;
  for (const [key, val] of props) {
    target[key] = val;
  }
  return target;
};
const SettingsDialog = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-97e83eab"]]);
const messages = {
  "ilhpps-title": { "hans": "跨语言链接设置", "hant": "跨語言連結設定" },
  "ilhpps-link-mode": { "hans": "链接外观", "hant": "連結外觀" },
  "ilhpps-link-mode-orig": { "hans": "只显示内部链接", "hant": "只顯示內部連結" },
  "ilhpps-link-mode-orig-n-unlinked-foreign": { "hans": "显示内部链接和不含链接的原文", "hant": "顯示內部連結和不含連結的原文" },
  "ilhpps-link-mode-foreign": { "hans": "只显示跨维基链接", "hant": "只顯示跨維基連結" },
  "ilhpps-link-mode-foreign-n-lang-code": { "hans": "显示跨维基链接和语言名后缀", "hant": "顯示跨維基連結和語言名字尾" },
  "ilhpps-popup-mode": { "hans": "弹框模式", "hant": "彈框模式" },
  "ilhpps-popup-mode-disabled": { "hans": "禁用", "hant": "禁用" },
  "ilhpps-popup-mode-on-hover": { "hans": "光标悬浮时显示", "hant": "游標懸浮時顯示" },
  "ilhpps-popup-mode-on-click": { "hans": "点击时显示", "hant": "點選時顯示" },
  "ilhpps-popup-mode-footnote": { "hans": "移动设备上将始终在点击时显示。", "hant": "移動裝置上將始終在點選時顯示。" },
  "ilhpps-popup-have-conflicts": { "hans": "请先关闭导航Popup小工具,才可使用本功能。", "hant": "請先關閉導航Popup小工具,才可使用本功能。" },
  "ilhpps-orig-link-color": { "hans": "内部链接颜色", "hant": "內部連結顏色" },
  "ilhpps-orig-link-color-red": { "hans": "红色", "hant": "紅色" },
  "ilhpps-orig-link-color-green": { "hans": "绿色", "hant": "綠色" },
  "ilhpps-highlight-existing": { "hans": "高亮显示本地已存在条目的跨语言链接", "hant": "高亮顯示本地已存在條目的跨語言連結" },
  "ilhpps-ok": { "hans": "确定", "hant": "確定" },
  "ilhpps-footnote": { "hans": "如要完全关闭本工具,请登录后在参数设置 → 小工具中关闭。", "hant": "如要完全關閉本工具,請登入後在偏好設定 → 小工具中關閉。" },
  "ilhpps-fallback-tips": { "hans": "之后若要访问本设置,可在页尾的链接处进入。", "hant": "之後若要訪問本設定,可在頁尾的連結處進入。" }
};
function showSettingsDialog() {
  mw.messages.set(ext_gadget_HanAssist.batchConv(messages));
  const root = document.createElement("div");
  document.body.append(root);
  vue.createMwApp({
    setup() {
      const isOpen = vue.ref(true);
      const isDisabled = vue.ref(false);
      const prefs = vue.reactive(ext_gadget_ilhpp.getPreferences());
      return () => vue.h(SettingsDialog, {
        open: isOpen.value,
        "onUpdate:open": (val) => {
          isOpen.value = val;
        },
        disabled: isDisabled.value,
        "onUpdate:disabled": (val) => {
          isDisabled.value = val;
        },
        prefs,
        onSave() {
          return __async(this, null, function* () {
            try {
              isDisabled.value = true;
              yield ext_gadget_ilhpp.setPreferences(prefs);
              isOpen.value = false;
            } catch (e) {
            }
          });
        }
      });
    }
  }).mount(root);
}
exports.showSettingsDialog = showSettingsDialog;
// </nowiki>