MCBBS Wiki欢迎您共同参与编辑!在参与编辑之前请先阅读Wiki方针

如果在编辑的过程中遇到了什么问题,可以去讨论板提问。

为了您能够无阻碍地参与编辑 未验证/绑定过邮箱的用户,请尽快绑定/验证

MCBBS Wiki GitHub群组已上线!

您可以在回声洞中发表吐槽!

服务器状态监控。点击进入

本站由MCBBS用户自行搭建,与MCBBS及东银河系漫游指南(北京)科技有限公司没有从属关系。点此了解 MCBBS Wiki 不是什么>>

Gadget:ReplaceUsername.js:修订间差异

来自MCBBS Wiki
跳到导航 跳到搜索
(// Edit via Wikiplus)
(// Edit via Wikiplus)
第3行: 第3行:
(function () {
(function () {
console.log("///////////////////////////////////////////////////////\n// \u8BB8\u53EF\u8BC1 License //\n// \u534F\u8BAE\uFF1ACC BY-NC-SA 4.0 //\n// \u4F5C\u8005\uFF1ASalt_lovely //\n// \u51FA\u5904\uFF1AMCBBS Wiki - https://mcbbs.wiki //\n// \u5FC5\u987B\u4FDD\u7559\u6B64\u8BB8\u53EF\u8BC1\uFF0C\u5E76\u4EE5\u76F8\u540C\u7684\u8BB8\u53EF\u8BC1\u5206\u53D1 //\n// \u4E0D\u63A5\u53D7\u4EFB\u4F55\u5F62\u5F0F\u7684\u201C\u522B\u540D\u201D\u201C\u6635\u79F0\u201D\u6216\u5176\u4ED6\u65B9\u5F0F\u5C1D\u8BD5\u7ED5\u8FC7\u8BB8\u53EF\u8BC1 //\n// \u82E5\u534F\u8BAE\u51B2\u7A81\u6216\u4E0D\u63A5\u53D7\u4EE5\u4E0A\u989D\u5916\u6761\u6B3E\uFF0C\u4F60\u53EF\u4EE5\u9009\u62E9\u4E0D\u642C\u8FD0 //\n///////////////////////////////////////////////////////\n ");
console.log("///////////////////////////////////////////////////////\n// \u8BB8\u53EF\u8BC1 License //\n// \u534F\u8BAE\uFF1ACC BY-NC-SA 4.0 //\n// \u4F5C\u8005\uFF1ASalt_lovely //\n// \u51FA\u5904\uFF1AMCBBS Wiki - https://mcbbs.wiki //\n// \u5FC5\u987B\u4FDD\u7559\u6B64\u8BB8\u53EF\u8BC1\uFF0C\u5E76\u4EE5\u76F8\u540C\u7684\u8BB8\u53EF\u8BC1\u5206\u53D1 //\n// \u4E0D\u63A5\u53D7\u4EFB\u4F55\u5F62\u5F0F\u7684\u201C\u522B\u540D\u201D\u201C\u6635\u79F0\u201D\u6216\u5176\u4ED6\u65B9\u5F0F\u5C1D\u8BD5\u7ED5\u8FC7\u8BB8\u53EF\u8BC1 //\n// \u82E5\u534F\u8BAE\u51B2\u7A81\u6216\u4E0D\u63A5\u53D7\u4EE5\u4E0A\u989D\u5916\u6761\u6B3E\uFF0C\u4F60\u53EF\u4EE5\u9009\u62E9\u4E0D\u642C\u8FD0 //\n///////////////////////////////////////////////////////\n ");
console.log("Running Gadget-ReplaceUsername.js");
/**改名表 */
/**改名表 */
var map = [["Beanflame", "beanflame"], ["Salt_lovely", "盐酱"], ["Bleake", "bleake"]];
var map = [["Beanflame", "beanflame"], ["Salt_lovely", "盐酱"], ["Bleake", "bleake"]];

2022年11月10日 (四) 16:44的版本

"use strict";

(function () {
  console.log("///////////////////////////////////////////////////////\n// \u8BB8\u53EF\u8BC1 License                                     //\n// \u534F\u8BAE\uFF1ACC BY-NC-SA 4.0                              //\n// \u4F5C\u8005\uFF1ASalt_lovely                                  //\n// \u51FA\u5904\uFF1AMCBBS Wiki - https://mcbbs.wiki           //\n// \u5FC5\u987B\u4FDD\u7559\u6B64\u8BB8\u53EF\u8BC1\uFF0C\u5E76\u4EE5\u76F8\u540C\u7684\u8BB8\u53EF\u8BC1\u5206\u53D1               //\n// \u4E0D\u63A5\u53D7\u4EFB\u4F55\u5F62\u5F0F\u7684\u201C\u522B\u540D\u201D\u201C\u6635\u79F0\u201D\u6216\u5176\u4ED6\u65B9\u5F0F\u5C1D\u8BD5\u7ED5\u8FC7\u8BB8\u53EF\u8BC1 //\n// \u82E5\u534F\u8BAE\u51B2\u7A81\u6216\u4E0D\u63A5\u53D7\u4EE5\u4E0A\u989D\u5916\u6761\u6B3E\uFF0C\u4F60\u53EF\u4EE5\u9009\u62E9\u4E0D\u642C\u8FD0     //\n///////////////////////////////////////////////////////\n    ");
  /**改名表 */
  var map = [["Beanflame", "beanflame"], ["Salt_lovely", "盐酱"], ["Bleake", "bleake"]];
  // 执行一次
  replaceUsername();
  // 窗口加载完毕后再运行一次,以防漏网之鱼
  window.addEventListener("load", replaceUsername);
  /**修改用户名显示功能 */
  function replaceUsername() {
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
      for (var _iterator = getUname()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var el = _step.value;
        var _iteratorNormalCompletion2 = true;
        var _didIteratorError2 = false;
        var _iteratorError2 = undefined;

        try {
          for (var _iterator2 = map[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
            var m = _step2.value;

            if (el.textContent == m[0] || el.textContent == mwUsernameTurn(m[0])) {
              el.textContent = m[1];
              if (el.hasAttribute("title")) {
                el.setAttribute("title", el.getAttribute("title") + " | 原名: " + m[0]);
              } else {
                el.setAttribute("title", "原名: " + m[0]);
              }
              break;
            }
          }
        } catch (err) {
          _didIteratorError2 = true;
          _iteratorError2 = err;
        } finally {
          try {
            if (!_iteratorNormalCompletion2 && _iterator2.return) {
              _iterator2.return();
            }
          } finally {
            if (_didIteratorError2) {
              throw _iteratorError2;
            }
          }
        }

        el.setAttribute("renamed", "");
      }
      /**获取可能出现用户名的元素 */
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }

    function getUname() {
      // 所有常见的用户名链接
      var a = Array.from(document.querySelectorAll("a.mw-userlink bdi:not([renamed])"));
      // 顶栏的用户名
      var topyn = document.querySelector("#pt-userpage a:not([renamed])");
      if (topyn) a.push(topyn);
      return a;
    }
    /**MediaWiki会在一些地方用空格代替下划线 */
    function mwUsernameTurn(unRaw) {
      while (unRaw.indexOf("_") != -1) {
        unRaw = unRaw.replace("_", " ");
      }return unRaw;
    }
  }
})();