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

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

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

MCBBS Wiki GitHub群组已上线!

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

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

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

Gadget:ReplaceUsername.js:修订间差异

来自MCBBS Wiki
跳到导航 跳到搜索
无编辑摘要
(// Edit via Wikiplus)
第1行: 第1行:
"use strict";

(function () {
(function () {
console.log("Running Gadget-ReplaceUsername.js")
console.log("Running Gadget-ReplaceUsername.js");
/**改名表 */
/**改名表 */
var map = [["Beanflame", "beanflame"], ["Salt_lovely", "盐酱"], ["Bleake", "bleake"]];
let map = [
// 执行一次
['Beanflame', 'beanflame'],
replaceUsername();
['Salt_lovely', '盐酱'],
// 窗口加载完毕后再运行一次,以防漏网之鱼
['Bleake','bleake'],
window.addEventListener("load", replaceUsername);
]
/**修改用户名显示功能 */
// 执行一次
replaceUsername()
function replaceUsername() {
var _iteratorNormalCompletion = true;
// 窗口加载完毕后再运行一次,以防漏网之鱼
var _didIteratorError = false;
window.addEventListener('load', replaceUsername)
var _iteratorError = undefined;
/**修改用户名显示功能 */

function replaceUsername() {
try {
for (let el of getUname()) {
for (var _iterator = getUname()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
for (let m of map) {
var el = _step.value;
if (el.textContent == m[0] || el.textContent == mwUsernameTurn(m[0])) {
el.textContent = m[1]
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
if (el.hasAttribute('title')) {
var _iteratorError2 = undefined;
el.setAttribute('title', el.getAttribute('title') + ' | 原名: ' + m[0])

} else {
try {
el.setAttribute('title', '原名: ' + m[0])
for (var _iterator2 = map[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
}
break
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;
}
}
el.setAttribute('renamed', '')
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
}

/**获取可能出现用户名的元素 */
function getUname() {
el.setAttribute("renamed", "");
}
// 所有常见的用户名链接
/**获取可能出现用户名的元素 */
let a = Array.from(document.querySelectorAll('a.mw-userlink bdi:not([renamed])'))
} catch (err) {
// 顶栏的用户名
_didIteratorError = true;
let topyn = document.querySelector('#pt-userpage a:not([renamed])')
if (topyn)
_iteratorError = err;
} finally {
a.push(topyn)
return a
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
}
} finally {
/**MediaWiki会在一些地方用空格代替下划线 */
function mwUsernameTurn(unRaw) {
if (_didIteratorError) {
while (unRaw.indexOf('_') != -1)
throw _iteratorError;
unRaw = unRaw.replace('_', ' ')
return unRaw
}
}
}
}

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;
}
}
}
})()
})();

2022年11月9日 (三) 23:00的版本

"use strict";

(function () {
  console.log("Running Gadget-ReplaceUsername.js");
  /**改名表 */
  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;
    }
  }
})();