User:YMS/labelcollect.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/**
  Label Collector
  See [[User:YMS/LC]] for documentation, [[User:YMS/labelcollect2.js]] for the real thing
  <nowiki>
 */
(function() {
  "use strict";

  var toolPage = "User:YMS/LC";
  var name = "Label Collector";
  var id = "t-labelCollector";
  var desc = "Collect labels, descriptions and aliases from articles";

  // Startup
  $.when(
    mw.loader.using( [ 'mediawiki.util' ] ),
    $.ready
  ).done( function() {
    if (mw.config.get("wgNamespaceNumber") === 0 && mw.config.get("wbEntityId") !== null) {
      // Add portlet link for item
      mw.util.addPortletLink("p-tb", mw.util.getUrl(toolPage) + "#" + mw.config.get("wbEntityId"), name, id, desc);
    } else if (mw.config.get("wgRelevantUserName") !== null && mw.config.get("wgPageName") !== toolPage) {
      // Add portlet link for user
      mw.util.addPortletLink("p-tb", mw.util.getUrl(toolPage) + "#User:" + mw.config.get("wgRelevantUserName"), name, id, desc);
    } else if (mw.config.get("wgPageName") === "Special:Search" && mw.config.get("searchTerm") !== null) {
      // Add portlet link for search
      mw.util.addPortletLink("p-tb", mw.util.getUrl(toolPage) + "#Special:Search/" + mw.config.get("searchTerm"), name, id, desc);
    } else if (mw.config.get("wgPageName") === toolPage && mw.config.get("wgAction") === "view") {
      // Load & run script
      $.ajax({
        url: "//www.wikidata.org/w/index.php?title=User:YMS/labelcollect2.js",
        data: {
          action: "raw",
          ctype: "text/javascript"
        },
        dataType: "script",
        cache: true
      });
    }
  });
})();