User:Slakr/sectionlinks.js

// // based off of User:The Voidwalker/alwaysEditSectionLink.js // var $mwHeadlines = $('.mw-headline'); if (mw.config.get('wgIsProbablyEditable') && $mwHeadlines.length) { var normalEditLink = $('#ca-edit').find('a').attr('href'); var normalPermalink = $('#t-permalink').find('a').attr('href'); $mwHeadlines.each(function(idx) {   var $ele = $(this);    var sectionKey = $ele.attr('id');    var sectionNum = idx + 1;    // Find its parent element (probably an )    var $dParent = $ele.parent;

// Then see if there's already an editsection. var $editsection = $dParent.find('.mw-editsection'); if (!$editsection.length) { $editsection = $(' ').addClass('mw-editsection').append(     	$(' ').addClass('mw-editsection-bracket').text('['),      	$('')      	  .attr('href', normalEditLink + '&section=' + sectionNum)      	  .attr('title', 'Edit section')      	  .text('edit'),      	$(' ').addClass('mw-editsection-bracket').text(']')      ); $editsection.appendTo($dParent); $editsection = $dParent.find('.mw-editsection'); }   var $lastBracket = $editsection.find('.mw-editsection-bracket:last');

var separator = ' ⋅ '; // Equivalent to &sdot; var $linkSection = $('').attr('href', '#' + encodeURIComponent(sectionKey)).text('link'); var $permaLinkSection = $('').attr('href', normalPermalink + '#' + encodeURIComponent(sectionKey)).text('perm'); $lastBracket.prepend(document.createTextNode(separator), $linkSection, document.createTextNode(separator), $permaLinkSection); }); }