User:Anne drew/admintagger.js

This is an old revision of this page, as edited by Anne drew (talk | contribs) at 16:01, 22 June 2019 (change steward icon). 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.
// Forked from User:Amorymeltzer/crathighlighter.js
//<nowiki>

(function($, mw) {
  var 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 {
            var 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
            var 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") {
              var 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
              ) {
                var user = mwtitle.getMain().replace(/_/g, " ");
                if (mwtitle.getNamespaceId() === -1)
                  user = user.replace("Contributions/", "");
                if (crdata[user] == 1) {
                  link.parentNode.insertBefore(
                    document.createTextNode(" 🔧 "),
                    link.nextSibling
                  );
                } else if (sydata[user] == 1) {
                  link.parentNode.insertBefore(
                    document.createTextNode(" 🧹 "),
                    link.nextSibling
                  );
                }
                if (osdata[user] == 1) {
                  link.parentNode.insertBefore(
                    document.createTextNode(" 👁️ "),
                    link.nextSibling
                  );
                }
                if (cudata[user] == 1) {
                  link.parentNode.insertBefore(
                    document.createTextNode(" ❓ "),
                    link.nextSibling
                  );
                }
                if (swdata[user] == 1) {
                  link.parentNode.insertBefore(
                    document.createTextNode(" 🌐 "),
                    link.nextSibling
                  );
                }
                if (acdata[user] == 1) {
                  link.parentNode.insertBefore(
                    document.createTextNode(" ⚖ "),
                    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>