Jump to content

User:GhostInTheMachine/SDlinkBuilder.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by GhostInTheMachine (talk | contribs) at 22:06, 21 February 2020 (caseind sort). 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.
$(function(){
  var menuTabs = $('#p-cactions > div > ul');

  menuTabs.append($('<li id="sd-link-maker"><a href="#" title="Build list of SDlinks">SDlinks</a></li>'))
  $('#sd-link-maker').click(makeSDlinks);
});

function makeSDlinks(){
  var $links = $("#mw-content-text a[href^='/wiki/'].nonimage");
  var links = [];
  $links.each(function() {
    var page = $(this).text();
    if( page ) {
      links.push(page);
    }
  });

  links.sort(function (a, b) {
    return a.toLowerCase().localeCompare(b.toLowerCase());
  });

  var body = $("#mw-content-text");
  body.html("<ul>");
  links.each(function() {
    var page = $(this).text();
    if( page ) {
      body.append( $("<li>").html( '* {{SDlink|' + page + '}}' ));
    }
  });
}