User:William Avery/see-also-check.js

// Put an asterisk button after every See also entry that is also linked in the article body. // When you click the '*', it outlines all the corresponding links in red and scrolls up to the section // that contains the first highlighted link function highlight(href, id) { $('.seealso-link').removeClass('seealso-link') $('a[href="' + href + '"]').addClass('seealso-link') // links could be hiding in collapsed content; in which case, click the button to open it up. $('.seealso-link').parents('.mw-collapsed').each(function {   $('.mw-collapsible-toggle-collapsed', this).click  }); var escaped_id = id.replace(/\(/, '\\(').replace(/\)/, '\\)') $('html, body').animate({   //scrollTop: $("#" + escaped_id).offset.top    scrollTop: $('.seealso-link').offset.top  }, 500); } $(function($) { var hrefs = {}  var insection = 'firstHeading'  if (![0, 2, 118].includes(mw.config.get('wgNamespaceNumber')))    return;

mw.loader.using('mediawiki.util').then(function {   mw.util.addCSS('.seealso-link { border: 1px solid red; }}')

$('h2 .mw-headline, h3 .mw-headline, h4 .mw-headline, a', $('#mw-content-text')).each(function(t, a) {     if (['H2', 'H3', 'H4'].includes($(this).parent.prop('nodeName'))) {        insection = $(this).attr('id')      }      var href = $(this).attr('href')      if (href)        if (insection === 'See_also' && hrefs[href])          $(this).after('*')      	else if (!hrefs[href])          hrefs[href] = insection    }); }); });