Wikipedia article name with language

In the 'Languages' list in the left sidebar, the language name linking to the same article in that language is complemented with the name of that article.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Wikipedia article name with language
// @version     1.0.2
// @namespace   http://www.agj.cl/
// @description In the 'Languages' list in the left sidebar, the language name linking to the same article in that language is complemented with the name of that article.
// @license     Unlicense
// @include     http*://*.wikipedia.org/wiki/*
// @grant       none
// ==/UserScript==

(function () {
  "use strict";

  console.log("Executing Wikipedia article name with language.");

  // Utilities.

  const sel = document.querySelector.bind(document);
  const selAll = document.querySelectorAll.bind(document);
  const eq = (a) => (b) => a === b;
  const test = (regex) => (text) => regex.test(text);
  const testOn = (text) => (regex) => regex.test(text);
  const prepend = (a) => (b) => a + b;
  const makeEl = (tag, attrs, ...content) => {
    const el = document.createElement(tag);
    if (attrs)
      Object.keys(attrs).forEach((attr) => el.setAttribute(attr, attrs[attr]));
    content
      .map((obj) =>
        typeof obj === "string" ? document.createTextNode(obj) : obj,
      )
      .forEach((node) => el.appendChild(node));
    return el;
  };
  const pipe = (...fs) =>
    fs.reduce(
      (left, right) =>
        (...args) =>
          right(left(...args)),
    );
  const uniq = (list) => {
    const seen = [];
    return list.filter((item) =>
      seen.some(eq(item)) ? false : (seen.push(item), true),
    );
  };
  const not =
    (f) =>
    (...args) =>
      !f(...args);

  //

  const elements = Array.from(selAll(".interlanguage-link"));

  elements.forEach((el) => {
    const a = el.getElementsByTagName("a")[0];
    const langName = a.textContent;
    const titleAndLanguage = a.getAttribute("title");
    const titleMatcher = [
      /(.+) – .+/, // English, etc.
      /(.+) +\(.+\)/, // Spanish, etc.
      /.+: (.+)/, // Japanese, etc.
    ].find(testOn(titleAndLanguage));
    const title = titleAndLanguage.replace(titleMatcher, "$1");
    a.textContent = "";
    a.appendChild(makeEl("span", { class: "language-name" }, langName));
    a.appendChild(document.createTextNode(" "));
    a.appendChild(makeEl("span", { class: "article-title" }, title));
  });

  // Styles.

  sel("head").appendChild(
    makeEl(
      "style",
      null,
      `
		.interlanguage-link .language-name {
			display: block;
			text-transform: uppercase;
			font-size: 0.7em;
		}
		`,
    ),
  );
})();