_ _    _ _____  ___   __                       
 __      _(_) | _(_)___ / ( _ ) / /_   ___ ___  _ __ ___  
 \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ 
  \ V  V /| |   <| |___) | (_) | (_) | (_| (_) | | | | | |
   \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|

User:Rummskartoffel/talk page usage.js

The importance of User:Rummskartoffel/talk page usage.js in today's society is undeniable. Whether it is a current topic or a historical event, User:Rummskartoffel/talk page usage.js plays a vital role in people's lives. Over the years, User:Rummskartoffel/talk page usage.js has been the subject of debate, analysis and reflection in different areas, from politics and economics to culture and entertainment. In this article, we will explore the impact of User:Rummskartoffel/talk page usage.js on everyday life, as well as its influence on decision-making and human behavior. From its importance in the workplace to its influence on mental and emotional health, User:Rummskartoffel/talk page usage.js has a reach that transcends borders and time.
/*
	On Special:Contributions and user (talk) pages, displays information about
	the user's most recent edits to talk namespaces.
*/

mw.loader.using(, function() {
  /* ==== DEFINITIONS ==== */
  function getLatestNamespaceEdit(api, username, namespace) {
    return api
      .get({
        action: "query",
        format: "json",
        list: "usercontribs",
        formatversion: "2",
        uclimit: 1,
        ucuser: username,
        ucnamespace: namespace,
      })
      .then(function(response) {
        return {
          namespace: namespace,
          edit: response.query.usercontribs,
        };
      });
  }

  function createResultList() {
    const div = document.createElement("div");
    div.id = "rummskartoffel-talk-page-usage";
    div.classList.add("hlist");
    div.style.fontSize = "92%";
    div.innerText = "Latest edits in namespaces: ";
    const dl = document.createElement("dl");
    dl.style.display = "inline";
    div.appendChild(dl);

    return div;
  }

  function formatTimeInterval(timestamp) {
    const interval_milliseconds = new Date(timestamp).getTime() - Date.now();
    const formatter = new Intl.RelativeTimeFormat(
      mw.config.get("wgUserLanguage"), {
        numeric: "auto",
      }
    );
    const day_milliseconds = 1000 * 60 * 60 * 24;
    const week_milliseconds = day_milliseconds * 7;
    const month_milliseconds = day_milliseconds * 30;
    const year_milliseconds = day_milliseconds * 356;

    if (interval_milliseconds < week_milliseconds)
      return formatter.format(
        Math.round(interval_milliseconds / day_milliseconds),
        "day"
      );
    else if (interval_milliseconds < month_milliseconds)
      return formatter.format(
        Math.round(interval_milliseconds / week_milliseconds),
        "week"
      );
    else if (interval_milliseconds < year_milliseconds)
      return formatter.format(
        Math.round(interval_milliseconds / month_milliseconds),
        "month"
      );
    else
      return formatter.format(
        Math.round(interval_milliseconds / year_milliseconds),
        "year"
      );
  }

  function createNamespaceResultListEntry(namespace, username, edit) {
    const dt = document.createElement("dt");
    const dt_a = document.createElement("a");
    dt.style.fontWeight = 400;
    dt_a.innerText = mw.config.get("wgFormattedNamespaces");
    dt_a.href = mw.util.getUrl("Special:Contributions", {
      target: username,
      namespace,
    });
    if (!edit) dt_a.classList.add("new");
    dt.appendChild(dt_a);

    const dd = document.createElement("dd");
    if (edit) {
      const dd_a = document.createElement("a");
      dd_a.innerText = formatTimeInterval(edit.timestamp);
      dd_a.href = mw.util.getUrl("", {
        diff: edit.revid,
      });
      dd.appendChild(dd_a);
    } else dd.innerText = "no edits";

    return ;
  }

  /* ==== MAIN ==== */
  const is_user = !!mw.config.get("wgRelevantUserName"),
		is_contributions = mw.config.get("wgCanonicalSpecialPageName") === "Contributions",
		is_user_namespace = .indexOf(mw.config.get("wgNamespaceNumber")) !== -1;
  if (!is_user || !(is_contributions || is_user_namespace)) {
    return;
  }
  
  mw.loader.load("https://wiki386.com/en/Template:Hlist/styles.css?action=raw&ctype=text/css", "text/css");

  const api = new mw.Api();
  const username = mw.config.get("wgRelevantUserName");
  const requests = .map(namespace =>
    getLatestNamespaceEdit(api, username, namespace)
  );
  const result_list = createResultList();
  Promise.all(requests)
    .then(results =>
      results.map(result =>
        result_list.firstElementChild.append(
          ...createNamespaceResultListEntry(
            result.namespace,
            username,
            result.edit
          )
        )
      )
    )
    .then(() => {
      const site_sub = document.getElementById("siteSub");
      if (site_sub) site_sub.after(result_list);
      else document.getElementById("bodyContent").prepend(result_list);
    });
});