User:Anne drew/admintagger.js

This is an old revision of this page, as edited by Anne drew (talk | contribs) at 16:46, 22 June 2019 (change). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//Taken from https://en.wikipedia.org/w/index.php?title=User:Bellezzasolo/Scripts/adminhighlighter.js&oldid=829278273
//Inspired from https://en.wikipedia.org/w/index.php?title=User:Amalthea/userhighlighter.js&oldid=437693511
//Apply to sysops, IA, CU, OS, 'crats', AC members
//
//If you want different colors, add something like
//.userhighlighter_bureaucrat {background-color: red !important}
//to your modern.css file.
//
//Not at all friendly to other styles, erases 'em all completely
//<nowiki>

(function($, mw) {
  let acdata, crdata, osdata, cudata, sydata, swdata;
  $.when(
    $.getJSON(
      mw.config.get("wgScriptPath") +
        "/index.php?action=raw&ctype=application/json&title=User:Amorymeltzer/crathighlighter.js/arbcom.json",
      function(data) {
        acdata = data;
      }
    ),
    $.getJSON(
      mw.config.get("wgScriptPath") +
        "/index.php?action=raw&ctype=application/json&title=User:Amorymeltzer/crathighlighter.js/bureaucrat.json",
      function(data) {
        crdata = data;
      }
    ),
    $.getJSON(
      mw.config.get("wgScriptPath") +
        "/index.php?action=raw&ctype=application/json&title=User:Amorymeltzer/crathighlighter.js/oversight.json",
      function(data) {
        osdata = data;
      }
    ),
    $.getJSON(
      mw.config.get("wgScriptPath") +
        "/index.php?action=raw&ctype=application/json&title=User:Amorymeltzer/crathighlighter.js/checkuser.json",
      function(data) {
        cudata = data;
      }
    ),
    $.getJSON(
      mw.config.get("wgScriptPath") +
        "/index.php?action=raw&ctype=application/json&title=User:Amalthea_(bot)/userhighlighter.js/sysop.js",
      function(data) {
        sydata = data;
      }
    ),
    $.getJSON(
      mw.config.get("wgScriptPath") +
        "/index.php?action=raw&ctype=application/json&title=User:Amorymeltzer/crathighlighter.js/steward.json",
      function(data) {
        swdata = data;
      }
    )
  ).then(function() {
    ADMINHIGHLIGHT_EXTLINKS = window.ADMINHIGHLIGHT_EXTLINKS || false;
    ADMINHIGHLIGHT_NAMESPACES = [-1, 2, 3];
    mw.loader.using(
      ["mediawiki.util", "mediawiki.Uri", "mediawiki.Title"],
      function() {
        $("#mw-content-text a").each(function(index, link) {
          try {
            const url = link.getAttribute("href");
            if (!url || url.charAt(0) === "#") return; // Skip <a> elements that aren't actually links; skip anchors
            if (
              url.lastIndexOf("http://", 0) !== 0 &&
              url.lastIndexOf("https://", 0) !== 0 &&
              url.lastIndexOf("/", 0) !== 0
            )
              return; //require http(s) links, avoid "javascript:..." etc. which mw.Uri does not support
            if (
              link.parentElement.className &&
              link.parentElement.classList[0] == "autocomment"
            )
              return; // Skip span.autocomment links aka automatic section links in edit summaries
            if (link.className && link.classList[0] == "external") return; // Avoid errors on hard-to-parse external links
            const uri = new mw.Uri(url);
            if (!ADMINHIGHLIGHT_EXTLINKS && !$.isEmptyObject(uri.query)) return; // Skip links with query strings if highlighting external links is disabled
            if (uri.host == "en.wikipedia.org") {
              const mwtitle = new mw.Title(
                mw.util.getParamValue("title", url) ||
                  decodeURIComponent(uri.path.slice(6))
              ); // Try to get the title parameter of URL; if not available, remove '/wiki/' and use that
              if (
                $.inArray(
                  mwtitle.getNamespaceId(),
                  ADMINHIGHLIGHT_NAMESPACES
                ) >= 0
              ) {
                let user = mwtitle.getMain().replace(/_/g, " ");
                if (mwtitle.getNamespaceId() === -1) {
                  user = user.replace("Contributions/", "");
                }

                const roles = [];

                if (crdata[user] == 1) {
                  roles.push("🔧");
                } else if (sydata[user] == 1) {
                  roles.push("🧹");
                }
                if (osdata[user] == 1) {
                  roles.push("👁");
                }
                if (cudata[user] == 1) {
                  roles.push("❓");
                }
                if (swdata[user] == 1) {
                  roles.push("🌐");
                }
                if (acdata[user] == 1) {
                  roles.push("⚖");
                }

                const rolesSpan = document.createElement("sup");

                rolesSpan.textContent = " " + roles.join(" ");
                // rolesSpan.style.fontSize = "0.9em";

                // append constructed span to user link
                link.parentNode.insertBefore(rolesSpan, link.nextSibling);
              }
            }
          } catch (e) {
            console.log(link);
            // Sometimes we will run into unparsable links, so just log these and move on
            window.console &&
              console.error("Admin highlighter recoverable error", e.message);
          }
        });
      }
    );
  });
})(jQuery, mediaWiki);
//</nowiki>