User:Galaktos/checkLinkAdd.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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/*
 * On diff pages for added links,
 * check if the same link exists in another language.
 * If there is another link with the same title,
 * a green checkmark is prepended to the edit comment.
 * Very useful for certain kinds of items
 * where titles tend to be the same across languages,
 * like persons (name) or taxons/species (latin name).
 */
if ($("body").hasClass("wb-diffpage")) {
  var comment = $(".diff-ntitle span.comment");
  var match = comment.text().match(/Added link to \[(.*)]:  (.*)\)/);
  if (match && match[1] && match[2]) {
    var wiki = match[1];
    var newtitle = match[2];
    $("li.wikibase-sitelinkview").each(function(index, elem) {
      if (!$(elem).hasClass("wikibase-sitelinkview-" + wiki)) {
        var title = $(elem).find("span.wikibase-sitelinkview-link a").text();
        if (newtitle === title) {
          var autocomment = $(".diff-ntitle span.autocomment");
          autocomment.before('<span style="color:green">✔</span>');
          return false; // stop loop
        }
      }
    });
  }
}